Syntax: Stricter typeface and fix preCode (alias inline) nested in bold

Fix: Syntax bug precode nested in bold apperead bold

Problem:
1. `that_ HERE _was` italic
2. `__that ``HERE`` was__  bold => PreCode should not receive typeface
region changes

Solution:
1. Stricter regex (and add \* to VimwikiError)
2. Add VikiError and WikiPre to nestables syntaxes
This commit is contained in:
Tinmarino 2020-08-09 22:21:05 -04:00
parent a241d458ab
commit 39407014c8
6 changed files with 107 additions and 11 deletions

View File

@ -1768,7 +1768,6 @@ endfunction
" Conceal
function! vimwiki#emoji#apply_conceal() abort
syn iskeyword 0-9,a-z,A-Z,:-:
for [name, emoji] in items(s:emoji_single)
exe 'syn keyword VimwikiEmoji :' . name . ': conceal cchar=' . emoji
endfor

View File

@ -273,11 +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\|$\)\@=']]
function! vimwiki#u#hi_expand_regex(lst) abort
let res = []
for delimiters in a:lst
call add(res, [delimiters[0] . '\S\@=', '\S\@<=' . delimiters[1]])
call add(res, [delimiters[0] . '\S\@=', '\S\@<=' . delimiters[1] . '\%(\s\|\n\)\@='])
endfor
return res
endfunction
@ -400,5 +400,5 @@ function! vimwiki#u#hi_typeface(dic) abort
" Prevent var_with_underscore to trigger italic text
" -- See $VIMRUNTIME/syntax/markdown.vim
syn match VimwikiError "\w\@<=_\w\@="
syn match VimwikiError "\w\@<=[_*]\w\@="
endfunction

View File

@ -25,7 +25,7 @@ let syntax_dic = g:vimwiki_syntax_variables[s:current_syntax]
" Declare nesting capabilities
" -- to be embeded in standard: bold, italic, underline
let syntax_dic.nested_extended = 'VimwikiCode,VimwikiEqIn,VimwikiSuperScript,VimwikiSubScript,textSnipTEX'
let syntax_dic.nested_extended = 'VimwikiError,VimwikiPre,VimwikiCode,VimwikiEqIn,VimwikiSuperScript,VimwikiSubScript,textSnipTEX'
" -- to be embeded in exetended (the one above)
let syntax_dic.nested_typeface = 'VimwikiBold,VimwikiItalic,VimwikiUmderline,VimwikiDelText'
let syntax_dic.nested = syntax_dic.nested_extended . ',' . syntax_dic.nested_typeface

45
test/list_move.vader Normal file
View File

@ -0,0 +1,45 @@
# Move and edit a list (autocommand, config_
# Test J {{{1
############################################################
Given vimwiki (Markdown * [ ] list {{{2):
* [ ] Top Level
* [o] Child 1
* [X] Child 2
* [X] Post space
Execute (Set syntax markdown):
call SetSyntax('markdown')
Do (JJJJ):
JJJJ
0y$
:call AssertIfVersion(704, '* [ ] Top Level Child 1 Child 2 Post space', @")\<Cr>
Given vimwiki (Markdown * and - list {{{2):
* one
* two
- three
- for
Execute (Set syntax markdown):
call SetSyntax('markdown')
Do (JjJ):
JjJ
gg
0y$
:call AssertIfVersion(704, '* one two', @")\<Cr>
G
0y$
:call AssertIfVersion(704, '- three for', @")\<Cr>
# vim: sw=2:foldlevel=30:foldmethod=indent:

View File

@ -1,12 +1,59 @@
# Syntax and Highlight
#Given vimwiki (bold and pre):
# 1 Typeface {{{1
#################
Given vimwiki (Markdown bad __this_not_it__ {{{2):
See here 14 |
s2n_error
s*n*er_r_
n4rmal_aaaaaaaaaaaaaaaaaaaa_text_
n5t_italiccccccccccccccccccccc_no
n6t_italiccccccccccccccccccccccno
n7t*italiccccccccccccccccccccc_no
n8t*italiccccccccccccccccccccc*no
__not_italicccccccccc_but_boldd__
_a_asdasda_asdas_asdas_asdasda_a_
_jitaliccccccccccccccccccccccccc_
n12ormalllllllllllllllllllllllll_
_italic if at end of file unfortunately
Note: The decision to start a region is only based on a matching start
pattern. There is no check for a matching end pattern. This does NOT
work: (:h syn-region)
Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Assert Syntax extended types x 1):
AssertEqual 'VimwikiError2' , SyntaxAt(2, 4) . 2
AssertEqual 'VimwikiError3' , SyntaxAt(3, 4) . 3
AssertEqual '4' , SyntaxAt(4, 14) . 4
AssertEqual '5' , SyntaxAt(5, 14) . 5
AssertEqual '6' , SyntaxAt(6, 14) . 6
AssertEqual '7' , SyntaxAt(7, 14) . 7
AssertEqual '8' , SyntaxAt(8, 14) . 8
AssertEqual 'VimwikiBold9' , SyntaxAt(9, 14) . 9
AssertEqual 'VimwikiItalic10' , SyntaxAt(10, 14) . 10
AssertEqual 'VimwikiItalic11' , SyntaxAt(11, 14) . 11
AssertEqual '12' , SyntaxAt(12, 14) . 12
Given vimwiki (bold and pre {{{2):
__startbold
```
pre
```
__endbold
Execute (Set syntax markdown):
call SetSyntax('markdown')
Execute (Assert Syntax extended types x 1):
AssertEqual 'VimwikiPre' , SyntaxAt(3, 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
@ -23,7 +70,6 @@ Execute (Assert Syntax extended types x 1):
AssertEqual '' , SyntaxAt(4, 9)
# With vimwiki_hl_cb_checked {{{2
Given vimwiki (task list with code):
Normal syntax
- [X] Lorem __sit__ `sed do eiusmod
@ -116,11 +162,11 @@ Execute (Assert Syntax extended types nested in extended):
AssertEqual 'VimwikiSubScript' , SyntaxAt(5, 23)
Given vimwiki (Basic Types nested in extended):
From ^super t__bold __ is crazy but^ morF
From ,,sub to _italic with en_ aaaaaaa,, morF
From ^super __bold __ is crazy but^ morF
From ,,sub _italic with en_ aaaaaaa,, morF
From $eq to **boldboldboldbo** aaaaaaaaa $
From ^super t *italic aaaaaaa*aaaaaaaaaaaaaaaaaaaaa
From ~~strike__bbbbbbbbbbbbb__ssssssssssssssssss~~
From ^super *italic aaaaaaa*aaaaaaaaaaaaaaaaaaaaa
From ~~strik __bbbbbbbbbbbbb__ssssssssssssssssss~~
Execute (Set syntax markdown):
call SetSyntax('markdown')

View File

@ -268,4 +268,10 @@
return synIDattr(synIDtrans(l:s), 'name')
endfun
" Run Assert only if vim version higth enough
function! AssertIfVersion(version, one, two)
if v:version < a:version | return | endif
AssertEqual a:one, a:two
endfunction
" vim: ft=vim:sw=2