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.
This commit is contained in:
Henry Qin
2019-03-17 18:05:24 -07:00
2 changed files with 27 additions and 1 deletions

View File

@ -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