vim-pandoc-syntax icon indicating copy to clipboard operation
vim-pandoc-syntax copied to clipboard

``display`` attribute in ``pandocReferenceUrl`` may break folding

Open lyokha opened this issue 8 years ago • 3 comments

I use following pandoc-vim-syntax settings:

let g:pandoc#modules#disabled = ['menu', 'spell']
let g:pandoc#syntax#codeblocks#embeds#langs = ['vim', 'tex', 'sh', 'cpp']
let g:pandoc#formatting#textwidth = 80
let g:pandoc#folding#fold_fenced_codeblocks = 1
let g:pandoc#folding#fdc = 0
let g:pandoc#after#modules#enabled = ["tablemode"]
let g:pandoc#biblio#sources = "b"

Imagine that there is an URL with double underscores within (a bit stupid and certainly rare, but for example links to C++ boost docs that I used may contain them). Here is an example:

    # Example

    Some [stupid link](http://exampe.com/stupid__link).

    ```vim
    echo "Enjoy broken code block"
    ```

    End.

(I had to indent this example by 4 because I do not know how to write markdown in markdown, probably this is the only possible way :) )

In this example folding will be totally broken because pandocReferenceUrl has attribute display, i.e. it is getting skipped while the double underscores are accepted by the vim syntax engine.

Vim doc says:

Generally, you can use "display" for match and region items that meet these conditions: ...

  • The item does not allow other items to match that didn't match otherwise, and that item may extend the match too far. Example for C: A match for a "//" comment can't use "display", because a "/*" inside that comment would match then and start a comment which extends past the end of the line.

As soon as display attribute of the pandocReferenceUrl exposes double underscores within URL and they do match, the folding gets broken.

Here is a little patch against it:

--- vim-pandoc-syntax-master/syntax/pandoc.vim  2016-03-18 16:26:52.000000000 +0300
+++ syntax/pandoc.vim   2016-03-19 13:56:52.326251249 +0300
@@ -248,9 +248,9 @@
 " Base: {{{3
 syn region pandocReferenceLabel matchgroup=pandocOperator start=/!\{,1}\\\@<!\[/ skip=/\(\\\@<!\]\]\@=\|`.*\\\@<!].*`\)/ end=/\\\@<!\]/ keepend display
 if g:pandoc#syntax#conceal#urls == 1
-    syn region pandocReferenceURL matchgroup=pandocOperator start=/\]\@1<=(/ end=/)/ keepend display conceal
+    syn region pandocReferenceURL matchgroup=pandocOperator start=/\]\@1<=(/ end=/)/ keepend conceal
 else
-    syn region pandocReferenceURL matchgroup=pandocOperator start=/\]\@1<=(/ end=/)/ keepend display 
+    syn region pandocReferenceURL matchgroup=pandocOperator start=/\]\@1<=(/ end=/)/ keepend
 endif
 " let's not consider "a [label] a" as a label, remove formatting - Note: breaks implicit links
 syn match pandocNoLabel /\]\@1<!\(\s\{,3}\|^\)\[[^\[\]]\{-}\]\(\s\+\|$\)[\[(]\@!/ contains=pandocPCite
@@ -327,7 +327,7 @@
 " }}}
 " Headers: {{{2
 "
-syn match pandocAtxHeader /\(\%^\|<.\+>.*\n\|^\s*\n\)\@<=#\{1,6}.*\n/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,@Spell, display
+syn match pandocAtxHeader /\(\%^\|<.\+>.*\n\|^\s*\n\)\@<=#\{1,6}.*\n/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,@Spell display
 syn match pandocAtxHeaderMark /\(^#\{1,6}\|\\\@<!#\+\(\s*.*$\)\@=\)/ contained containedin=pandocAtxHeader
 call s:WithConceal("atx", 'syn match pandocAtxStart /#/ contained containedin=pandocAtxHeaderMark', 'conceal cchar='.s:cchars["atx"])
 syn match pandocSetexHeader /^.\+\n[=]\+$/ contains=pandocEmphasis,pandocStrong,pandocNoFormatted,pandocLaTeXInlineMath,@Spell

(I also removed a comma in the second hunk because it looks like a typo!)

lyokha avatar Mar 19 '16 11:03 lyokha