markdown.vim (7527B)
1 " Vim syntax file 2 " Language: Markdown 3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org> 4 " Filenames: *.markdown 5 " Last Change: 2016 Aug 29 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 for s:type in map(copy(g:markdown_fenced_languages),'matchstr(v:val,"[^=]*$")') 22 if s:type =~ '\.' 23 let b:{matchstr(s:type,'[^.]*')}_subtype = matchstr(s:type,'\.\zs.*') 24 endif 25 exe 'syn include @markdownHighlight'.substitute(s:type,'\.','','g').' syntax/'.matchstr(s:type,'[^.]*').'.vim' 26 unlet! b:current_syntax 27 endfor 28 unlet! s:type 29 30 syn sync minlines=10 31 syn case ignore 32 33 syn match markdownValid '[<>]\c[a-z/$!]\@!' 34 syn match markdownValid '&\%(#\=\w*;\)\@!' 35 36 syn match markdownLineStart "^[<@]\@!" nextgroup=@markdownBlock,htmlSpecialChar 37 38 syn cluster markdownBlock contains=markdownH1,markdownH2,markdownH3,markdownH4,markdownH5,markdownH6,markdownBlockquote,markdownListMarker,markdownOrderedListMarker,markdownCodeBlock,markdownRule 39 syn cluster markdownInline contains=markdownLineBreak,markdownLinkText,markdownItalic,markdownBold,markdownCode,markdownEscape,@htmlTop,markdownError 40 41 syn match markdownH1 "^.\+\n=\+$" contained contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink 42 syn match markdownH2 "^.\+\n-\+$" contained contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink 43 44 syn match markdownHeadingRule "^[=-]\+$" contained 45 46 syn region markdownH1 matchgroup=markdownHeadingDelimiter start="##\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained 47 syn region markdownH2 matchgroup=markdownHeadingDelimiter start="###\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained 48 syn region markdownH3 matchgroup=markdownHeadingDelimiter start="####\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained 49 syn region markdownH4 matchgroup=markdownHeadingDelimiter start="#####\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained 50 syn region markdownH5 matchgroup=markdownHeadingDelimiter start="######\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained 51 syn region markdownH6 matchgroup=markdownHeadingDelimiter start="#######\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained 52 53 syn match markdownBlockquote ">\%(\s\|$\)" contained nextgroup=@markdownBlock 54 55 syn region markdownCodeBlock start=" \| " end="$" contained 56 57 " TODO: real nesting 58 syn match markdownListMarker "\%(\t\| \{0,4\}\)[-*+]\%(\s\+\S\)\@=" contained 59 syn match markdownOrderedListMarker "\%(\t\| \{0,4}\)\<\d\+\.\%(\s\+\S\)\@=" contained 60 61 syn match markdownRule "\* *\* *\*[ *]*$" contained 62 syn match markdownRule "- *- *-[ -]*$" contained 63 64 syn match markdownLineBreak " \{2,\}$" 65 66 syn region markdownIdDeclaration matchgroup=markdownLinkDelimiter start="^ \{0,3\}!\=\[" end="\]:" oneline keepend nextgroup=markdownUrl skipwhite 67 syn match markdownUrl "\S\+" nextgroup=markdownUrlTitle skipwhite contained 68 syn region markdownUrl matchgroup=markdownUrlDelimiter start="<" end=">" oneline keepend nextgroup=markdownUrlTitle skipwhite contained 69 syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+"+ end=+"+ keepend contained 70 syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+'+ end=+'+ keepend contained 71 syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+(+ end=+)+ keepend contained 72 73 syn region markdownLinkText matchgroup=markdownLinkTextDelimiter start="!\=\[\%(\_[^]]*]\%( \=[[(]\)\)\@=" end="\]\%( \=[[(]\)\@=" nextgroup=markdownLink,markdownId skipwhite contains=@markdownInline,markdownLineStart 74 syn region markdownLink matchgroup=markdownLinkDelimiter start="(" end=")" contains=markdownUrl keepend contained 75 syn region markdownId matchgroup=markdownIdDelimiter start="\[" end="\]" keepend contained 76 syn region markdownAutomaticLink matchgroup=markdownUrlDelimiter start="<\%(\w\+:\|[[:alnum:]_+-]\+@\)\@=" end=">" keepend oneline 77 78 let s:concealends = has('conceal') ? ' concealends' : '' 79 exe 'syn region markdownItalic matchgroup=markdownItalicDelimiter start="\S\@<=\*\|\*\S\@=" end="\S\@<=\*\|\*\S\@=" keepend contains=markdownLineStart' . s:concealends 80 exe 'syn region markdownBold matchgroup=markdownBoldDelimiter start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" keepend contains=markdownLineStart,markdownItalic' . s:concealends 81 exe 'syn region markdownBoldItalic matchgroup=markdownBoldItalicDelimiter start="\S\@<=\*\*\*\|\*\*\*\S\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" keepend contains=markdownLineStart' . s:concealends 82 83 syn region markdownCode matchgroup=markdownCodeDelimiter start="`" end="`" keepend contains=markdownLineStart 84 syn region markdownCode matchgroup=markdownCodeDelimiter start="`` \=" end=" \=``" keepend contains=markdownLineStart 85 syn region markdownCode matchgroup=markdownCodeDelimiter start="^\s*```.*$" end="^\s*```\ze\s*$" keepend 86 87 syn match markdownFootnote "\[^[^\]]\+\]" 88 syn match markdownFootnoteDefinition "^\[^[^\]]\+\]:" 89 90 if main_syntax ==# 'markdown' 91 for s:type in g:markdown_fenced_languages 92 exe 'syn region markdownHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\..*','','').' matchgroup=markdownCodeDelimiter start="^\s*```\s*'.matchstr(s:type,'[^=]*').'\>.*$" end="^\s*```\ze\s*$" keepend contains=@markdownHighlight'.substitute(matchstr(s:type,'[^=]*$'),'\.','','g') 93 endfor 94 unlet! s:type 95 endif 96 97 syn match markdownEscape "\\[][\\`*_{}()<>#+.!-]" 98 syn match markdownError "\w\@<=\w\@=" 99 100 hi def link markdownH1 htmlH1 101 hi def link markdownH2 htmlH2 102 hi def link markdownH3 htmlH3 103 hi def link markdownH4 htmlH4 104 hi def link markdownH5 htmlH5 105 hi def link markdownH6 htmlH6 106 hi def link markdownHeadingRule markdownRule 107 hi def link markdownHeadingDelimiter Delimiter 108 hi def link markdownOrderedListMarker markdownListMarker 109 hi def link markdownListMarker htmlTagName 110 hi def link markdownBlockquote Comment 111 hi def link markdownRule PreProc 112 113 hi def link markdownFootnote Typedef 114 hi def link markdownFootnoteDefinition Typedef 115 116 hi def link markdownLinkText htmlLink 117 hi def link markdownIdDeclaration Typedef 118 hi def link markdownId Type 119 hi def link markdownAutomaticLink markdownUrl 120 hi def link markdownUrl Float 121 hi def link markdownUrlTitle String 122 hi def link markdownIdDelimiter markdownLinkDelimiter 123 hi def link markdownUrlDelimiter htmlTag 124 hi def link markdownUrlTitleDelimiter Delimiter 125 126 hi def link markdownItalic htmlItalic 127 hi def link markdownItalicDelimiter markdownItalic 128 hi def link markdownBold htmlBold 129 hi def link markdownBoldDelimiter markdownBold 130 hi def link markdownBoldItalic htmlBoldItalic 131 hi def link markdownBoldItalicDelimiter markdownBoldItalic 132 hi def link markdownCodeDelimiter Delimiter 133 134 hi def link markdownEscape Special 135 hi def link markdownError Error 136 137 let b:current_syntax = "markdown" 138 if main_syntax ==# 'markdown' 139 unlet main_syntax 140 endif 141 142 " vim:set sw=2: