Add multiline comment support via %%+ and +%%
This commit is contained in:
parent
321e518fdb
commit
6dff2c60a5
@ -1245,6 +1245,7 @@ function! s:parse_line(line, state) abort
|
|||||||
let state.para = a:state.para
|
let state.para = a:state.para
|
||||||
let state.quote = a:state.quote
|
let state.quote = a:state.quote
|
||||||
let state.arrow_quote = a:state.arrow_quote
|
let state.arrow_quote = a:state.arrow_quote
|
||||||
|
let state.active_multiline_comment = a:state.active_multiline_comment
|
||||||
let state.pre = a:state.pre[:]
|
let state.pre = a:state.pre[:]
|
||||||
let state.math = a:state.math[:]
|
let state.math = a:state.math[:]
|
||||||
let state.table = a:state.table[:]
|
let state.table = a:state.table[:]
|
||||||
@ -1257,6 +1258,40 @@ function! s:parse_line(line, state) abort
|
|||||||
let processed = 0
|
let processed = 0
|
||||||
let line = a:line
|
let line = a:line
|
||||||
|
|
||||||
|
" Handle multiline comments, keeping in mind that they can mutate the
|
||||||
|
" current line while not marking as processed in the scenario where some
|
||||||
|
" text remains that needs to go through additional processing
|
||||||
|
if !processed
|
||||||
|
let mc_start = vimwiki#vars#get_syntaxlocal('rxMultilineCommentStart')
|
||||||
|
let mc_end = vimwiki#vars#get_syntaxlocal('rxMultilineCommentEnd')
|
||||||
|
|
||||||
|
" If either start or end is empty, we want to skip multiline handling
|
||||||
|
if !empty(mc_start) && !empty(mc_end)
|
||||||
|
" If we have an active multiline comment, we prepend the start of the
|
||||||
|
" multiline to our current line to make searching easier, knowing that
|
||||||
|
" it will be removed using substitute in all scenarios
|
||||||
|
if state.active_multiline_comment
|
||||||
|
let line = mc_start.line
|
||||||
|
endif
|
||||||
|
|
||||||
|
" Remove all instances of multiline comment pairs (start + end), using
|
||||||
|
" a lazy match so that we stop at the first ending multiline comment
|
||||||
|
" rather than potentially absorbing multiple
|
||||||
|
let line = substitute(line, mc_start.'.\{-\}'.mc_end, '', 'g')
|
||||||
|
|
||||||
|
" Check for a dangling multiline comment (comprised only of start) and
|
||||||
|
" remove all characters beyond it, also indicating that we are dangling
|
||||||
|
let mc_start_pos = match(line, mc_start)
|
||||||
|
if mc_start_pos >= 0
|
||||||
|
" NOTE: mc_start_pos is the byte offset, so should be fine with strpart
|
||||||
|
let line = strpart(line, 0, mc_start_pos)
|
||||||
|
endif
|
||||||
|
|
||||||
|
" If we had a dangling multiline comment, we want to flag as such
|
||||||
|
let state.active_multiline_comment = mc_start_pos >= 0
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
if !processed
|
if !processed
|
||||||
" allows insertion of plain text to the final html conversion
|
" allows insertion of plain text to the final html conversion
|
||||||
" for example:
|
" for example:
|
||||||
@ -1296,7 +1331,7 @@ function! s:parse_line(line, state) abort
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let line = s:safe_html_line(a:line)
|
let line = s:safe_html_line(line)
|
||||||
|
|
||||||
" pres
|
" pres
|
||||||
if !processed
|
if !processed
|
||||||
@ -1326,7 +1361,6 @@ function! s:parse_line(line, state) abort
|
|||||||
call extend(res_lines, lines)
|
call extend(res_lines, lines)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
if !processed
|
if !processed
|
||||||
if line =~# vimwiki#vars#get_syntaxlocal('rxComment')
|
if line =~# vimwiki#vars#get_syntaxlocal('rxComment')
|
||||||
let processed = 1
|
let processed = 1
|
||||||
@ -1603,6 +1637,7 @@ function! s:convert_file_to_lines(wikifile, current_html_file) abort
|
|||||||
let state.para = 0
|
let state.para = 0
|
||||||
let state.quote = 0
|
let state.quote = 0
|
||||||
let state.arrow_quote = 0
|
let state.arrow_quote = 0
|
||||||
|
let state.active_multiline_comment = 0
|
||||||
let state.pre = [0, 0] " [in_pre, indent_pre]
|
let state.pre = [0, 0] " [in_pre, indent_pre]
|
||||||
let state.math = [0, 0] " [in_math, indent_math]
|
let state.math = [0, 0] " [in_math, indent_math]
|
||||||
let state.table = []
|
let state.table = []
|
||||||
|
@ -1472,6 +1472,15 @@ The default commentstring can be changed or disabled with
|
|||||||
|g:vimwiki_commentstring| so an alternative commentstring can be set, e.g.:
|
|g:vimwiki_commentstring| so an alternative commentstring can be set, e.g.:
|
||||||
<!-- This may be a comment too -->
|
<!-- This may be a comment too -->
|
||||||
|
|
||||||
|
A multi-line comment is one that starts with %%+ and ends with +%%. This can
|
||||||
|
traverse across multiple lines, or can be contained within part of a single
|
||||||
|
line.
|
||||||
|
E.g.:
|
||||||
|
%%+ this text
|
||||||
|
and this text
|
||||||
|
would not be
|
||||||
|
in html +%%
|
||||||
|
%%+ not included +%% is included %%+ also not included +%%
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
5.11. Horizontal line *vimwiki-syntax-hr*
|
5.11. Horizontal line *vimwiki-syntax-hr*
|
||||||
@ -3706,6 +3715,7 @@ http://code.google.com/p/vimwiki/issues/list. They may be accessible from
|
|||||||
https://github.com/vimwiki-backup/vimwiki/issues.
|
https://github.com/vimwiki-backup/vimwiki/issues.
|
||||||
|
|
||||||
New:~
|
New:~
|
||||||
|
* PR #967: Add multiline comment support via %%+ and +%%
|
||||||
* Issue #942: Fixing wrong html link conversion in windows
|
* Issue #942: Fixing wrong html link conversion in windows
|
||||||
* PR #946: Add option |g:vimwiki_commentstring| to customize commentstring
|
* PR #946: Add option |g:vimwiki_commentstring| to customize commentstring
|
||||||
* Issue #940: Render table header inside thead element and rest under
|
* Issue #940: Render table header inside thead element and rest under
|
||||||
|
@ -348,6 +348,14 @@ if vimwiki#vars#get_global('valid_html_tags') !=? ''
|
|||||||
|
|
||||||
execute 'syntax match VimwikiComment /'.vimwiki#vars#get_syntaxlocal('rxComment').
|
execute 'syntax match VimwikiComment /'.vimwiki#vars#get_syntaxlocal('rxComment').
|
||||||
\ '/ contains=@Spell,VimwikiTodo'
|
\ '/ contains=@Spell,VimwikiTodo'
|
||||||
|
|
||||||
|
" Only do syntax highlighting for multiline comments if they exist
|
||||||
|
let s:mc_start = vimwiki#vars#get_syntaxlocal('rxMultilineCommentStart')
|
||||||
|
let s:mc_end = vimwiki#vars#get_syntaxlocal('rxMultilineCommentEnd')
|
||||||
|
if !empty(s:mc_start) && !empty(s:mc_end)
|
||||||
|
execute 'syntax region VimwikiMultilineComment start=/'.s:mc_start.
|
||||||
|
\ '/ end=/'.s:mc_end.'/ contains=@NoSpell,VimwikiTodo'
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" tags
|
" tags
|
||||||
@ -425,6 +433,7 @@ hi def link VimwikiSubScriptT VimwikiSubScript
|
|||||||
|
|
||||||
hi def link VimwikiTodo Todo
|
hi def link VimwikiTodo Todo
|
||||||
hi def link VimwikiComment Comment
|
hi def link VimwikiComment Comment
|
||||||
|
hi def link VimwikiMultilineComment Comment
|
||||||
|
|
||||||
hi def link VimwikiPlaceholder SpecialKey
|
hi def link VimwikiPlaceholder SpecialKey
|
||||||
hi def link VimwikiPlaceholderParam String
|
hi def link VimwikiPlaceholderParam String
|
||||||
@ -487,4 +496,3 @@ call vimwiki#base#nested_syntax('tex',
|
|||||||
|
|
||||||
|
|
||||||
syntax spell toplevel
|
syntax spell toplevel
|
||||||
|
|
||||||
|
@ -95,6 +95,8 @@ let s:default_syntax.rxPreEnd = '}}}'
|
|||||||
let s:default_syntax.rxMathStart = '{{\$'
|
let s:default_syntax.rxMathStart = '{{\$'
|
||||||
let s:default_syntax.rxMathEnd = '}}\$'
|
let s:default_syntax.rxMathEnd = '}}\$'
|
||||||
|
|
||||||
|
let s:default_syntax.rxMultilineCommentStart = '%%+'
|
||||||
|
let s:default_syntax.rxMultilineCommentEnd = '+%%'
|
||||||
let s:default_syntax.rxComment = '^\s*%%.*$'
|
let s:default_syntax.rxComment = '^\s*%%.*$'
|
||||||
let s:default_syntax.rxTags = '\%(^\|\s\)\@<=:\%([^:''[:space:]]\+:\)\+\%(\s\|$\)\@='
|
let s:default_syntax.rxTags = '\%(^\|\s\)\@<=:\%([^:''[:space:]]\+:\)\+\%(\s\|$\)\@='
|
||||||
|
|
||||||
|
@ -89,6 +89,9 @@ let s:markdown_syntax.rxPreEnd = '\%(`\{3,}\|\~\{3,}\)'
|
|||||||
let s:markdown_syntax.rxMathStart = '\$\$'
|
let s:markdown_syntax.rxMathStart = '\$\$'
|
||||||
let s:markdown_syntax.rxMathEnd = '\$\$'
|
let s:markdown_syntax.rxMathEnd = '\$\$'
|
||||||
|
|
||||||
|
" NOTE: There is no multi-line comment syntax for Markdown
|
||||||
|
let s:markdown_syntax.rxMultilineCommentStart = ''
|
||||||
|
let s:markdown_syntax.rxMultilineCommentEnd = ''
|
||||||
let s:markdown_syntax.rxComment = '^\s*%%.*$\|<!--[^>]*-->'
|
let s:markdown_syntax.rxComment = '^\s*%%.*$\|<!--[^>]*-->'
|
||||||
let s:markdown_syntax.rxTags = '\%(^\|\s\)\@<=:\%([^:[:space:]]\+:\)\+\%(\s\|$\)\@='
|
let s:markdown_syntax.rxTags = '\%(^\|\s\)\@<=:\%([^:[:space:]]\+:\)\+\%(\s\|$\)\@='
|
||||||
|
|
||||||
|
@ -70,6 +70,9 @@ let s:media_syntax.rxPreEnd = '<\/pre>'
|
|||||||
let s:media_syntax.rxMathStart = '{{\$'
|
let s:media_syntax.rxMathStart = '{{\$'
|
||||||
let s:media_syntax.rxMathEnd = '}}\$'
|
let s:media_syntax.rxMathEnd = '}}\$'
|
||||||
|
|
||||||
|
" NOTE: There is no multi-line comment syntax for MediaWiki
|
||||||
|
let s:media_syntax.rxMultilineCommentStart = ''
|
||||||
|
let s:media_syntax.rxMultilineCommentEnd = ''
|
||||||
let s:media_syntax.rxComment = '^\s*%%.*$'
|
let s:media_syntax.rxComment = '^\s*%%.*$'
|
||||||
let s:media_syntax.rxTags = '\%(^\|\s\)\@<=:\%([^:[:space:]]\+:\)\+\%(\s\|$\)\@='
|
let s:media_syntax.rxTags = '\%(^\|\s\)\@<=:\%([^:[:space:]]\+:\)\+\%(\s\|$\)\@='
|
||||||
|
|
||||||
|
@ -4,8 +4,54 @@ Execute (Copy Wiki's Resources):
|
|||||||
Log "Start: Copy Resources"
|
Log "Start: Copy Resources"
|
||||||
call CopyResources()
|
call CopyResources()
|
||||||
|
|
||||||
|
#################################################
|
||||||
|
Given vimwiki (Comments):
|
||||||
|
This is some text
|
||||||
|
%% This is a comment
|
||||||
|
Test%%+INLINE COMMENT+%%1
|
||||||
|
%%+INLINE COMMENT+%%Test2
|
||||||
|
Test3%%+INLINE COMMENT+%%
|
||||||
|
%%+ Multiline
|
||||||
|
comment
|
||||||
|
that
|
||||||
|
is
|
||||||
|
removed
|
||||||
|
+%%
|
||||||
|
Final text
|
||||||
|
|
||||||
|
Do (Convert):
|
||||||
|
:call ConvertWiki2Html()\<Cr>
|
||||||
|
# Keep only body
|
||||||
|
ggd/<body>\<Cr>
|
||||||
|
|
||||||
|
Expect (Comments Removed):
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
This is some text
|
||||||
|
Test1
|
||||||
|
Test2
|
||||||
|
Test3
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Final text
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
|
|
||||||
|
Execute(Delete):
|
||||||
|
call DeleteFile('$HOME/testwiki/test_html_table.wiki')
|
||||||
|
call DeleteFile('$HOME/html/default/test_html_table.html')
|
||||||
|
|
||||||
|
#################################################
|
||||||
Given vimwiki (Table no heading {{{1):
|
Given vimwiki (Table no heading {{{1):
|
||||||
| header1 | header2 |
|
| header1 | header2 |
|
||||||
| val1 | val2 |
|
| val1 | val2 |
|
||||||
@ -127,7 +173,6 @@ Execute(Delete):
|
|||||||
call DeleteFile('$HOME/testwiki/test_html_table.wiki')
|
call DeleteFile('$HOME/testwiki/test_html_table.wiki')
|
||||||
call DeleteFile('$HOME/html/default/test_html_table.html')
|
call DeleteFile('$HOME/html/default/test_html_table.html')
|
||||||
|
|
||||||
|
|
||||||
#################################################
|
#################################################
|
||||||
Execute (Log):
|
Execute (Log):
|
||||||
Log '#473: Syntax "local:" doesnt work as expected. #473'
|
Log '#473: Syntax "local:" doesnt work as expected. #473'
|
||||||
@ -174,11 +219,11 @@ Do (Get Html body):
|
|||||||
|
|
||||||
Expect (Local link):
|
Expect (Local link):
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<a href="../../here">Link</a>
|
<a href="../../here">Link</a>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
||||||
@ -226,7 +271,7 @@ Do (Get Html body):
|
|||||||
|
|
||||||
|
|
||||||
Expect (Plain Html):
|
Expect (Plain Html):
|
||||||
# the whole default html file should be here as a base + the modifications
|
# the whole default html file should be here as a base + the modifications
|
||||||
# from "Given"
|
# from "Given"
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
@ -171,6 +171,47 @@ Execute (Assert Syntax Header):
|
|||||||
AssertEqual SyntaxAt(5, 10), 'VimwikiHeader5'
|
AssertEqual SyntaxAt(5, 10), 'VimwikiHeader5'
|
||||||
AssertEqual SyntaxAt(6, 10), 'VimwikiHeader6'
|
AssertEqual SyntaxAt(6, 10), 'VimwikiHeader6'
|
||||||
|
|
||||||
|
# 10 Comments {{{1
|
||||||
|
###############
|
||||||
|
|
||||||
|
Given vimwiki (%%):
|
||||||
|
%% This is a line comment
|
||||||
|
%% This is also a comment
|
||||||
|
|
||||||
|
Execute (Set syntax default):
|
||||||
|
call SetSyntax('default')
|
||||||
|
|
||||||
|
Execute (Assert Syntax VimwikiComment):
|
||||||
|
AssertEqual SyntaxAt(1, 1), 'VimwikiComment'
|
||||||
|
AssertEqual SyntaxAt(2, 4), 'VimwikiComment'
|
||||||
|
|
||||||
|
Given vimwiki (%%+, +%%):
|
||||||
|
%%+ This
|
||||||
|
is a
|
||||||
|
multiline
|
||||||
|
comment +%%
|
||||||
|
%%+ This is a comment on one line +%%
|
||||||
|
%%+ One +%% Not a comment %%+ Two +%% Not a comment
|
||||||
|
|
||||||
|
Execute (Set syntax default):
|
||||||
|
call SetSyntax('default')
|
||||||
|
|
||||||
|
Execute (Assert Syntax VimwikiMultilineComment):
|
||||||
|
AssertEqual SyntaxAt(1, 1), 'VimwikiMultilineComment'
|
||||||
|
AssertEqual SyntaxAt(1, 8), 'VimwikiMultilineComment'
|
||||||
|
AssertEqual SyntaxAt(2, 1), 'VimwikiMultilineComment'
|
||||||
|
AssertEqual SyntaxAt(3, 1), 'VimwikiMultilineComment'
|
||||||
|
AssertEqual SyntaxAt(4, 1), 'VimwikiMultilineComment'
|
||||||
|
AssertEqual SyntaxAt(5, 1), 'VimwikiMultilineComment'
|
||||||
|
|
||||||
|
AssertEqual SyntaxAt(6, 1), 'VimwikiMultilineComment'
|
||||||
|
AssertEqual SyntaxAt(6, 11), 'VimwikiMultilineComment'
|
||||||
|
AssertEqual SyntaxAt(6, 12), ''
|
||||||
|
AssertEqual SyntaxAt(6, 26), ''
|
||||||
|
AssertEqual SyntaxAt(6, 27), 'VimwikiMultilineComment'
|
||||||
|
AssertEqual SyntaxAt(6, 37), 'VimwikiMultilineComment'
|
||||||
|
AssertEqual SyntaxAt(6, 38), ''
|
||||||
|
AssertEqual SyntaxAt(6, 51), ''
|
||||||
|
|
||||||
# 10 Code {{{1
|
# 10 Code {{{1
|
||||||
# 10.1 Code Indent (4 spaces) {{{2
|
# 10.1 Code Indent (4 spaces) {{{2
|
||||||
|
Loading…
Reference in New Issue
Block a user