]> git.madduck.net Git - etc/vim.git/blob - 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:

Link improvements from Marc Hartstein.
[etc/vim.git] / 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 " Version:      8
6 " Last Change:  2008 April 29 
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)
11
12
13 " Read the HTML syntax to start with
14 if version < 600
15   so <sfile>:p:h/html.vim
16 else
17   runtime! syntax/html.vim
18   unlet b:current_syntax
19 endif
20
21 if version < 600
22   syntax clear
23 elseif exists("b:current_syntax")
24   finish
25 endif
26
27 " don't use standard HiLink, it will not work with included syntax files
28 if version < 508
29   command! -nargs=+ HtmlHiLink hi link <args>
30 else
31   command! -nargs=+ HtmlHiLink hi def link <args>
32 endif
33
34 syn spell toplevel
35 syn case ignore
36 syn sync linebreaks=1
37
38 "additions to HTML groups
39 syn region htmlBold     start=/\\\@<!\(^\|\A\)\@=\*\@<!\*\*\*\@!/     end=/\\\@<!\*\@<!\*\*\*\@!\($\|\A\)\@=/   contains=@Spell,htmlItalic
40 syn region htmlItalic   start=/\\\@<!\(^\|\A\)\@=\*\@<!\*\*\@!/       end=/\\\@<!\*\@<!\*\*\@!\($\|\A\)\@=/      contains=htmlBold,@Spell
41 syn region htmlBold     start=/\\\@<!\(^\|\A\)\@=_\@<!___\@!/         end=/\\\@<!_\@<!___\@!\($\|\A\)\@=/       contains=htmlItalic,@Spell
42 syn region htmlItalic   start=/\\\@<!\(^\|\A\)\@=_\@<!__\@!/          end=/\\\@<!_\@<!__\@!\($\|\A\)\@=/        contains=htmlBold,@Spell
43
44 " [link](URL) | [link][id] | [link][]
45 syn region mkdLink matchgroup=mkdDelimiter      start="\!\?\[" end="\]\ze\s*[[(]" contains=@Spell nextgroup=mkdURL,mkdID skipwhite oneline
46 syn region mkdID matchgroup=mkdDelimiter        start="\["    end="\]" contained
47 syn region mkdURL matchgroup=mkdDelimiter       start="("     end=")"  contained
48
49 " Link definitions: [id]: URL (Optional Title)
50 " TODO handle automatic links without colliding with htmlTag (<URL>)
51 syn region mkdLinkDef matchgroup=mkdDelimiter   start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
52 syn region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]"   contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline
53 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+     end=+"+  contained
54 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+     end=+'+  contained
55 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+     end=+)+  contained
56
57 "define Markdown groups
58 syn match  mkdLineContinue ".$" contained
59 syn match  mkdRule      /^\s*\*\s\{0,1}\*\s\{0,1}\*$/
60 syn match  mkdRule      /^\s*-\s\{0,1}-\s\{0,1}-$/
61 syn match  mkdRule      /^\s*_\s\{0,1}_\s\{0,1}_$/
62 syn match  mkdRule      /^\s*-\{3,}$/
63 syn match  mkdRule      /^\s*\*\{3,5}$/
64 syn match  mkdListItem  "^\s*[-*+]\s\+"
65 syn match  mkdListItem  "^\s*\d\+\.\s\+"
66 syn match  mkdCode      /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/
67 syn match  mkdLineBreak /  \+$/
68 syn region mkdCode      start=/\\\@<!`/                   end=/\\\@<!`/
69 syn region mkdCode      start=/\s*``[^`]*/          end=/[^`]*``\s*/
70 syn region mkdBlockquote start=/^\s*>/              end=/$/                 contains=mkdLineBreak,mkdLineContinue,@Spell
71 syn region mkdCode      start="<pre[^>]*>"         end="</pre>"
72 syn region mkdCode      start="<code[^>]*>"        end="</code>"
73
74 "HTML headings
75 syn region htmlH1       start="^\s*#"                   end="\($\|#\+\)" contains=@Spell
76 syn region htmlH2       start="^\s*##"                  end="\($\|#\+\)" contains=@Spell
77 syn region htmlH3       start="^\s*###"                 end="\($\|#\+\)" contains=@Spell
78 syn region htmlH4       start="^\s*####"                end="\($\|#\+\)" contains=@Spell
79 syn region htmlH5       start="^\s*#####"               end="\($\|#\+\)" contains=@Spell
80 syn region htmlH6       start="^\s*######"              end="\($\|#\+\)" contains=@Spell
81 syn match  htmlH1       /^.\+\n=\+$/ contains=@Spell
82 syn match  htmlH2       /^.\+\n-\+$/ contains=@Spell
83
84 "highlighting for Markdown groups
85 HtmlHiLink mkdString        String
86 HtmlHiLink mkdCode          String
87 HtmlHiLink mkdBlockquote    Comment
88 HtmlHiLink mkdLineContinue  Comment
89 HtmlHiLink mkdListItem      Identifier
90 HtmlHiLink mkdRule          Identifier
91 HtmlHiLink mkdLineBreak     Todo
92 HtmlHiLink mkdLink          htmlLink
93 HtmlHiLink mkdURL           htmlString
94 HtmlHiLink mkdID            Identifier
95 HtmlHiLink mkdLinkDef       mkdID
96 HtmlHiLink mkdLinkDefTarget mkdURL
97 HtmlHiLink mkdLinkTitle     htmlString
98
99 HtmlHiLink mkdDelimiter     Delimiter
100
101 let b:current_syntax = "mkd"
102
103 delcommand HtmlHiLink
104 " vim: ts=8