From 21f5069e48d92af17a0b8b805342e956282e19ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sat, 26 Jan 2019 10:29:29 +0100 Subject: [PATCH 1/4] Code-blocks auto-color. --- autoload/vimwiki/html.vim | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/autoload/vimwiki/html.vim b/autoload/vimwiki/html.vim index ba2cc4c..243189a 100644 --- a/autoload/vimwiki/html.vim +++ b/autoload/vimwiki/html.vim @@ -344,7 +344,17 @@ endfunction function! s:tag_code(value) - return ''.s:safe_html_preformatted(s:mid(a:value, 1)).'' + let l:retstr = '' + return l:retstr endfunction From 08ec02a7554e9981967f0a4443ea310b7fbdccd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Tue, 19 Feb 2019 21:04:57 +0100 Subject: [PATCH 2/4] Alternative where text color is inverse of background. --- autoload/vimwiki/html.vim | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/autoload/vimwiki/html.vim b/autoload/vimwiki/html.vim index 243189a..b9ed95c 100644 --- a/autoload/vimwiki/html.vim +++ b/autoload/vimwiki/html.vim @@ -349,8 +349,12 @@ 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:retstr .= " style='background-color: " . l:str . ";'" + let l:inv_color = 0xFFFFFF - eval("0x" . l:str[1:]) + + let l:retstr .= printf(" style='background-color: %s; color: #%x;'", + \ l:str, l:inv_color) endif let l:retstr .= '>'.s:safe_html_preformatted(l:str).'' 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 3/4] 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).'' From da52523710af2f6252eae8fe02ff147e7d498d67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20H=C3=B6rnquist?= Date: Sun, 17 Mar 2019 22:50:56 +0100 Subject: [PATCH 4/4] Add documentation for colorcodes. --- doc/vimwiki.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index 4f935e5..457b1f3 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -880,6 +880,12 @@ is decorated: > 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 > + #ffe119 + ------------------------------------------------------------------------------ 5.2. Links *vimwiki-syntax-links*