Highlight markdown typeface more compliant with Github Flavoured Markdown

This commit is contained in:
Tinmarino
2023-03-10 13:54:40 -03:00
parent fea8bee382
commit 59402cdf8b
6 changed files with 94 additions and 41 deletions
+27 -14
View File
@@ -500,7 +500,7 @@ function! vimwiki#base#goto(...) abort
" Save current file pos " Save current file pos
let vimwiki_prev_link = [vimwiki#path#current_wiki_file(), getpos('.')] let vimwiki_prev_link = [vimwiki#path#current_wiki_file(), getpos('.')]
call vimwiki#base#edit_file(':e', call vimwiki#base#edit_file('edit',
\ vimwiki#vars#get_wikilocal('path') . key . vimwiki#vars#get_wikilocal('ext'), \ vimwiki#vars#get_wikilocal('path') . key . vimwiki#vars#get_wikilocal('ext'),
\ anchor, \ anchor,
\ vimwiki_prev_link, \ vimwiki_prev_link,
@@ -1120,7 +1120,7 @@ function! vimwiki#base#edit_file(command, filename, anchor, ...) abort
" which happens if we jump to an achor in the current file. " which happens if we jump to an achor in the current file.
" This hack is necessary because apparently Vim messes up the result of " This hack is necessary because apparently Vim messes up the result of
" getpos() directly after this command. Strange. " getpos() directly after this command. Strange.
if !(a:command ==# ':e ' && vimwiki#path#is_equal(a:filename, expand('%:p'))) if !(a:command =~# ':\?[ed].*' && vimwiki#path#is_equal(a:filename, expand('%:p')))
try try
execute a:command fname execute a:command fname
catch /E37:/ catch /E37:/
@@ -1130,6 +1130,10 @@ function! vimwiki#base#edit_file(command, filename, anchor, ...) abort
catch /E325:/ catch /E325:/
call vimwiki#u#warn('Vim couldn''t open the file, probably because a swapfile already exists. See :h E325.') call vimwiki#u#warn('Vim couldn''t open the file, probably because a swapfile already exists. See :h E325.')
return return
catch /E319:/
call vimwiki#u#warn('Vim couldn''t open the file, cannot launch the drop command. See :h E319.')
execute 'edit' fname
return
endtry endtry
" If the opened file was not already loaded by Vim, an autocommand is " If the opened file was not already loaded by Vim, an autocommand is
" triggered at this point " triggered at this point
@@ -1391,7 +1395,7 @@ endfunction
function! s:open_wiki_buffer(item) abort function! s:open_wiki_buffer(item) abort
" Edit wiki file. " Edit wiki file.
" Called: by rename_file: Usefull for buffer commands " Called: by rename_file: Usefull for buffer commands
call vimwiki#base#edit_file(':e', a:item[0], '') call vimwiki#base#edit_file('edit', a:item[0], '')
if !empty(a:item[1]) if !empty(a:item[1])
call vimwiki#vars#set_bufferlocal('prev_links', a:item[1], a:item[0]) call vimwiki#vars#set_bufferlocal('prev_links', a:item[1], a:item[0])
endif endif
@@ -1665,23 +1669,26 @@ function! vimwiki#base#follow_link(split, ...) abort
endif endif
if a:split ==# 'hsplit' if a:split ==# 'hsplit'
let cmd = ':split ' let cmd = 'split'
elseif a:split ==# 'vsplit' elseif a:split ==# 'vsplit'
let cmd = ':vsplit ' let cmd = 'vsplit'
elseif a:split ==# 'badd' elseif a:split ==# 'badd'
let cmd = ':badd ' let cmd = 'badd'
elseif a:split ==# 'tab' elseif a:split ==# 'tab'
let cmd = ':tabnew ' let cmd = 'tabnew'
elseif a:split ==# 'tabdrop' elseif a:split ==# 'tabdrop'
" Use tab drop if we've already got the file open in an existing tab " Use tab drop if we've already got the file open in an existing tab
let cmd = ':tab drop ' let cmd = 'tab edit'
if exists(':drop') == 2
let cmd = 'tab drop'
endif
else else
" Same as above - doing this by default reduces incidence of multiple " Same as above - doing this by default reduces incidence of multiple
" tabs with the same file. We default to :e just in case :drop doesn't " tabs with the same file. We default to :e just in case :drop doesn't
" exist in the current build. " exist in the current build.
let cmd = ':e ' let cmd = 'edit'
if exists(':drop') if exists(':drop') == 2 && has('windows')
let cmd = ':drop ' let cmd = 'drop'
endif endif
endif endif
@@ -1691,7 +1698,7 @@ function! vimwiki#base#follow_link(split, ...) abort
let previous_window_nr = winnr('#') let previous_window_nr = winnr('#')
if previous_window_nr > 0 && previous_window_nr != winnr() if previous_window_nr > 0 && previous_window_nr != winnr()
execute previous_window_nr . 'wincmd w' execute previous_window_nr . 'wincmd w'
let cmd = ':e' let cmd = ':edit'
endif endif
endif endif
@@ -1739,8 +1746,14 @@ function! vimwiki#base#go_back_link() abort
" Jump to target with edit_file " Jump to target with edit_file
if !empty(prev_link) if !empty(prev_link)
" go back to saved wiki link " go back to saved wiki link
call vimwiki#base#edit_file(':e ', prev_link[0], '') " Change file if required lazy
call setpos('.', prev_link[1]) let file = prev_link[0]
let pos = prev_link[1]
" Removed the filereadable check for Vader
if !(vimwiki#path#is_equal(file, expand('%:p')))
call vimwiki#base#edit_file('edit', file, '')
endif
call setpos('.', pos)
else else
" maybe we came here by jumping to a tag -> pop from the tag stack " maybe we came here by jumping to a tag -> pop from the tag stack
silent! pop! silent! pop!
+11 -8
View File
@@ -299,20 +299,23 @@ function! vimwiki#diary#make_note(wnum, ...) abort
call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('path', wiki_nr). call vimwiki#path#mkdir(vimwiki#vars#get_wikilocal('path', wiki_nr).
\ vimwiki#vars#get_wikilocal('diary_rel_path', wiki_nr)) \ vimwiki#vars#get_wikilocal('diary_rel_path', wiki_nr))
let cmd = 'edit' let cmd = ':edit'
if a:0 if a:0
if a:1 == 1 if a:1 == 1
let cmd = 'tabedit' let cmd = ':tabedit'
elseif a:1 == 2 elseif a:1 == 2
let cmd = 'split' let cmd = ':split'
elseif a:1 == 3 elseif a:1 == 3
let cmd = 'vsplit' let cmd = ':vsplit'
elseif a:1 == 4 elseif a:1 == 4
let cmd = 'tab drop' let cmd = ':tab edit'
if exists(':drop') == 2
let cmd = ':tab drop'
endif
elseif a:1 == 5 elseif a:1 == 5
let cmd = 'drop' let cmd = ':edit'
if exists(':drop') if exists(':drop') == 2
let cmd = 'drop' let cmd = ':drop'
endif endif
endif endif
endif endif
+5 -5
View File
@@ -1884,26 +1884,26 @@ function! s:convert_file(path_html, wikifile) abort
endif endif
call vimwiki#path#mkdir(path_html) call vimwiki#path#mkdir(path_html)
if g:vimwiki_global_vars['listing_hl'] > 0 && has("unix") if g:vimwiki_global_vars['listing_hl'] > 0 && has('unix')
let i = 0 let i = 0
while i < len(html_lines) while i < len(html_lines)
if html_lines[i] =~ '^<pre .*type=.\+>' if html_lines[i] =~# '^<pre .*type=.\+>'
let type = split(split(split(html_lines[i], 'type=')[1], '>')[0], '\s\+')[0] let type = split(split(split(html_lines[i], 'type=')[1], '>')[0], '\s\+')[0]
let attr = split(split(html_lines[i], '<pre ')[0], '>')[0] let attr = split(split(html_lines[i], '<pre ')[0], '>')[0]
let start = i + 1 let start = i + 1
let cur = start let cur = start
while html_lines[cur] !~ '^<\/pre>' while html_lines[cur] !~# '^<\/pre>'
let cur += 1 let cur += 1
endwhile endwhile
let tmp = ('tmp'. split(system('mktemp -p . --suffix=.' . type, 'silent'), 'tmp')[-1])[:-2] let tmp = ('tmp'. split(system('mktemp -p . --suffix=.' . type, 'silent'), 'tmp')[-1])[:-2]
call system('echo ' . shellescape(join(html_lines[start:cur - 1], '\n')) . ' > ' . tmp) call system('echo ' . shellescape(join(html_lines[start : cur - 1], '\n')) . ' > ' . tmp)
call system(g:vimwiki_global_vars['listing_hl_command'] . ' ' . tmp . ' > ' . tmp . '.html') call system(g:vimwiki_global_vars['listing_hl_command'] . ' ' . tmp . ' > ' . tmp . '.html')
let html_out = system('cat ' . tmp . '.html') let html_out = system('cat ' . tmp . '.html')
call system('rm ' . tmp . ' ' . tmp . '.html') call system('rm ' . tmp . ' ' . tmp . '.html')
let i = cur let i = cur
let html_lines = html_lines[0:start - 1] + split(html_out, '\n') + html_lines[cur:] let html_lines = html_lines[0 : start - 1] + split(html_out, '\n') + html_lines[cur : ]
endif endif
let i += 1 let i += 1
endwhile endwhile
+49 -10
View File
@@ -304,18 +304,55 @@ function! vimwiki#u#hi_expand_regex(lst) abort
" :param: list<list,delimiters>> with reduced regex " :param: list<list,delimiters>> with reduced regex
" Return: list with extended regex delimiters (not inside a word) " Return: list with extended regex delimiters (not inside a word)
" -- [['\*_', '_\*']] -> [['\*_\S\@=', '\S\@<=_\*\%(\s\|$\)\@=']] " -- [['\*_', '_\*']] -> [['\*_\S\@=', '\S\@<=_\*\%(\s\|$\)\@=']]
" Note: For purposes of this definition, the beginning and the end of the line count as Unicode whitespace.
" See: https://github.github.com/gfm/#left-flanking-delimiter-run " See: https://github.github.com/gfm/#left-flanking-delimiter-run
let res = [] let res = []
let p = vimwiki#u#get_punctuation_string() let punctuation = vimwiki#u#get_punctuation_string()
for delimiters in a:lst
let r_prefix = '\(^\|[[:space:]]\@<=\)' " Iterate on (left delimiter, right delimiter pair)
" Regex Start: not preceded by backslash, not ended by space for a_delimiter in a:lst
let r_start = r_prefix . delimiters[0] . '\S\@=' let r_left_del = a_delimiter[0]
" Regex End: not preceded by backslash or space, ended by punctuation or space let r_right_del = a_delimiter[1]
let r_prefix = '\(^\|[^[:space:]\\]\@<=\)'
let r_end = r_prefix . delimiters[1] . '\%(\_[[:space:]' . p . ']\)\@=' " Regex Start:
" Left-Flanking is not followed by space (or ned of line)
let r_left_prefix = '\%(^\|[[:space:]]\@<=\)'
let r_left_prefix = '\\\@<!'
" -- not followed by Unicode whitespace,
let r_left_suffix = '\%([^[:space:]]\@=\)'
" Left Case1: not followed by punctuation
let r_left_suffix1 = '\%(\%([^[:space:]' . punctuation . ']\)\@=\)'
" -- Can escape the leftflank
let r_left_prefix1 = '\%(^\|\\\@<!\)'
" Left Case2: followed by punctuation so must be preceded by Unicode whitespace or start of line or a punctuation character.
let r_left_suffix2 = '\%([' . punctuation . ']\@=\)'
let r_left_prefix2 = '\%(\%(^\|[[:space:]' . punctuation . ']\)\@<=\)'
" Left Concatenate
let r_start = '\%(' . r_left_prefix1 . r_left_del . r_left_suffix1
let r_start .= '\|' . r_left_prefix2 . r_left_del . r_left_suffix2 . '\)'
" Regex End:
" not preceded by Unicode whitespace
let r_right_prefix = '\(^\|[^[:space:]]\@<=\)'
" Right Case1: not preceded by a punctuation character (or start of line)
let r_right_prefix1 = '\%(\%(^\|[^[:space:]' . punctuation . ']\)\@<=\)'
let r_right_suffix1 = ''
" Right Case2: preceded by a punctuation character and followed by Unicode whitespace or end of line or a punctuation character
let r_right_prefix2 = '\%([' . punctuation . ']\@<=\)'
let r_right_suffix2 = '\%(\%($\|[[:space:]' . punctuation . ']\)\@<=\)'
" Right Concatenate
let r_end = '\%(' . r_right_prefix1 . r_right_del . r_right_suffix1
let r_end .= '\|' . r_right_prefix2 . r_right_del . r_right_suffix2 . '\)'
call add(res, [r_start, r_end]) call add(res, [r_start, r_end])
endfor endfor
return res return res
endfunction endfunction
@@ -337,9 +374,9 @@ function! vimwiki#u#hi_tag(tag_pre, tag_post, syntax_group, contains, ...) abort
endif endif
" Craft command " Craft command
" \ 'skip="\\' . a:tag_pre . '" ' .
let cmd = 'syn region ' . a:syntax_group . ' matchgroup=VimwikiDelimiter ' . let cmd = 'syn region ' . a:syntax_group . ' matchgroup=VimwikiDelimiter ' .
\ opt_is_contained . \ opt_is_contained .
\ 'skip="\\' . a:tag_pre . '" ' .
\ 'start="' . a:tag_pre . '" ' . \ 'start="' . a:tag_pre . '" ' .
\ 'end="' . a:tag_post . '" ' . \ 'end="' . a:tag_post . '" ' .
\ 'keepend ' . \ 'keepend ' .
@@ -442,5 +479,7 @@ function! vimwiki#u#hi_typeface(dic) abort
" Prevent var_with_underscore to trigger italic text " Prevent var_with_underscore to trigger italic text
" -- See $VIMRUNTIME/syntax/markdown.vim " -- See $VIMRUNTIME/syntax/markdown.vim
syn match VimwikiError "\w\@<=[_*]\w\@=" " But leave
" -- See https://github.github.com/gfm/#example-364
syn match VimwikiError "\w\@<=_\w\@="
endfunction endfunction
+2 -2
View File
@@ -755,9 +755,9 @@ function! s:get_markdown_syntaxlocal() abort
\ 'underline': vimwiki#u#hi_expand_regex([]), \ 'underline': vimwiki#u#hi_expand_regex([]),
\ 'bold_italic': vimwiki#u#hi_expand_regex([['\*_', '_\*'], ['_\*', '\*_'], ['\*\*\*', '\*\*\*'], ['___', '___']]), \ 'bold_italic': vimwiki#u#hi_expand_regex([['\*_', '_\*'], ['_\*', '\*_'], ['\*\*\*', '\*\*\*'], ['___', '___']]),
\ 'code': [ \ 'code': [
\ ['\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@=', \ ['\%(^\|[^`\\]\)\@<=`\%($\|[^`]\)\@=',
\ '\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@='], \ '\%(^\|[^`]\)\@<=`\%($\|[^`]\)\@='],
\ ['\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@=', \ ['\%(^\|[^`\\]\)\@<=``\%($\|[^`]\)\@=',
\ '\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@='], \ '\%(^\|[^`]\)\@<=``\%($\|[^`]\)\@='],
\ ], \ ],
\ 'del': [['\~\~', '\~\~']], \ 'del': [['\~\~', '\~\~']],
-2
View File
@@ -452,8 +452,6 @@ if str2nr(vimwiki#vars#get_global('key_mappings').links)
call vimwiki#u#map_key('n', '+', '<Plug>VimwikiNormalizeLink') call vimwiki#u#map_key('n', '+', '<Plug>VimwikiNormalizeLink')
call vimwiki#u#map_key('v', '+', '<Plug>VimwikiNormalizeLinkVisual') call vimwiki#u#map_key('v', '+', '<Plug>VimwikiNormalizeLinkVisual')
call vimwiki#u#map_key('v', '<CR>', '<Plug>VimwikiNormalizeLinkVisualCR') call vimwiki#u#map_key('v', '<CR>', '<Plug>VimwikiNormalizeLinkVisualCR')
call vimwiki#u#map_key('n', '<D-CR>', '<Plug>VimwikiTabDropLink')
call vimwiki#u#map_key('n', '<C-S-CR>', '<Plug>VimwikiTabDropLink', 1)
call vimwiki#u#map_key('n', '<BS>', '<Plug>VimwikiGoBackLink') call vimwiki#u#map_key('n', '<BS>', '<Plug>VimwikiGoBackLink')
call vimwiki#u#map_key('n', '<TAB>', '<Plug>VimwikiNextLink') call vimwiki#u#map_key('n', '<TAB>', '<Plug>VimwikiNextLink')
call vimwiki#u#map_key('n', '<S-TAB>', '<Plug>VimwikiPrevLink') call vimwiki#u#map_key('n', '<S-TAB>', '<Plug>VimwikiPrevLink')