]> 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:

Code block improvements. Line break highlighting from Daniel Hulme.
[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:         Do something appropriate with image syntax
11 " TODO:         Handle stuff contained within stuff (e.g. headings within blockquotes)
12
13
14 " Read the HTML syntax to start with
15 if version < 600
16   so <sfile>:p:h/html.vim
17 else
18   runtime! syntax/html.vim
19   unlet b:current_syntax
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 htmlBold     start=/\\\@<!\(^\|\A\)\@=\*\@<!\*\*\*\@!/     end=/\\\@<!\*\@<!\*\*\*\@!\($\|\A\)\@=/   contains=@Spell,htmlItalic
41 syn region htmlItalic   start=/\\\@<!\(^\|\A\)\@=\*\@<!\*\*\@!/       end=/\\\@<!\*\@<!\*\*\@!\($\|\A\)\@=/      contains=htmlBold,@Spell
42 syn region htmlBold     start=/\\\@<!\(^\|\A\)\@=_\@<!___\@!/         end=/\\\@<!_\@<!___\@!\($\|\A\)\@=/       contains=htmlItalic,@Spell
43 syn region htmlItalic   start=/\\\@<!\(^\|\A\)\@=_\@<!__\@!/          end=/\\\@<!_\@<!__\@!\($\|\A\)\@=/        contains=htmlBold,@Spell
44 syn region htmlString   start="]("ms=s+2             end=")"me=e-1
45 syn region htmlLink     start="\\\@<!\["ms=s+1            end="\\\@<!\]"me=e-1 contains=@Spell
46 syn region htmlString   start="\(\[.*]: *\)\@<=.*"  end="$"
47
48 "define Markdown groups
49 syn match  mkdLineContinue ".$" contained
50 syn match  mkdRule      /^\s*\*\s\{0,1}\*\s\{0,1}\*$/
51 syn match  mkdRule      /^\s*-\s\{0,1}-\s\{0,1}-$/
52 syn match  mkdRule      /^\s*_\s\{0,1}_\s\{0,1}_$/
53 syn match  mkdRule      /^\s*-\{3,}$/
54 syn match  mkdRule      /^\s*\*\{3,5}$/
55 syn match  mkdListItem  "^\s*[-*+]\s\+"
56 syn match  mkdListItem  "^\s*\d\+\.\s\+"
57 syn match  mkdCode      /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/
58 syn match  mkdLineBreak /  \+$/
59 syn region mkdCode      start=/\\\@<!`/                   end=/\\\@<!`/
60 syn region mkdCode      start=/\s*``[^`]*/          end=/[^`]*``\s*/
61 syn region mkdBlockquote start=/^\s*>/              end=/$/                 contains=mkdLineBreak,mkdLineContinue,@Spell
62 syn region mkdCode      start="<pre[^>]*>"         end="</pre>"
63 syn region mkdCode      start="<code[^>]*>"        end="</code>"
64
65 "HTML headings
66 syn region htmlH1       start="^\s*#"                   end="\($\|#\+\)" contains=@Spell
67 syn region htmlH2       start="^\s*##"                  end="\($\|#\+\)" contains=@Spell
68 syn region htmlH3       start="^\s*###"                 end="\($\|#\+\)" contains=@Spell
69 syn region htmlH4       start="^\s*####"                end="\($\|#\+\)" contains=@Spell
70 syn region htmlH5       start="^\s*#####"               end="\($\|#\+\)" contains=@Spell
71 syn region htmlH6       start="^\s*######"              end="\($\|#\+\)" contains=@Spell
72 syn match  htmlH1       /^.\+\n=\+$/ contains=@Spell
73 syn match  htmlH2       /^.\+\n-\+$/ contains=@Spell
74
75 "highlighting for Markdown groups
76 HtmlHiLink mkdString        String
77 HtmlHiLink mkdCode          String
78 HtmlHiLink mkdBlockquote    Comment
79 HtmlHiLink mkdLineContinue  Comment
80 HtmlHiLink mkdListItem      Identifier
81 HtmlHiLink mkdRule          Identifier
82 HtmlHiLink mkdLineBreak     Todo
83
84 let b:current_syntax = "mkd"
85
86 delcommand HtmlHiLink
87 " vim: ts=8