]> git.madduck.net Git - etc/vim.git/blob - syntax/mkd.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

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.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Remove outdated fields from syntax header.
[etc/vim.git] / syntax / mkd.vim
1 " Vim syntax file
2 " Language:     Markdown
3 " Maintainer:   Ben Williams <benw@plasticboy.com>
4 " URL:          http://plasticboy.com/markdown-vim-mode/
5 " Remark:       Uses HTML syntax file
6 " Remark:       I don't do anything with angle brackets (<>) because that would too easily
7 "               easily conflict with HTML syntax
8 " TODO:         Handle stuff contained within stuff (e.g. headings within blockquotes)
9
10
11 " Read the HTML syntax to start with
12 if version < 600
13   so <sfile>:p:h/html.vim
14 else
15   runtime! syntax/html.vim
16
17   if exists('b:current_syntax')
18     unlet b:current_syntax
19   endif
20 endif
21
22 if version < 600
23   syntax clear
24 elseif exists("b:current_syntax")
25   finish
26 endif
27
28 " don't use standard HiLink, it will not work with included syntax files
29 if version < 508
30   command! -nargs=+ HtmlHiLink hi link <args>
31 else
32   command! -nargs=+ HtmlHiLink hi def link <args>
33 endif
34
35 syn spell toplevel
36 syn case ignore
37 syn sync linebreaks=1
38
39 "additions to HTML groups
40 syn region htmlItalic start="\\\@<!\*\S\@=" end="\S\@<=\\\@<!\*" keepend oneline
41 syn region htmlItalic start="\(^\|\s\)\@<=_\|\\\@<!_\([^_]\+\s\)\@=" end="\S\@<=_\|_\S\@=" keepend oneline
42 syn region htmlBold start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" keepend oneline
43 syn region htmlBold start="\S\@<=__\|__\S\@=" end="\S\@<=__\|__\S\@=" keepend oneline
44 syn region htmlBoldItalic start="\S\@<=\*\*\*\|\*\*\*\S\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" keepend oneline
45 syn region htmlBoldItalic start="\S\@<=___\|___\S\@=" end="\S\@<=___\|___\S\@=" keepend oneline
46
47 " [link](URL) | [link][id] | [link][]
48 syn region mkdFootnotes matchgroup=mkdDelimiter start="\[^"    end="\]"
49 syn region mkdID matchgroup=mkdDelimiter        start="\["    end="\]" contained oneline
50 syn region mkdURL matchgroup=mkdDelimiter       start="("     end=")"  contained oneline
51 syn region mkdLink matchgroup=mkdDelimiter      start="\\\@<!\[" end="\]\ze\s*[[(]" contains=@Spell nextgroup=mkdURL,mkdID skipwhite oneline
52 " mkd  inline links:           protocol   optional  user:pass@       sub/domain                 .com, .co.uk, etc      optional port   path/querystring/hash fragment
53 "                            ------------ _____________________ --------------------------- ________________________ ----------------- __
54 syntax match   mkdInlineURL /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*/
55
56 " Link definitions: [id]: URL (Optional Title)
57 " TODO handle automatic links without colliding with htmlTag (<URL>)
58 syn region mkdLinkDef matchgroup=mkdDelimiter   start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
59 syn region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]"   contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline
60 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+     end=+"+  contained
61 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+     end=+'+  contained
62 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+     end=+)+  contained
63
64 "define Markdown groups
65 syn match  mkdLineContinue ".$" contained
66 syn match  mkdLineBreak    /  \+$/
67 syn region mkdBlockquote   start=/^\s*>/                   end=/$/ contains=mkdLineBreak,mkdLineContinue,@Spell
68 syn region mkdCode         start=/\(\([^\\]\|^\)\\\)\@<!`/ end=/\(\([^\\]\|^\)\\\)\@<!`/
69 syn region mkdCode         start=/\s*``[^`]*/              end=/[^`]*``\s*/
70 syn region mkdCode         start=/^\s*```\s*[0-9A-Za-z_-]*\s*$/          end=/^\s*```\s*$/
71 syn region mkdCode         start="<pre[^>]*>"              end="</pre>"
72 syn region mkdCode         start="<code[^>]*>"             end="</code>"
73 syn region mkdFootnote     start="\[^"                     end="\]"
74 syn match  mkdCode         /^\s*\n\(\(\s\{8,}[^ ]\|\t\t\+[^\t]\).*\n\)\+/
75 syn match  mkdIndentCode   /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ contained
76 syn match  mkdListItem     "^\s*[-*+]\s\+"
77 syn match  mkdListItem     "^\s*\d\+\.\s\+"
78 syn region mkdNonListItemBlock start="\n\(\_^\_$\|\s\{4,}[^ ]\|\t+[^\t]\)\@!" end="^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@=" contains=@mkdNonListItem,@Spell
79 syn match  mkdRule         /^\s*\*\s\{0,1}\*\s\{0,1}\*$/
80 syn match  mkdRule         /^\s*-\s\{0,1}-\s\{0,1}-$/
81 syn match  mkdRule         /^\s*_\s\{0,1}_\s\{0,1}_$/
82 syn match  mkdRule         /^\s*-\{3,}$/
83 syn match  mkdRule         /^\s*\*\{3,5}$/
84
85 "HTML headings
86 syn region htmlH1       start="^\s*#"                   end="\($\|#\+\)" contains=@Spell
87 syn region htmlH2       start="^\s*##"                  end="\($\|#\+\)" contains=@Spell
88 syn region htmlH3       start="^\s*###"                 end="\($\|#\+\)" contains=@Spell
89 syn region htmlH4       start="^\s*####"                end="\($\|#\+\)" contains=@Spell
90 syn region htmlH5       start="^\s*#####"               end="\($\|#\+\)" contains=@Spell
91 syn region htmlH6       start="^\s*######"              end="\($\|#\+\)" contains=@Spell
92 syn match  htmlH1       /^.\+\n=\+$/ contains=@Spell
93 syn match  htmlH2       /^.\+\n-\+$/ contains=@Spell
94
95 if get(g:, 'vim_markdown_math', 0)
96   syn region mkdMath matchgroup=mkdDelimiter start="\\\@<!\$" end="\$"
97   syn region mkdMath matchgroup=mkdDelimiter start="\\\@<!\$\$" end="\$\$"
98 endif
99
100 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
101
102 "highlighting for Markdown groups
103 HtmlHiLink mkdString        String
104 HtmlHiLink mkdCode          String
105 HtmlHiLink mkdIndentCode    String
106 HtmlHiLink mkdFootnote    Comment
107 HtmlHiLink mkdBlockquote    Comment
108 HtmlHiLink mkdLineContinue  Comment
109 HtmlHiLink mkdListItem      Identifier
110 HtmlHiLink mkdRule          Identifier
111 HtmlHiLink mkdLineBreak     Todo
112 HtmlHiLink mkdFootnotes     htmlLink
113 HtmlHiLink mkdLink          htmlLink
114 HtmlHiLink mkdURL           htmlString
115 HtmlHiLink mkdInlineURL     htmlLink
116 HtmlHiLink mkdID            Identifier
117 HtmlHiLink mkdLinkDef       mkdID
118 HtmlHiLink mkdLinkDefTarget mkdURL
119 HtmlHiLink mkdLinkTitle     htmlString
120 HtmlHiLink mkdMath          Statement
121 HtmlHiLink mkdDelimiter     Delimiter
122
123 " Automatically insert bullets
124 setlocal formatoptions+=r
125 " Do not automatically insert bullets when auto-wrapping with text-width
126 setlocal formatoptions-=c
127 " Accept various markers as bullets
128 setlocal comments=b:*,b:+,b:-
129
130 " Automatically continue blockquote on line break
131 setlocal comments+=b:>
132
133 let b:current_syntax = "mkd"
134
135 delcommand HtmlHiLink
136 " vim: ts=8