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\@=`
This commit is contained in:
Tinmarino 2020-08-08 16:51:28 -04:00
parent 21c5a7f796
commit a1f1b9c290
3 changed files with 33 additions and 22 deletions

View File

@ -273,14 +273,11 @@ endfunction
" Helper: Expand regex from reduced typeface delimiters
" :param: list<list,delimiters>> 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

View File

@ -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 = '='

View File

@ -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)
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`