From 2f87f92060a154f71416e8ac84dc48d96c03dc4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 17 Mar 2019 22:40:34 +0100 Subject: [PATCH] Better foreground for colorcodes. --- autoload/vimwiki/html.vim | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/autoload/vimwiki/html.vim b/autoload/vimwiki/html.vim index b9ed95c..0ad9ea4 100644 --- a/autoload/vimwiki/html.vim +++ b/autoload/vimwiki/html.vim @@ -349,12 +349,18 @@ function! s:tag_code(value) 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:inv_color = 0xFFFFFF - eval("0x" . l:str[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:retstr .= printf(" style='background-color: %s; color: #%x;'", - \ l:str, l:inv_color) + 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).''