All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
3 " Maintainer: Ben Williams <benw@plasticboy.com>
4 " URL: http://plasticboy.com/markdown-vim-mode/
6 " Last Change: 2009 May 18
7 " Remark: Uses HTML syntax file
8 " Remark: I don't do anything with angle brackets (<>) because that would too easily
9 " easily conflict with HTML syntax
10 " TODO: Handle stuff contained within stuff (e.g. headings within blockquotes)
13 " Read the HTML syntax to start with
15 so <sfile>:p:h/html.vim
17 runtime! syntax/html.vim
19 if exists('b:current_syntax')
20 unlet b:current_syntax
26 elseif exists("b:current_syntax")
30 " don't use standard HiLink, it will not work with included syntax files
32 command! -nargs=+ HtmlHiLink hi link <args>
34 command! -nargs=+ HtmlHiLink hi def link <args>
41 "additions to HTML groups
42 syn region htmlItalic start="\\\@<!\*\S\@=" end="\S\@<=\\\@<!\*" keepend oneline
43 syn region htmlItalic start="\(^\|\s\)\@<=_\|\\\@<!_\([^_]\+\s\)\@=" end="\S\@<=_\|_\S\@=" keepend oneline
44 syn region htmlBold start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" keepend oneline
45 syn region htmlBold start="\S\@<=__\|__\S\@=" end="\S\@<=__\|__\S\@=" keepend oneline
46 syn region htmlBoldItalic start="\S\@<=\*\*\*\|\*\*\*\S\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" keepend oneline
47 syn region htmlBoldItalic start="\S\@<=___\|___\S\@=" end="\S\@<=___\|___\S\@=" keepend oneline
49 " [link](URL) | [link][id] | [link][]
50 syn region mkdFootnotes matchgroup=mkdDelimiter start="\[^" end="\]"
51 syn region mkdID matchgroup=mkdDelimiter start="\[" end="\]" contained oneline
52 syn region mkdURL matchgroup=mkdDelimiter start="(" end=")" contained oneline
53 syn region mkdLink matchgroup=mkdDelimiter start="\\\@<!\[" end="\]\ze\s*[[(]" contains=@Spell nextgroup=mkdURL,mkdID skipwhite oneline
54 " mkd inline links: protocol optional user:pass@ sub/domain .com, .co.uk, etc optional port path/querystring/hash fragment
55 " ------------ _____________________ --------------------------- ________________________ ----------------- __
56 syntax match mkdInlineURL /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*/
58 " Link definitions: [id]: URL (Optional Title)
59 " TODO handle automatic links without colliding with htmlTag (<URL>)
60 syn region mkdLinkDef matchgroup=mkdDelimiter start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
61 syn region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]" contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline
62 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+ end=+"+ contained
63 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+ end=+'+ contained
64 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+ end=+)+ contained
66 "define Markdown groups
67 syn match mkdLineContinue ".$" contained
68 syn match mkdLineBreak / \+$/
69 syn region mkdBlockquote start=/^\s*>/ end=/$/ contains=mkdLineBreak,mkdLineContinue,@Spell
70 syn region mkdCode start=/\(\([^\\]\|^\)\\\)\@<!`/ end=/\(\([^\\]\|^\)\\\)\@<!`/
71 syn region mkdCode start=/\s*``[^`]*/ end=/[^`]*``\s*/
72 syn region mkdCode start=/^\s*```\s*[0-9A-Za-z_-]*\s*$/ end=/^\s*```\s*$/
73 syn region mkdCode start="<pre[^>]*>" end="</pre>"
74 syn region mkdCode start="<code[^>]*>" end="</code>"
75 syn region mkdFootnote start="\[^" end="\]"
76 syn match mkdCode /^\s*\n\(\(\s\{8,}[^ ]\|\t\t\+[^\t]\).*\n\)\+/
77 syn match mkdIndentCode /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ contained
78 syn match mkdListItem "^\s*[-*+]\s\+"
79 syn match mkdListItem "^\s*\d\+\.\s\+"
80 syn region mkdNonListItemBlock start="\n\(\_^\_$\|\s\{4,}[^ ]\|\t+[^\t]\)\@!" end="^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@=" contains=@mkdNonListItem,@Spell
81 syn match mkdRule /^\s*\*\s\{0,1}\*\s\{0,1}\*$/
82 syn match mkdRule /^\s*-\s\{0,1}-\s\{0,1}-$/
83 syn match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_$/
84 syn match mkdRule /^\s*-\{3,}$/
85 syn match mkdRule /^\s*\*\{3,5}$/
88 syn region htmlH1 start="^\s*#" end="\($\|#\+\)" contains=@Spell
89 syn region htmlH2 start="^\s*##" end="\($\|#\+\)" contains=@Spell
90 syn region htmlH3 start="^\s*###" end="\($\|#\+\)" contains=@Spell
91 syn region htmlH4 start="^\s*####" end="\($\|#\+\)" contains=@Spell
92 syn region htmlH5 start="^\s*#####" end="\($\|#\+\)" contains=@Spell
93 syn region htmlH6 start="^\s*######" end="\($\|#\+\)" contains=@Spell
94 syn match htmlH1 /^.\+\n=\+$/ contains=@Spell
95 syn match htmlH2 /^.\+\n-\+$/ contains=@Spell
97 if get(g:, 'vim_markdown_math', 0)
98 syn region mkdMath matchgroup=mkdDelimiter start="\\\@<!\$" end="\$"
99 syn region mkdMath matchgroup=mkdDelimiter start="\\\@<!\$\$" end="\$\$"
102 syn cluster mkdNonListItem contains=htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdID,mkdURL,mkdLink,mkdLinkDef,mkdLineBreak,mkdBlockquote,mkdCode,mkdMath,mkdIndentCode,mkdListItem,mkdRule,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6
104 " highlight YAML frontmatter
105 syn include @yamlTop syntax/yaml.vim
106 syntax match Comment /\%^---\_$\_.\{-}\_^---$/ contains=@yamlTop
108 "highlighting for Markdown groups
109 HtmlHiLink mkdString String
110 HtmlHiLink mkdCode String
111 HtmlHiLink mkdIndentCode String
112 HtmlHiLink mkdFootnote Comment
113 HtmlHiLink mkdBlockquote Comment
114 HtmlHiLink mkdLineContinue Comment
115 HtmlHiLink mkdListItem Identifier
116 HtmlHiLink mkdRule Identifier
117 HtmlHiLink mkdLineBreak Todo
118 HtmlHiLink mkdFootnotes htmlLink
119 HtmlHiLink mkdLink htmlLink
120 HtmlHiLink mkdURL htmlString
121 HtmlHiLink mkdInlineURL htmlLink
122 HtmlHiLink mkdID Identifier
123 HtmlHiLink mkdLinkDef mkdID
124 HtmlHiLink mkdLinkDefTarget mkdURL
125 HtmlHiLink mkdLinkTitle htmlString
126 HtmlHiLink mkdMath Statement
127 HtmlHiLink mkdDelimiter Delimiter
129 " Automatically insert bullets
130 setlocal formatoptions+=r
131 " Do not automatically insert bullets when auto-wrapping with text-width
132 setlocal formatoptions-=c
133 " Accept various markers as bullets
134 setlocal comments=b:*,b:+,b:-
136 " Automatically continue blockquote on line break
137 setlocal comments+=b:>
139 let b:current_syntax = "mkd"
141 delcommand HtmlHiLink