tpope / vim-markdown

Vim Markdown runtime files
1.23k stars 191 forks source link

Prevent false detection of fenced code block start #160

Closed anthony-geoghegan closed 3 years ago

anthony-geoghegan commented 4 years ago

If a line begins (ignoring any space characters) with a word that happens to match one of the languages listed in g:markdown_fenced_languages, the line is wrongly detected as being the start of a fenced code-block for that language.

As an example, the following line would be highlighted as the start of fenced code block and lines immediately following it are highlighted as SQL statements (until a blank line is reached).

SQL (Structured Query Language) is a declarative language

vim-markdown-fenced-code-bug

This bug was introduced in the most recent commit where an extraneous asterisk allows for zero matches of the \z(~\{3,\}\) atom. This pull request should ensure that a line is only treated as the start of a fenced code block if the line begins with three or more consecutive backtick or tilde characters (with optional leading white-space).

bluz71 commented 4 years ago

Thanks for the PR.

I've forked vim-markdown and applied this fix to my fork since this issue is a major deal-breaker. I am surprised more folks have not hit this.

Anyway, I hope this is fixed eventually.

MarkLodato commented 3 years ago

Friendly ping. Any chance this could get merged?

tpope commented 3 years ago

Where the heck did that * come from???

anthony-geoghegan commented 3 years ago

Where the heck did that * come from???

Gremlins!

In fairness, there were already a couple of * in the original start regular expression used to define the syntax region. It’s an easy thing to forget to remove one. Regular expressions are powerful but the syntax isn’t very human-friendly. Having used Vim for close to 20 years, I still have to use trial-and-error to get a complicated pattern to work the way I want (missing backslashes, etc.). Related: http://regex.info/blog/2006-09-15/247