vim-pandoc / vim-pandoc-syntax

pandoc markdown syntax, to be installed alongside vim-pandoc
MIT License
424 stars 61 forks source link

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

Open lyokha opened 8 years ago

lyokha commented 8 years ago

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:

``` diff
--- 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!)

fmoralesc commented 8 years ago

Thanks for the report. Can you open a PR with this change? (if not, I'll add it) It looks benign. And yes, that was a typo (or there was something I forgot to add :p ).

lyokha commented 8 years ago

Ok, I'll make a PR. There is another interesting folding issue I'm fighting with, but it seems to regard with general vim settings.

effigies commented 11 months ago

I am seeing this or a very similar issue with anonymous hyperlinks:

I'm writing a `link <https://example.com>`__.                                                   
I'm going to write another link that has the same text but a different
URL, so I used an
`anonymous <https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#toc-entry-52>`_ link.
Now that we can see this incorrectly bolded text, here's another `link <https://another.com>`__.
And now the bold text is gone.

Here's how this renders with syntax=pandoc.rst:

image