How to stop Vim markdown syntax from highlighting as italic asterisks used to denote bold?

1

Using Vim 7.4 on Windows in ConEmu (though I have seen the same thing on other platforms/setups), I notice that the syntax highlighting is matching the beginning and ending double-asterisks as italic sub-regions within the bold region that they denote. This is an eyesore:

Vim markdown highlighting asterisks as italics in bold area

After digging around, I think I have found the source of this problem (from $VIMRUNTIME/syntax/markdown.vim):

syn region markdownItalic start="\S\@<=\*\|\*\S\@=" end="\S\@<=\*\|\*\S\@=" keepend contains=markdownLineStart
syn region markdownItalic start="\S\@<=_\|_\S\@=" end="\S\@<=_\|_\S\@=" keepend contains=markdownLineStart
syn region markdownBold start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" keepend contains=markdownLineStart,markdownItalic
syn region markdownBold start="\S\@<=__\|__\S\@=" end="\S\@<=__\|__\S\@=" keepend contains=markdownLineStart,markdownItalic
syn region markdownBoldItalic start="\S\@<=\*\*\*\|\*\*\*\S\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" keepend contains=markdownLineStart
syn region markdownBoldItalic start="\S\@<=___\|___\S\@=" end="\S\@<=___\|___\S\@=" keepend contains=markdownLineStart

And farther down:

hi def link markdownItalic                htmlItalic
hi def link markdownBold                  htmlBold
hi def link markdownBoldItalic            htmlBoldItalic

As you can see, the bold accepts italics as a subregion. The problem is if I remove markdownItalic from the contains=, this:

bold and italic working

no longer works right:

bold and italic goofed up

even though it fixed the other problem. I also trying substituting \S in the regexes for italic to be [^*] but that didn't work either. Also, installing Plastic Boy's Markdown plugin didn't fix it.

Any ideas on how to get around this annoying case?

Kazark

Posted 2014-08-11T17:30:57.753

Reputation: 2 871

Another thing I don't understand is why the start and end are being matched as the same thing with an or in the middle. It would seem to me that one have of the or should be for start and one half for end. But then again, when you get regexes this complicated, it gets hard to know what all is going on and why... – Kazark – 2014-08-12T20:51:56.127

Figure out any solutions here? – George Mauer – 2015-04-29T13:42:19.977

Answers

1

So this basic concept does work:

I also trying substituting \S in the regexes for italic to be [^*] but that didn't work either.

Just copy $VIMRUNTIME/syntax/markdown.vim into ~/.vim/syntax/ and change the two syn region markdownItalic... lines to be

syn region markdownItalic start="[^* ]\@<=\*\*\@!\|\*\@<!\*[^* ]\@=" end="[^* ]\@<=\*\|\*\@<!\*[^* ]\@=" keepend contains=markdownLineStart
syn region markdownItalic start="[^_ ]\@<=__\@!\|_\@<!_[^_]\@=" end="[^_ ]\@<=_\|_\@<!_[^_]\@=" keepend contains=markdownLineStart

Also, notably, it seems Tim Pope's current vim-markdown does not have the problem (though as of this writing it has others related to italics; it seems this is a difficult problem to solve with Vim syntax highlighting).

Kazark

Posted 2014-08-11T17:30:57.753

Reputation: 2 871