diff --git a/autoload/vimwiki/html.vim b/autoload/vimwiki/html.vim index 07d0828..c1d2f0f 100644 --- a/autoload/vimwiki/html.vim +++ b/autoload/vimwiki/html.vim @@ -1245,6 +1245,7 @@ function! s:parse_line(line, state) abort let state.para = a:state.para let state.quote = a:state.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.math = a:state.math[:] let state.table = a:state.table[:] @@ -1257,6 +1258,40 @@ function! s:parse_line(line, state) abort let processed = 0 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 " allows insertion of plain text to the final html conversion " for example: @@ -1296,7 +1331,7 @@ function! s:parse_line(line, state) abort endif endif - let line = s:safe_html_line(a:line) + let line = s:safe_html_line(line) " pres if !processed @@ -1326,7 +1361,6 @@ function! s:parse_line(line, state) abort call extend(res_lines, lines) endif - if !processed if line =~# vimwiki#vars#get_syntaxlocal('rxComment') let processed = 1 @@ -1603,6 +1637,7 @@ function! s:convert_file_to_lines(wikifile, current_html_file) abort let state.para = 0 let state.quote = 0 let state.arrow_quote = 0 + let state.active_multiline_comment = 0 let state.pre = [0, 0] " [in_pre, indent_pre] let state.math = [0, 0] " [in_math, indent_math] let state.table = [] diff --git a/doc/vimwiki.txt b/doc/vimwiki.txt index ddf8c8d..a9ef944 100644 --- a/doc/vimwiki.txt +++ b/doc/vimwiki.txt @@ -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.: +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* @@ -3706,6 +3715,7 @@ http://code.google.com/p/vimwiki/issues/list. They may be accessible from https://github.com/vimwiki-backup/vimwiki/issues. New:~ + * PR #967: Add multiline comment support via %%+ and +%% * Issue #942: Fixing wrong html link conversion in windows * PR #946: Add option |g:vimwiki_commentstring| to customize commentstring * Issue #940: Render table header inside thead element and rest under diff --git a/syntax/vimwiki.vim b/syntax/vimwiki.vim index 588954d..e3e8f76 100644 --- a/syntax/vimwiki.vim +++ b/syntax/vimwiki.vim @@ -348,6 +348,14 @@ if vimwiki#vars#get_global('valid_html_tags') !=? '' execute 'syntax match VimwikiComment /'.vimwiki#vars#get_syntaxlocal('rxComment'). \ '/ 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 " tags @@ -425,6 +433,7 @@ hi def link VimwikiSubScriptT VimwikiSubScript hi def link VimwikiTodo Todo hi def link VimwikiComment Comment +hi def link VimwikiMultilineComment Comment hi def link VimwikiPlaceholder SpecialKey hi def link VimwikiPlaceholderParam String @@ -487,4 +496,3 @@ call vimwiki#base#nested_syntax('tex', syntax spell toplevel - diff --git a/syntax/vimwiki_default.vim b/syntax/vimwiki_default.vim index 1fcbdec..237ebe0 100644 --- a/syntax/vimwiki_default.vim +++ b/syntax/vimwiki_default.vim @@ -95,6 +95,8 @@ let s:default_syntax.rxPreEnd = '}}}' let s:default_syntax.rxMathStart = '{{\$' 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.rxTags = '\%(^\|\s\)\@<=:\%([^:''[:space:]]\+:\)\+\%(\s\|$\)\@=' diff --git a/syntax/vimwiki_markdown.vim b/syntax/vimwiki_markdown.vim index b0849e1..9240d77 100644 --- a/syntax/vimwiki_markdown.vim +++ b/syntax/vimwiki_markdown.vim @@ -89,6 +89,9 @@ let s:markdown_syntax.rxPreEnd = '\%(`\{3,}\|\~\{3,}\)' let s:markdown_syntax.rxMathStart = '\$\$' 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.rxTags = '\%(^\|\s\)\@<=:\%([^:[:space:]]\+:\)\+\%(\s\|$\)\@=' diff --git a/syntax/vimwiki_media.vim b/syntax/vimwiki_media.vim index 6287c7c..8c3de45 100644 --- a/syntax/vimwiki_media.vim +++ b/syntax/vimwiki_media.vim @@ -70,6 +70,9 @@ let s:media_syntax.rxPreEnd = '<\/pre>' let s:media_syntax.rxMathStart = '{{\$' 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.rxTags = '\%(^\|\s\)\@<=:\%([^:[:space:]]\+:\)\+\%(\s\|$\)\@=' diff --git a/test/convert_default_html.vader b/test/convert_default_html.vader index 61b80cd..4644df4 100644 --- a/test/convert_default_html.vader +++ b/test/convert_default_html.vader @@ -4,8 +4,54 @@ Execute (Copy Wiki's Resources): Log "Start: Copy Resources" 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()\ +# Keep only body + ggd/\ + +Expect (Comments Removed): + + +

+ This is some text + Test1 + Test2 + Test3 +

+ + + + +

+ Final text +

+ + + + + +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): | header1 | header2 | | val1 | val2 | @@ -127,7 +173,6 @@ Execute(Delete): call DeleteFile('$HOME/testwiki/test_html_table.wiki') call DeleteFile('$HOME/html/default/test_html_table.html') - ################################################# Execute (Log): Log '#473: Syntax "local:" doesnt work as expected. #473' @@ -174,11 +219,11 @@ Do (Get Html body): Expect (Local link): - +

Link

- + @@ -226,7 +271,7 @@ Do (Get Html body): 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" diff --git a/test/syntax.vader b/test/syntax.vader index 3fdd5d6..bbc56cc 100644 --- a/test/syntax.vader +++ b/test/syntax.vader @@ -171,6 +171,47 @@ Execute (Assert Syntax Header): AssertEqual SyntaxAt(5, 10), 'VimwikiHeader5' 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.1 Code Indent (4 spaces) {{{2