|
| 1 | +" Vim syntax file |
| 2 | +" Language: Markdown |
| 3 | +" Maintainer: Tim Pope <[email protected]> |
| 4 | +" Filenames: *.markdown |
| 5 | +" Last Change: 2013 May 30 |
| 6 | + |
| 7 | +if exists("b:current_syntax") |
| 8 | + finish |
| 9 | +endif |
| 10 | + |
| 11 | +if !exists('main_syntax') |
| 12 | + let main_syntax = 'markdown' |
| 13 | +endif |
| 14 | + |
| 15 | +runtime! syntax/html.vim |
| 16 | +unlet! b:current_syntax |
| 17 | + |
| 18 | +if !exists('g:markdown_fenced_languages') |
| 19 | + let g:markdown_fenced_languages = [] |
| 20 | +endif |
| 21 | +let s:done_include = {} |
| 22 | +for s:type in map(copy(g:markdown_fenced_languages),'matchstr(v:val,"[^=]*$")') |
| 23 | + if has_key(s:done_include, matchstr(s:type,'[^.]*')) |
| 24 | + continue |
| 25 | + endif |
| 26 | + if s:type =~ '\.' |
| 27 | + let b:{matchstr(s:type,'[^.]*')}_subtype = matchstr(s:type,'\.\zs.*') |
| 28 | + endif |
| 29 | + exe 'syn include @markdownHighlight'.substitute(s:type,'\.','','g').' syntax/'.matchstr(s:type,'[^.]*').'.vim' |
| 30 | + unlet! b:current_syntax |
| 31 | + let s:done_include[matchstr(s:type,'[^.]*')] = 1 |
| 32 | +endfor |
| 33 | +unlet! s:type |
| 34 | +unlet! s:done_include |
| 35 | + |
| 36 | +if !exists('g:markdown_minlines') |
| 37 | + let g:markdown_minlines = 50 |
| 38 | +endif |
| 39 | +execute 'syn sync minlines=' . g:markdown_minlines |
| 40 | +syn case ignore |
| 41 | + |
| 42 | +syn match markdownValid '[<>]\c[a-z/$!]\@!' |
| 43 | +syn match markdownValid '&\%(#\=\w*;\)\@!' |
| 44 | + |
| 45 | +syn match markdownLineStart "^[<@]\@!" nextgroup=@markdownBlock,htmlSpecialChar |
| 46 | + |
| 47 | +syn cluster markdownBlock contains=markdownH1,markdownH2,markdownH3,markdownH4,markdownH5,markdownH6,markdownBlockquote,markdownListMarker,markdownOrderedListMarker,markdownCodeBlock,markdownRule |
| 48 | +syn cluster markdownInline contains=markdownLineBreak,markdownLinkText,markdownItalic,markdownBold,markdownCode,markdownEscape,@htmlTop,markdownError |
| 49 | + |
| 50 | +syn match markdownH1 "^.\+\n=\+$" contained contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink |
| 51 | +syn match markdownH2 "^.\+\n-\+$" contained contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink |
| 52 | + |
| 53 | +syn match markdownHeadingRule "^[=-]\+$" contained |
| 54 | + |
| 55 | +syn region markdownH1 matchgroup=markdownH1Delimiter start="##\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained |
| 56 | +syn region markdownH2 matchgroup=markdownH2Delimiter start="###\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained |
| 57 | +syn region markdownH3 matchgroup=markdownH3Delimiter start="####\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained |
| 58 | +syn region markdownH4 matchgroup=markdownH4Delimiter start="#####\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained |
| 59 | +syn region markdownH5 matchgroup=markdownH5Delimiter start="######\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained |
| 60 | +syn region markdownH6 matchgroup=markdownH6Delimiter start="#######\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained |
| 61 | + |
| 62 | +syn match markdownBlockquote ">\%(\s\|$\)" contained nextgroup=@markdownBlock |
| 63 | + |
| 64 | +syn region markdownCodeBlock start=" \|\t" end="$" contained |
| 65 | + |
| 66 | +" TODO: real nesting |
| 67 | +syn match markdownListMarker "\%(\t\| \{0,4\}\)[-*+]\%(\s\+\S\)\@=" contained |
| 68 | +syn match markdownOrderedListMarker "\%(\t\| \{0,4}\)\<\d\+\.\%(\s\+\S\)\@=" contained |
| 69 | + |
| 70 | +syn match markdownRule "\* *\* *\*[ *]*$" contained |
| 71 | +syn match markdownRule "- *- *-[ -]*$" contained |
| 72 | + |
| 73 | +syn match markdownLineBreak " \{2,\}$" |
| 74 | + |
| 75 | +syn region markdownIdDeclaration matchgroup=markdownLinkDelimiter start="^ \{0,3\}!\=\[" end="\]:" oneline keepend nextgroup=markdownUrl skipwhite |
| 76 | +syn match markdownUrl "\S\+" nextgroup=markdownUrlTitle skipwhite contained |
| 77 | +syn region markdownUrl matchgroup=markdownUrlDelimiter start="<" end=">" oneline keepend nextgroup=markdownUrlTitle skipwhite contained |
| 78 | +syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+"+ end=+"+ keepend contained |
| 79 | +syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+'+ end=+'+ keepend contained |
| 80 | +syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+(+ end=+)+ keepend contained |
| 81 | + |
| 82 | +syn region markdownLinkText matchgroup=markdownLinkTextDelimiter start="!\=\[\%(\_[^]]*]\%( \=[[(]\)\)\@=" end="\]\%( \=[[(]\)\@=" nextgroup=markdownLink,markdownId skipwhite contains=@markdownInline,markdownLineStart |
| 83 | +syn region markdownLink matchgroup=markdownLinkDelimiter start="(" end=")" contains=markdownUrl keepend contained |
| 84 | +syn region markdownId matchgroup=markdownIdDelimiter start="\[" end="\]" keepend contained |
| 85 | +syn region markdownAutomaticLink matchgroup=markdownUrlDelimiter start="<\%(\w\+:\|[[:alnum:]_+-]\+@\)\@=" end=">" keepend oneline |
| 86 | + |
| 87 | +let s:concealends = '' |
| 88 | +if has('conceal') && get(g:, 'markdown_syntax_conceal', 1) == 1 |
| 89 | + let s:concealends = ' concealends' |
| 90 | +endif |
| 91 | +exe 'syn region markdownItalic matchgroup=markdownItalicDelimiter start="\S\@<=\*\|\*\S\@=" end="\S\@<=\*\|\*\S\@=" keepend contains=markdownLineStart,@Spell' . s:concealends |
| 92 | +exe 'syn region markdownItalic matchgroup=markdownItalicDelimiter start="\S\@<=_\|_\S\@=" end="\S\@<=_\|_\S\@=" keepend contains=markdownLineStart,@Spell' . s:concealends |
| 93 | +exe 'syn region markdownBold matchgroup=markdownBoldDelimiter start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" keepend contains=markdownLineStart,markdownItalic,@Spell' . s:concealends |
| 94 | +exe 'syn region markdownBold matchgroup=markdownBoldDelimiter start="\S\@<=__\|__\S\@=" end="\S\@<=__\|__\S\@=" keepend contains=markdownLineStart,markdownItalic,@Spell' . s:concealends |
| 95 | +exe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\S\@<=\*\*\*\|\*\*\*\S\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" keepend contains=markdownLineStart,@Spell' . s:concealends |
| 96 | +exe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\S\@<=___\|___\S\@=" end="\S\@<=___\|___\S\@=" keepend contains=markdownLineStart,@Spell' . s:concealends |
| 97 | + |
| 98 | +syn region markdownCode matchgroup=markdownCodeDelimiter start="`" end="`" keepend contains=markdownLineStart |
| 99 | +syn region markdownCode matchgroup=markdownCodeDelimiter start="`` \=" end=" \=``" keepend contains=markdownLineStart |
| 100 | +syn region markdownCode matchgroup=markdownCodeDelimiter start="^\s*````*.*$" end="^\s*````*\ze\s*$" keepend |
| 101 | + |
| 102 | +syn match markdownFootnote "\[^[^\]]\+\]" |
| 103 | +syn match markdownFootnoteDefinition "^\[^[^\]]\+\]:" |
| 104 | + |
| 105 | +if main_syntax ==# 'markdown' |
| 106 | + let s:done_include = {} |
| 107 | + for s:type in g:markdown_fenced_languages |
| 108 | + if has_key(s:done_include, matchstr(s:type,'[^.]*')) |
| 109 | + continue |
| 110 | + endif |
| 111 | + exe 'syn region markdownHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\..*','','').' matchgroup=markdownCodeDelimiter start="^\s*````*\s*'.matchstr(s:type,'[^=]*').'\S\@!.*$" end="^\s*````*\ze\s*$" keepend contains=@markdownHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\.','','g') |
| 112 | + let s:done_include[matchstr(s:type,'[^.]*')] = 1 |
| 113 | + endfor |
| 114 | + unlet! s:type |
| 115 | + unlet! s:done_include |
| 116 | +endif |
| 117 | + |
| 118 | +syn match markdownEscape "\\[][\\`*_{}()<>#+.!-]" |
| 119 | +syn match markdownError "\w\@<=_\w\@=" |
| 120 | + |
| 121 | +hi def link markdownH1 htmlH1 |
| 122 | +hi def link markdownH2 htmlH2 |
| 123 | +hi def link markdownH3 htmlH3 |
| 124 | +hi def link markdownH4 htmlH4 |
| 125 | +hi def link markdownH5 htmlH5 |
| 126 | +hi def link markdownH6 htmlH6 |
| 127 | +hi def link markdownHeadingRule markdownRule |
| 128 | +hi def link markdownH1Delimiter markdownHeadingDelimiter |
| 129 | +hi def link markdownH2Delimiter markdownHeadingDelimiter |
| 130 | +hi def link markdownH3Delimiter markdownHeadingDelimiter |
| 131 | +hi def link markdownH4Delimiter markdownHeadingDelimiter |
| 132 | +hi def link markdownH5Delimiter markdownHeadingDelimiter |
| 133 | +hi def link markdownH6Delimiter markdownHeadingDelimiter |
| 134 | +hi def link markdownHeadingDelimiter Delimiter |
| 135 | +hi def link markdownOrderedListMarker markdownListMarker |
| 136 | +hi def link markdownListMarker htmlTagName |
| 137 | +hi def link markdownBlockquote Comment |
| 138 | +hi def link markdownRule PreProc |
| 139 | + |
| 140 | +hi def link markdownFootnote Typedef |
| 141 | +hi def link markdownFootnoteDefinition Typedef |
| 142 | + |
| 143 | +hi def link markdownLinkText htmlLink |
| 144 | +hi def link markdownIdDeclaration Typedef |
| 145 | +hi def link markdownId Type |
| 146 | +hi def link markdownAutomaticLink markdownUrl |
| 147 | +hi def link markdownUrl Float |
| 148 | +hi def link markdownUrlTitle String |
| 149 | +hi def link markdownIdDelimiter markdownLinkDelimiter |
| 150 | +hi def link markdownUrlDelimiter htmlTag |
| 151 | +hi def link markdownUrlTitleDelimiter Delimiter |
| 152 | + |
| 153 | +hi def link markdownItalic htmlItalic |
| 154 | +hi def link markdownItalicDelimiter markdownItalic |
| 155 | +hi def link markdownBold htmlBold |
| 156 | +hi def link markdownBoldDelimiter markdownBold |
| 157 | +hi def link markdownBoldItalic htmlBoldItalic |
| 158 | +hi def link markdownBoldItalicDelimiter markdownBoldItalic |
| 159 | +hi def link markdownCodeDelimiter Delimiter |
| 160 | + |
| 161 | +hi def link markdownEscape Special |
| 162 | +hi def link markdownError Error |
| 163 | + |
| 164 | +let b:current_syntax = "markdown" |
| 165 | +if main_syntax ==# 'markdown' |
| 166 | + unlet main_syntax |
| 167 | +endif |
| 168 | + |
| 169 | +" vim:set sw=2: |
0 commit comments