Skip to content

Commit b64a485

Browse files
committed
Improve markdownRule syntax matching
- Change existing markdownRule syntax matching rules to match only if preceded by 0-3 spaces and nothing else (in accordance with CommonMark) - Add support for horizontal rules (thematic breaks) using underscores (in accordance with John Gruber's original spec and CommonMark) - Change the italic and bold syntax matching so that they do not collide with horizontal rules composed of asterisks or underscores
1 parent 296eeaa commit b64a485

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

syntax/markdown.vim

+9-8
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ syn region markdownCodeBlock start=" \|\t" end="$" contained
7676
syn match markdownListMarker "\%(\t\| \{0,4\}\)[-*+]\%(\s\+\S\)\@=" contained
7777
syn match markdownOrderedListMarker "\%(\t\| \{0,4}\)\<\d\+\.\%(\s\+\S\)\@=" contained
7878

79-
syn match markdownRule "\* *\* *\*[ *]*$" contained
80-
syn match markdownRule "- *- *-[ -]*$" contained
79+
syn match markdownRule "^ \{0,3\}\* *\* *\*[ *]*$" contained
80+
syn match markdownRule "^ \{0,3\}- *- *-[ -]*$" contained
81+
syn match markdownRule "^ \{0,3\}_ *_ *_[ _]*$" contained
8182

8283
syn match markdownLineBreak " \{2,\}$"
8384

@@ -97,12 +98,12 @@ let s:concealends = ''
9798
if has('conceal') && get(g:, 'markdown_syntax_conceal', 1) == 1
9899
let s:concealends = ' concealends'
99100
endif
100-
exe 'syn region markdownItalic matchgroup=markdownItalicDelimiter start="\S\@<=\*\|\*\S\@=" end="\S\@<=\*\|\*\S\@=" skip="\\\*" contains=markdownLineStart,@Spell' . s:concealends
101-
exe 'syn region markdownItalic matchgroup=markdownItalicDelimiter start="\w\@<!_\S\@=" end="\S\@<=_\w\@!" skip="\\_" contains=markdownLineStart,@Spell' . s:concealends
102-
exe 'syn region markdownBold matchgroup=markdownBoldDelimiter start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" skip="\\\*" contains=markdownLineStart,markdownItalic,@Spell' . s:concealends
103-
exe 'syn region markdownBold matchgroup=markdownBoldDelimiter start="\w\@<!__\S\@=" end="\S\@<=__\w\@!" skip="\\_" contains=markdownLineStart,markdownItalic,@Spell' . s:concealends
104-
exe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\S\@<=\*\*\*\|\*\*\*\S\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" skip="\\\*" contains=markdownLineStart,@Spell' . s:concealends
105-
exe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\w\@<!___\S\@=" end="\S\@<=___\w\@!" skip="\\_" contains=markdownLineStart,@Spell' . s:concealends
101+
exe 'syn region markdownItalic matchgroup=markdownItalicDelimiter start="\%(\S\&[^\*]\)\@<=\*\|\*\%(\S\&[^\*]\)\@=" end="\S\@<=\*\|\*\S\@=" skip="\\\*" contains=markdownLineStart,@Spell' . s:concealends
102+
exe 'syn region markdownItalic matchgroup=markdownItalicDelimiter start="\w\@<!_\%(\S\&[^_]\)\@=" end="\S\@<=_\w\@!" skip="\\_" contains=markdownLineStart,@Spell' . s:concealends
103+
exe 'syn region markdownBold matchgroup=markdownBoldDelimiter start="\%(\S\&[^\*]\)\@<=\*\*\|\*\*\%(\S\&[^\*]\)\@=" end="\S\@<=\*\*\|\*\*\S\@=" skip="\\\*" contains=markdownLineStart,markdownItalic,@Spell' . s:concealends
104+
exe 'syn region markdownBold matchgroup=markdownBoldDelimiter start="\w\@<!__\%(\S\&[^_]\)\@=" end="\S\@<=__\w\@!" skip="\\_" contains=markdownLineStart,markdownItalic,@Spell' . s:concealends
105+
exe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\%(\S\&[^\*]\)\@<=\*\*\*\|\*\*\*\%(\S\&[^\*]\)\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" skip="\\\*" contains=markdownLineStart,@Spell' . s:concealends
106+
exe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\w\@<!___\%(\S\&[^_]\)\@=" end="\S\@<=___\w\@!" skip="\\_" contains=markdownLineStart,@Spell' . s:concealends
106107

107108
syn region markdownCode matchgroup=markdownCodeDelimiter start="`" end="`" keepend contains=markdownLineStart
108109
syn region markdownCode matchgroup=markdownCodeDelimiter start="`` \=" end=" \=``" keepend contains=markdownLineStart

0 commit comments

Comments
 (0)