Skip to content

Commit 8edf904

Browse files
committed
handle named colors in css
#1238
1 parent 036da13 commit 8edf904

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

issues/1238.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<style>
2+
div { color: palegoldenrod; }
3+
</style>

web-mode.el

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6983,7 +6983,7 @@ Also return non-nil if it is the command `self-insert-command' is remapped to."
69836983
(when (and dec-beg dec-end)
69846984
(goto-char dec-beg)
69856985
(while (and web-mode-enable-css-colorization
6986-
(re-search-forward "#[0-9a-fA-F]\\{6\\}\\|#[0-9a-fA-F]\\{3\\}\\|rgba?([ ]*\\([[:digit:]]\\{1,3\\}\\)[ ]*,[ ]*\\([[:digit:]]\\{1,3\\}\\)[ ]*,[ ]*\\([[:digit:]]\\{1,3\\}\\)\\(.*?\\))" dec-end t)
6986+
(re-search-forward "palegoldenrod\\|palegreen\\|#[0-9a-fA-F]\\{6\\}\\|#[0-9a-fA-F]\\{3\\}\\|rgba?([ ]*\\([[:digit:]]\\{1,3\\}\\)[ ]*,[ ]*\\([[:digit:]]\\{1,3\\}\\)[ ]*,[ ]*\\([[:digit:]]\\{1,3\\}\\)\\(.*?\\))" dec-end t)
69876987
;;(progn (message "%S %S" end (point)) t)
69886988
(<= (point) dec-end))
69896989
(web-mode-colorize (match-beginning 0) (match-end 0))
@@ -7001,23 +7001,24 @@ Also return non-nil if it is the command `self-insert-command' is remapped to."
70017001
"white" "black")))
70027002

70037003
(defun web-mode-colorize (beg end)
7004-
(let (str plist len)
7004+
(let (str plist)
70057005
(setq str (buffer-substring-no-properties beg end))
7006-
(setq len (length str))
7006+
;;(message "%S" str)
70077007
(cond
70087008
((string= (substring str 0 1) "#")
70097009
(setq plist (list :background str
7010-
:foreground (web-mode-colorize-foreground str)))
7011-
(put-text-property beg end 'face plist))
7010+
:foreground (web-mode-colorize-foreground str))))
70127011
((or (string= (substring str 0 4) "rgb(") (string= (substring str 0 5) "rgba("))
70137012
(setq str (format "#%02X%02X%02X"
70147013
(string-to-number (match-string-no-properties 1))
70157014
(string-to-number (match-string-no-properties 2))
70167015
(string-to-number (match-string-no-properties 3))))
70177016
(setq plist (list :background str
7018-
:foreground (web-mode-colorize-foreground str)))
7019-
(put-text-property beg end 'face plist))
7017+
:foreground (web-mode-colorize-foreground str))))
7018+
((string= str "palegoldenrod") (setq plist (list :background "#eee8aa" :foreground (web-mode-colorize-foreground "#eee8aa"))))
7019+
((string= str "palegreen") (setq plist (list :background "#98fb98" :foreground (web-mode-colorize-foreground "#98fb98"))))
70207020
) ;cond
7021+
(put-text-property beg end 'face plist)
70217022
))
70227023

70237024
(defun web-mode-interpolate-block-tag (beg end)

0 commit comments

Comments
 (0)