]> git.r.bdr.sh - rbdr/dotfiles/blob - vim/syntax/markdown.vim
Local vim/zsh changes
[rbdr/dotfiles] / vim / syntax / markdown.vim
1 " Vim syntax file
2 " Language: Markdown
3 " Maintainer: Tim Pope <vimNOSPAM@tpope.org>
4 " Filenames: *.markdown
5
6 if exists("b:current_syntax")
7 finish
8 endif
9
10 runtime! syntax/html.vim
11 unlet! b:current_syntax
12
13 syn sync minlines=10
14 syn case ignore
15
16 syn match markdownValid '[<>]\S\@!'
17 syn match markdownValid '&\%(#\=\w*;\)\@!'
18
19 syn match markdownLineStart "^[<@]\@!" nextgroup=@markdownBlock
20
21 syn cluster markdownBlock contains=markdownH1,markdownH2,markdownH3,markdownH4,markdownH5,markdownH6,markdownBlockquote,markdownListMarker,markdownOrderedListMarker,markdownCodeBlock,markdownRule
22 syn cluster markdownInline contains=markdownLineBreak,markdownLinkText,markdownItalic,markdownBold,markdownCode,markdownEscape,@htmlTop
23
24 syn match markdownH1 ".\+\n=\+$" contained contains=@markdownInline,markdownHeadingRule
25 syn match markdownH2 ".\+\n-\+$" contained contains=@markdownInline,markdownHeadingRule
26
27 syn match markdownHeadingRule "^[=-]\+$" contained
28
29 syn region markdownH1 matchgroup=markdownHeadingDelimiter start="##\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained
30 syn region markdownH2 matchgroup=markdownHeadingDelimiter start="###\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained
31 syn region markdownH3 matchgroup=markdownHeadingDelimiter start="####\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained
32 syn region markdownH4 matchgroup=markdownHeadingDelimiter start="#####\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained
33 syn region markdownH5 matchgroup=markdownHeadingDelimiter start="######\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained
34 syn region markdownH6 matchgroup=markdownHeadingDelimiter start="#######\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained
35
36 syn match markdownBlockquote ">\s" contained nextgroup=@markdownBlock
37
38 syn region markdownCodeBlock start=" \|\t" end="$" contained
39
40 " TODO: real nesting
41 syn match markdownListMarker " \{0,4\}[-*+]\%(\s\+\S\)\@=" contained
42 syn match markdownOrderedListMarker " \{0,4}\<\d\+\.\%(\s*\S\)\@=" contained
43
44 syn match markdownRule "\* *\* *\*[ *]*$" contained
45 syn match markdownRule "- *- *-[ -]*$" contained
46
47 syn match markdownLineBreak "\s\{2,\}$"
48
49 syn region markdownIdDeclaration matchgroup=markdownLinkDelimiter start="^ \{0,3\}!\=\[" end="\]:" oneline keepend nextgroup=markdownUrl skipwhite
50 syn match markdownUrl "\S\+" nextgroup=markdownUrlTitle skipwhite contained
51 syn region markdownUrl matchgroup=markdownUrlDelimiter start="<" end=">" oneline keepend nextgroup=markdownUrlTitle skipwhite contained
52 syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+"+ end=+"+ keepend contained
53 syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+'+ end=+'+ keepend contained
54 syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+(+ end=+)+ keepend contained
55
56 syn region markdownLinkText matchgroup=markdownLinkTextDelimiter start="!\=\[\%(\_[^]]*]\%( \=[[(]\)\)\@=" end="\]\%( \=[[(]\)\@=" keepend nextgroup=markdownLink,markdownId skipwhite contains=@markdownInline,markdownLineStart
57 syn region markdownLink matchgroup=markdownLinkDelimiter start="(" end=")" contains=markdownUrl keepend contained
58 syn region markdownId matchgroup=markdownIdDelimiter start="\[" end="\]" keepend contained
59 syn region markdownAutomaticLink matchgroup=markdownUrlDelimiter start="<\%(\w\+:\|[[:alnum:]_+-]\+@\)\@=" end=">" keepend oneline
60
61 syn region markdownItalic start="\S\@<=\*\|\*\S\@=" end="\S\@<=\*\|\*\S\@=" keepend contains=markdownLineStart
62 syn region markdownItalic start="\S\@<=_\|_\S\@=" end="\S\@<=_\|_\S\@=" keepend contains=markdownLineStart
63 syn region markdownBold start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" keepend contains=markdownLineStart
64 syn region markdownBold start="\S\@<=__\|__\S\@=" end="\S\@<=__\|__\S\@=" keepend contains=markdownLineStart
65 syn region markdownBoldItalic start="\S\@<=\*\*\*\|\*\*\*\S\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" keepend contains=markdownLineStart
66 syn region markdownBoldItalic start="\S\@<=___\|___\S\@=" end="\S\@<=___\|___\S\@=" keepend contains=markdownLineStart
67 syn region markdownCode matchgroup=markdownCodeDelimiter start="`" end="`" keepend contains=markdownLineStart
68 syn region markdownCode matchgroup=markdownCodeDelimiter start="`` \=" end=" \=``" keepend contains=markdownLineStart
69 syn region markdownCode matchgroup=markdownCodeDelimiter start="^\s*\zs```\s*\w*\ze\s*$" end="^```\ze\s*$" keepend
70
71 syn match markdownEscape "\\[][\\`*_{}()#+.!-]"
72 syn match markdownError "\w\@<=_\w\@="
73
74 hi def link markdownH1 htmlH1
75 hi def link markdownH2 htmlH2
76 hi def link markdownH3 htmlH3
77 hi def link markdownH4 htmlH4
78 hi def link markdownH5 htmlH5
79 hi def link markdownH6 htmlH6
80 hi def link markdownHeadingRule markdownRule
81 hi def link markdownHeadingDelimiter Delimiter
82 hi def link markdownOrderedListMarker markdownListMarker
83 hi def link markdownListMarker htmlTagName
84 hi def link markdownBlockquote Comment
85 hi def link markdownRule PreProc
86
87 hi def link markdownLinkText htmlLink
88 hi def link markdownIdDeclaration Typedef
89 hi def link markdownId Type
90 hi def link markdownAutomaticLink markdownUrl
91 hi def link markdownUrl Float
92 hi def link markdownUrlTitle String
93 hi def link markdownIdDelimiter markdownLinkDelimiter
94 hi def link markdownUrlDelimiter htmlTag
95 hi def link markdownUrlTitleDelimiter Delimiter
96
97 hi def link markdownItalic htmlItalic
98 hi def link markdownBold htmlBold
99 hi def link markdownBoldItalic htmlBoldItalic
100 hi def link markdownCodeDelimiter Delimiter
101
102 hi def link markdownEscape Special
103 hi def link markdownError Error
104
105 let b:current_syntax = "markdown"
106
107 " vim:set sw=2: