From a1f1b9c290000af493bc03558ed3e12a235f162a Mon Sep 17 00:00:00 2001 From: Tinmarino Date: Sat, 8 Aug 2020 16:51:28 -0400 Subject: [PATCH] Syntax: Stricter italic match: match '_that_' not 'a_ that _a' See: https://github.github.com/gfm/#emphasis-and-strong-emphasis `A single * character can open emphasis iff (if and only if) it is part of a left-flanking delimiter run.` Tim Pope default is too permissive (leads to too much emphasis openener): `\S\@<=_\|_\S\@=` -> `_\S\@=` --- autoload/vimwiki/u.vim | 7 ++----- syntax/vimwiki_default.vim | 16 ++++++---------- test/syntax.vader | 32 +++++++++++++++++++++++++------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/autoload/vimwiki/u.vim b/autoload/vimwiki/u.vim index 31312e5..528d3f3 100644 --- a/autoload/vimwiki/u.vim +++ b/autoload/vimwiki/u.vim @@ -273,14 +273,11 @@ endfunction " Helper: Expand regex from reduced typeface delimiters " :param: list> with reduced regex " Return: list with extended regex delimiters (not inside a word) -" -- [['\*_', '_\*']] -> [['\S\@<=\*_\|\*_\S\@=', '\S\@<=_\*\|_\*\S\@=']] +" -- [['\*_', '_\*']] -> [['\*_\S\@=', '\S\@<=_\*']] function! vimwiki#u#hi_expand_regex(lst) abort let res = [] - function! s:expand_regex(rx) abort - return '\S\@<=' .a:rx . '\|' . a:rx . '\S\@=' - endfunction for delimiters in a:lst - call add(res, [s:expand_regex(delimiters[0]), s:expand_regex(delimiters[1])]) + call add(res, [delimiters[0] . '\S\@=', '\S\@<=' . delimiters[1]]) endfor return res endfunction diff --git a/syntax/vimwiki_default.vim b/syntax/vimwiki_default.vim index a4c805d..79c54d0 100644 --- a/syntax/vimwiki_default.vim +++ b/syntax/vimwiki_default.vim @@ -16,23 +16,19 @@ let b:vimwiki_syntax_conceal = exists('+conceallevel') ? ' conceal' : '' let b:vimwiki_syntax_concealends = has('conceal') ? ' concealends' : '' " text: *strong* -let s:default_syntax.dTypeface.bold = [ - \ ['\S\@<=\*\|\*\S\@=', '\S\@<=\*\|\*\S\@='], - \ ] +let s:default_syntax.dTypeface.bold = vimwiki#u#hi_expand_regex([ + \ ['\*', '\*']]) " text: _italic_ -let s:default_syntax.dTypeface.italic = [ - \ ['\S\@<=_\|_\S\@=', '\S\@<=_\|_\S\@='], - \ ] +let s:default_syntax.dTypeface.italic = vimwiki#u#hi_expand_regex([ + \ ['_', '_']]) " text: no underline defined let s:default_syntax.dTypeface.underline = [] " text: *_bold italic_* or _*italic bold*_ -let s:default_syntax.dTypeface.bold_italic = [ - \ ['\S\@<=\*_\|\*_\S\@=', '\S\@<=_\*\|_\*\S\@='], - \ ['\S\@<=_\*\|_\*\S\@=', '\S\@<=\*_\|\*_\S\@='], - \ ] +let s:default_syntax.dTypeface.bold_italic = vimwiki#u#hi_expand_regex([ + \ ['\*_', '_\*'], ['_\*', '\*_']]) " generic headers let s:default_syntax.rxH = '=' diff --git a/test/syntax.vader b/test/syntax.vader index a0fa360..5687a1a 100644 --- a/test/syntax.vader +++ b/test/syntax.vader @@ -4,6 +4,24 @@ # 1 Typeface {{{1 ################# +# Emphasis stricker {{{2 +# See: https://github.github.com/gfm/#emphasis-and-strong-emphasis + +Given vimwiki (Emphasis and not): + this __bold__ ok + this _italic_ ok + t__ no bold __ t + t_ no ital _ t + +Execute (Set syntax markdown): + call SetSyntax('markdown') + +Execute (Assert Syntax extended types x 1): + AssertEqual 'VimwikiBold' , SyntaxAt(1, 9) + AssertEqual 'VimwikiItalic' , SyntaxAt(2, 9) + AssertEqual '' , SyntaxAt(3, 9) + AssertEqual '' , SyntaxAt(4, 9) + # With vimwiki_hl_cb_checked {{{2 Given vimwiki (task list with code): @@ -102,17 +120,17 @@ Given vimwiki (Basic Types nested in extended): From ,,sub to _italic with en_ aaaaaaa,, morF From $eq to **boldboldboldbo** aaaaaaaaa $ From ^super t *italic aaaaaaa*aaaaaaaaaaaaaaaaaaaaa - From ~~strike__ bbbbbbbbbbbbb__ssssssssssssssssss~~ + From ~~strike__bbbbbbbbbbbbb__ssssssssssssssssss~~ Execute (Set syntax markdown): call SetSyntax('markdown') -Execute (Assert Syntax basic types nested in extended): - AssertEqual 'VimwikiBold' , SyntaxAt(1, 23) - AssertEqual 'VimwikiItalic' , SyntaxAt(2, 23) - AssertEqual 'textSnipTEX' , SyntaxAt(3, 23) - AssertEqual 'VimwikiItalic' , SyntaxAt(4, 23) - AssertEqual 'VimwikiBold' , SyntaxAt(5, 23) +Execute (Assert Syntax basic types nested in extended): + AssertEqual 'VimwikiBold1' , SyntaxAt(1, 23) . 1 + AssertEqual 'VimwikiItalic2' , SyntaxAt(2, 23) . 2 + AssertEqual 'textSnipTEX3' , SyntaxAt(3, 23) . 3 + AssertEqual 'VimwikiItalic4' , SyntaxAt(4, 23) . 4 + AssertEqual 'VimwikiBold5' , SyntaxAt(5, 23) . 5 Given vimwiki (Try to nest in code): From `codeto__no onenest in code__ end`