markdown.vim 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. " Vim syntax file
  2. " Language: Markdown
  3. " Author: Ben Williams <benw@plasticboy.com>
  4. " Maintainer: Hallison Batista <email@hallisonbatista.com>
  5. " URL: http://plasticboy.com/markdown-vim-mode/
  6. " Version: 1.0.1
  7. " Last Change: Fri Dec 4 08:36:48 AMT 2009
  8. " Remark: Uses HTML syntax file
  9. " Remark: I don't do anything with angle brackets (<>) because that would too easily
  10. " easily conflict with HTML syntax
  11. " TODO: Handle stuff contained within stuff (e.g. headings within blockquotes)
  12. " Read the HTML syntax to start with
  13. if version < 600
  14. so <sfile>:p:h/html.vim
  15. else
  16. runtime! syntax/html.vim
  17. unlet b:current_syntax
  18. endif
  19. if version < 600
  20. syntax clear
  21. elseif exists("b:current_syntax")
  22. finish
  23. endif
  24. " Don't use standard HiLink, it will not work with included syntax files
  25. if version < 508
  26. command! -nargs=+ HtmlHiLink hi link <args>
  27. else
  28. command! -nargs=+ HtmlHiLink hi def link <args>
  29. endif
  30. syntax spell toplevel
  31. syntax case ignore
  32. syntax sync linebreaks=1
  33. " Additions to HTML groups
  34. syntax region htmlBold start=/\\\@<!\(^\|\A\)\@=\*\@<!\*\*\*\@!/ end=/\\\@<!\*\@<!\*\*\*\@!\($\|\A\)\@=/ contains=htmlItalic,@Spell
  35. syntax region htmlItalic start=/\\\@<!\(^\|\A\)\@=\*\@<!\*\*\@!/ end=/\\\@<!\*\@<!\*\*\@!\($\|\A\)\@=/ contains=htmlBold,@Spell
  36. syntax region htmlBold start=/\\\@<!\(^\|\A\)\@=_\@<!___\@!/ end=/\\\@<!_\@<!___\@!\($\|\A\)\@=/ contains=htmlItalic,@Spell
  37. syntax region htmlItalic start=/\\\@<!\(^\|\A\)\@=_\@<!__\@!/ end=/\\\@<!_\@<!__\@!\($\|\A\)\@=/ contains=htmlBold,@Spell
  38. " [link](URL) | [link][id] | [link][]
  39. syntax region mkdLink matchgroup=mkdDelimiter start="\!\?\[" end="\]\ze\s*[[(]" contains=@Spell nextgroup=mkdURL,mkdID skipwhite oneline
  40. syntax region mkdID matchgroup=mkdDelimiter start="\[" end="\]" contained
  41. syntax region mkdURL matchgroup=mkdDelimiter start="(" end=")" contained
  42. " Link definitions: [id]: URL (Optional Title)
  43. " TODO handle automatic links without colliding with htmlTag (<URL>)
  44. syntax region mkdLinkDef matchgroup=mkdDelimiter start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
  45. syntax region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]" contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline
  46. syntax region mkdLinkTitle matchgroup=mkdDelimiter start=+"+ end=+"+ contained
  47. syntax region mkdLinkTitle matchgroup=mkdDelimiter start=+'+ end=+'+ contained
  48. syntax region mkdLinkTitle matchgroup=mkdDelimiter start=+(+ end=+)+ contained
  49. " Define Markdown groups
  50. syntax match mkdLineContinue ".$" contained
  51. syntax match mkdRule /^\s*\*\s\{0,1}\*\s\{0,1}\*$/
  52. syntax match mkdRule /^\s*-\s\{0,1}-\s\{0,1}-$/
  53. syntax match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_$/
  54. syntax match mkdRule /^\s*-\{3,}$/
  55. syntax match mkdRule /^\s*\*\{3,5}$/
  56. syntax match mkdListItem "^\s*[-*+]\s\+"
  57. syntax match mkdListItem "^\s*\d\+\.\s\+"
  58. syntax match mkdCode /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/
  59. syntax match mkdLineBreak / \+$/
  60. syntax region mkdCode start=/\\\@<!`/ end=/\\\@<!`/
  61. syntax region mkdCode start=/\s*``[^`]*/ end=/[^`]*``\s*/
  62. syntax region mkdBlockquote start=/^\s*>/ end=/$/ contains=mkdLineBreak,mkdLineContinue,@Spell
  63. syntax region mkdCode start="<pre[^>]*>" end="</pre>"
  64. syntax region mkdCode start="<code[^>]*>" end="</code>"
  65. " HTML headings
  66. syntax region htmlH1 start="^\s*#" end="\($\|#\+\)" contains=@Spell
  67. syntax region htmlH2 start="^\s*##" end="\($\|#\+\)" contains=@Spell
  68. syntax region htmlH3 start="^\s*###" end="\($\|#\+\)" contains=@Spell
  69. syntax region htmlH4 start="^\s*####" end="\($\|#\+\)" contains=@Spell
  70. syntax region htmlH5 start="^\s*#####" end="\($\|#\+\)" contains=@Spell
  71. syntax region htmlH6 start="^\s*######" end="\($\|#\+\)" contains=@Spell
  72. syntax match htmlH1 /^.\+\n=\+$/ contains=@Spell
  73. syntax match htmlH2 /^.\+\n-\+$/ contains=@Spell
  74. "highlighting for Markdown groups
  75. HtmlHiLink mkdString String
  76. HtmlHiLink mkdCode String
  77. HtmlHiLink mkdBlockquote Comment
  78. HtmlHiLink mkdLineContinue Comment
  79. HtmlHiLink mkdListItem Identifier
  80. HtmlHiLink mkdRule Identifier
  81. HtmlHiLink mkdLineBreak Todo
  82. HtmlHiLink mkdLink htmlLink
  83. HtmlHiLink mkdURL htmlString
  84. HtmlHiLink mkdID Identifier
  85. HtmlHiLink mkdLinkDef mkdID
  86. HtmlHiLink mkdLinkDefTarget mkdURL
  87. HtmlHiLink mkdLinkTitle htmlString
  88. HtmlHiLink mkdDelimiter Delimiter
  89. let b:current_syntax = "markdown"
  90. delcommand HtmlHiLink
  91. " vim: tabstop=2