Feature: Syntax typeface delimiters can end at punctuation

This commit is contained in:
Tinmarino 2020-08-13 01:59:21 -04:00
parent 22d9d012ba
commit 0b85dd1a7b
3 changed files with 42 additions and 19 deletions

View File

@ -697,19 +697,6 @@ function! vimwiki#base#get_anchors(filename, syntax) abort
endfunction endfunction
" Helper to mutualize
" Called: normalize and unnormalize anchor
function! s:get_punctuaction_regex() abort
" From: https://gist.github.com/asabaylus/3071099#gistcomment-2563127
if v:version <= 703
" Retrocompatibility: Get invalid range for vim 7.03
return '[^0-9a-zA-Z_ \-]'
else
return '[^0-9a-zA-Z\u4e00-\u9fff_ \-]'
endif
endfunction
" :param: anchor <string> <= Heading line " :param: anchor <string> <= Heading line
" :param: (1) previous_anchors <dic[IN/OUT]> of previous normalized anchor " :param: (1) previous_anchors <dic[IN/OUT]> of previous normalized anchor
" -- to know if must append -2, updated on the fly " -- to know if must append -2, updated on the fly
@ -735,7 +722,7 @@ function! vimwiki#base#normalize_anchor(anchor, ...) abort
let anchor = tolower(anchor) let anchor = tolower(anchor)
" 2 Remove anything that is not a letter, number, CJK character, hyphen or space " 2 Remove anything that is not a letter, number, CJK character, hyphen or space
let punctuation_rx = s:get_punctuaction_regex() let punctuation_rx = vimwiki#u#get_punctuation_regex()
let anchor = substitute(anchor, punctuation_rx, '', 'g') let anchor = substitute(anchor, punctuation_rx, '', 'g')
" 3 Change any space to a hyphen " 3 Change any space to a hyphen
@ -777,7 +764,7 @@ function! vimwiki#base#unnormalize_anchor(anchor) abort
return [anchor, 1, ''] return [anchor, 1, '']
endif endif
let punctuation_rx = s:get_punctuaction_regex() let punctuation_rx = vimwiki#u#get_punctuation_regex()
" Permit url part of link: '](www.i.did.it.my.way.cl)' " Permit url part of link: '](www.i.did.it.my.way.cl)'
let link_rx = '\%(\]([^)]*)\)' let link_rx = '\%(\]([^)]*)\)'
let invisible_rx = '\%( \|-\|' . punctuation_rx . '\|' . link_rx . '\)' let invisible_rx = '\%( \|-\|' . punctuation_rx . '\|' . link_rx . '\)'

View File

@ -271,14 +271,40 @@ function! vimwiki#u#get_syntax_dic(...) abort
endfunction endfunction
" Helper to mutualize
" Called: normalize and unnormalize anchor
function! vimwiki#u#get_punctuation_regex() abort
" From: https://gist.github.com/asabaylus/3071099#gistcomment-2563127
" Faster
" Unused now
if v:version <= 703
" Retrocompatibility: Get invalid range for vim 7.03
return '[^0-9a-zA-Z_ \-]'
else
return '[^0-9a-zA-Z\u4e00-\u9fff_ \-]'
endif
endfunction
" Faster
function! vimwiki#u#get_punctuation_string() abort
" See: https://github.github.com/gfm/#ascii-punctuation-character
return '!"#$%&''()*+,-./:;<=>?@\[\\\]^`{}|~'
endfunction
" Helper: Expand regex from reduced typeface delimiters " Helper: Expand regex from reduced typeface delimiters
" :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\|$\)\@=']]
" See: https://github.github.com/gfm/#left-flanking-delimiter-run
function! vimwiki#u#hi_expand_regex(lst) abort function! vimwiki#u#hi_expand_regex(lst) abort
let res = [] let res = []
let p = vimwiki#u#get_punctuation_string()
for delimiters in a:lst for delimiters in a:lst
call add(res, [delimiters[0] . '\S\@=', '\S\@<=' . delimiters[1] . '\%(\s\|\n\)\@=']) call add(res, [
\ delimiters[0] . '\S\@=',
\ '\S\@<=' . delimiters[1] . '\%(\_[[:space:]' . p . ']\)\@='])
endfor endfor
return res return res
endfunction endfunction

View File

@ -5,6 +5,16 @@
# 1 Typeface {{{1 # 1 Typeface {{{1
################# #################
Given vimwiki (Markdown with punctuation #340 {{{2):
__bold__, not bold
Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Assert Syntax (alpha)):
AssertEqual 'VimwikiBold1' , SyntaxAt(1, 5) . 1
AssertEqual '2' , SyntaxAt(1, 16) . 2
Given vimwiki (Markdown bad __this_not_it__ {{{2): Given vimwiki (Markdown bad __this_not_it__ {{{2):
See here 14 | See here 14 |
s2n_error s2n_error
@ -26,7 +36,7 @@ Given vimwiki (Markdown bad __this_not_it__ {{{2):
Execute (Set syntax markdown): Execute (Set syntax markdown):
call SetSyntax('markdown') call SetSyntax('markdown')
Execute (Assert Syntax extended types x 1): Execute (Assert Syntax (bravo)):
AssertEqual 'VimwikiError2' , SyntaxAt(2, 4) . 2 AssertEqual 'VimwikiError2' , SyntaxAt(2, 4) . 2
AssertEqual 'VimwikiError3' , SyntaxAt(3, 4) . 3 AssertEqual 'VimwikiError3' , SyntaxAt(3, 4) . 3
AssertEqual '4' , SyntaxAt(4, 14) . 4 AssertEqual '4' , SyntaxAt(4, 14) . 4
@ -49,7 +59,7 @@ Given vimwiki (bold and pre {{{2):
Execute (Set syntax markdown): Execute (Set syntax markdown):
call SetSyntax('markdown') call SetSyntax('markdown')
Execute (Assert Syntax extended types x 1): Execute (Assert Syntax (charlie)):
AssertEqual 'VimwikiPre' , SyntaxAt(3, 1) AssertEqual 'VimwikiPre' , SyntaxAt(3, 1)
# Emphasis stricker {{{2 # Emphasis stricker {{{2
@ -63,7 +73,7 @@ Given vimwiki (Emphasis and not):
Execute (Set syntax markdown): Execute (Set syntax markdown):
call SetSyntax('markdown') call SetSyntax('markdown')
Execute (Assert Syntax extended types x 1): Execute (Assert Syntax (delta)):
AssertEqual 'VimwikiBold' , SyntaxAt(1, 9) AssertEqual 'VimwikiBold' , SyntaxAt(1, 9)
AssertEqual 'VimwikiItalic' , SyntaxAt(2, 9) AssertEqual 'VimwikiItalic' , SyntaxAt(2, 9)
AssertEqual '' , SyntaxAt(3, 9) AssertEqual '' , SyntaxAt(3, 9)