commit e6d6830db7a0b0ec4f026d950aeaa778adefa7ff
parent 8941508e359e2edc546e39d54b3fc6d5c78b9493
Author: Henry Qin <root@hq6.me>
Date: Sun, 17 Mar 2019 18:05:24 -0700
Merge branch 'colorcodes' into 'dev'. Closes PR #616.
This colors all CSS color codes found alone in inline code blocks to the
color they mention.
Diffstat:
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/autoload/vimwiki/html.vim b/autoload/vimwiki/html.vim
@@ -344,7 +344,27 @@ endfunction
function! s:tag_code(value)
- return '<code>'.s:safe_html_preformatted(s:mid(a:value, 1)).'</code>'
+ let l:retstr = '<code'
+
+ let l:str = s:mid(a:value, 1)
+ let l:match = match(l:str, '^#[a-fA-F0-9]\{6\}$')
+
+ if l:match != -1
+ let l:r = eval("0x".l:str[1:2])
+ let l:g = eval("0x".l:str[3:4])
+ let l:b = eval("0x".l:str[5:6])
+
+ let l:fg_color =
+ \ (((0.299 * r + 0.587 * g + 0.114 * b) / 0xFF) > 0.5)
+ \ ? "black" : "white"
+
+ let l:retstr .=
+ \ " style='background-color:" . l:str .
+ \ ";color:" . l:fg_color . ";'"
+ endif
+
+ let l:retstr .= '>'.s:safe_html_preformatted(l:str).'</code>'
+ return l:retstr
endfunction
diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt
@@ -886,6 +886,12 @@ For Markdown syntax these variations are used: >
Furthermore, there are a number of words which are highlighted extra flashy:
TODO, DONE, STARTED, FIXME, FIXED, XXX.
+When rendered as HTML, code blocks containing only a hash prefixed 6 digit hex
+number will be colored as themselves. For example >
+ `#ffe119`
+Becomes >
+ <code style='background-color:#ffe119;color:black;'>#ffe119</code>
+
------------------------------------------------------------------------------
5.2. Links *vimwiki-syntax-links*