Feature: Add command VimwikiColorize (Issue #990)

Only colorize the current line to start
This commit is contained in:
mtourneb
2020-09-03 23:43:56 -04:00
parent dbbadc8035
commit a7f34cd8cf
6 changed files with 128 additions and 3 deletions
+43
View File
@@ -2902,6 +2902,49 @@ function! vimwiki#base#linkify() abort
endfunction
function! vimwiki#base#complete_colorize(ArgLead, CmdLine, CursorPos) abort
" We can safely ignore args if we use -custom=complete option, Vim engine
" will do the job of filtering
let colorlist = keys(vimwiki#vars#get_wikilocal('color_dic'))
return join(colorlist, "\n")
endfunction
function! vimwiki#base#colorize(...) abort
" TODO Must be coherent with color_tag_template
" -- Just removeing spaces, \/ -> /, replacing COLORFG will do it
let key = a:0 ? a:1 : 'default'
let color_dic = vimwiki#vars#get_wikilocal('color_dic')
" Guard: color key nust exist
if !has_key(color_dic, key)
call vimwiki#u#error('color_dic variable has no key ''' . key . '''')
return
endif
" Get content
let content = getline('.')
" TODO save position for visual selection: see u#get_selection
" Surround
" -- pre
let [fg, bg] = color_dic[key]
let pre = '<span style="'
if fg !=# ''
let pre .= 'color:' . fg . ';'
endif
if bg !=# ''
let pre .= 'background:' . bg . ';'
endif
let pre .= '">'
" -- post
let post = '</span>'
" -- concat
let content = pre . content . post
" Set buffer content
call setline('.', content)
endfunction
" -------------------------------------------------------------------------
" Load syntax-specific Wiki functionality
for s:syn in s:vimwiki_get_known_syntaxes()
+24
View File
@@ -451,6 +451,13 @@ endfunction
" Get default wikilocal values
" Please: keep alphabetical sort
function! s:get_default_wikilocal() abort
" Build color_tag_template regular expression
" Must be coherent with VimwikiColorize
let fg = 'color\s*:\s*__COLORFG__\s*;\s*'
let bg = 'background\s*:\s*__COLORBG__\s*;\s*'
let color_tag_rx = '<span \s*style\s*=\s*"\s*\('
\ . fg . bg . '\|' . fg . '\|' . bg
\ . '\)"\s*>__CONTENT__<\/span>'
return {
\ 'auto_diary_index': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'auto_export': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
@@ -460,6 +467,23 @@ function! s:get_default_wikilocal() abort
\ 'auto_toc': {'type': type(0), 'default': 0, 'min': 0, 'max': 1},
\ 'automatic_nested_syntaxes': {'type': type(0), 'default': 1, 'min': 0, 'max': 1},
\ 'base_url': {'type': type(''), 'default': '', 'min_length': 1},
\ 'color_dic': {'type': type({}), 'default': {
\ 'default': ['', '#d79921'],
\ 'red': ['#cc241d', ''],
\ 'bred': ['', '#cc241d'],
\ 'green': ['#98971a', ''],
\ 'bgreen': ['', '#98971a'],
\ 'yellow': ['#d79921', ''],
\ 'byellow': ['', '#d79921'],
\ 'blue': ['#458588', ''],
\ 'bblue': ['', '#458588'],
\ 'purple': ['#b16286', ''],
\ 'bpurple': ['', '#b16286'],
\ 'orange': ['#d65d0e', ''],
\ 'borange': ['', '#d65d0e'],
\ 'gray': ['#a89984', ''],
\ 'bgray': ['', '#a89984']}},
\ 'color_tag_template': {'type': type({}), 'default': color_tag_rx},
\ 'commentstring': {'type': type(''), 'default': '%%%s'},
\ 'css_name': {'type': type(''), 'default': 'style.css', 'min_length': 1},
\ 'custom_wiki2html': {'type': type(''), 'default': ''},