Markdown Vim Mode
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
4.5 KiB

  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. " 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. unlet b:current_syntax
  17. endif
  18. if version < 600
  19. syntax clear
  20. elseif exists("b:current_syntax")
  21. finish
  22. endif
  23. " don't use standard HiLink, it will not work with included syntax files
  24. if version < 508
  25. command! -nargs=+ HtmlHiLink hi link <args>
  26. else
  27. command! -nargs=+ HtmlHiLink hi def link <args>
  28. endif
  29. syn spell toplevel
  30. syn case ignore
  31. syn sync linebreaks=1
  32. "additions to HTML groups
  33. syn region htmlBold start=/\\\@<!\(^\|\A\)\@=\*\@<!\*\*\*\@!/ end=/\\\@<!\*\@<!\*\*\*\@!\($\|\A\)\@=/ contains=@Spell,htmlItalic
  34. syn region htmlItalic start=/\\\@<!\(^\|\A\)\@=\*\@<!\*\*\@!/ end=/\\\@<!\*\@<!\*\*\@!\($\|\A\)\@=/ contains=htmlBold,@Spell
  35. syn region htmlBold start=/\\\@<!\(^\|\A\)\@=_\@<!___\@!/ end=/\\\@<!_\@<!___\@!\($\|\A\)\@=/ contains=htmlItalic,@Spell
  36. syn region htmlItalic start=/\\\@<!\(^\|\A\)\@=_\@<!__\@!/ end=/\\\@<!_\@<!__\@!\($\|\A\)\@=/ contains=htmlBold,@Spell
  37. " [link](URL) | [link][id] | [link][]
  38. syn region mkdLink matchgroup=mkdDelimiter start="\!\?\[" end="\]\ze\s*[[(]" contains=@Spell nextgroup=mkdURL,mkdID skipwhite oneline
  39. syn region mkdID matchgroup=mkdDelimiter start="\[" end="\]" contained
  40. syn region mkdURL matchgroup=mkdDelimiter start="(" end=")" contained
  41. " Link definitions: [id]: URL (Optional Title)
  42. " TODO handle automatic links without colliding with htmlTag (<URL>)
  43. syn region mkdLinkDef matchgroup=mkdDelimiter start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
  44. syn region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]" contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline
  45. syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+ end=+"+ contained
  46. syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+ end=+'+ contained
  47. syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+ end=+)+ contained
  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. "HTML headings
  65. syn region htmlH1 start="^\s*#" end="\($\|#\+\)" contains=@Spell
  66. syn region htmlH2 start="^\s*##" end="\($\|#\+\)" contains=@Spell
  67. syn region htmlH3 start="^\s*###" end="\($\|#\+\)" contains=@Spell
  68. syn region htmlH4 start="^\s*####" end="\($\|#\+\)" contains=@Spell
  69. syn region htmlH5 start="^\s*#####" end="\($\|#\+\)" contains=@Spell
  70. syn region htmlH6 start="^\s*######" end="\($\|#\+\)" contains=@Spell
  71. syn match htmlH1 /^.\+\n=\+$/ contains=@Spell
  72. syn match htmlH2 /^.\+\n-\+$/ contains=@Spell
  73. "highlighting for Markdown groups
  74. HtmlHiLink mkdString String
  75. HtmlHiLink mkdCode String
  76. HtmlHiLink mkdBlockquote Comment
  77. HtmlHiLink mkdLineContinue Comment
  78. HtmlHiLink mkdListItem Identifier
  79. HtmlHiLink mkdRule Identifier
  80. HtmlHiLink mkdLineBreak Todo
  81. HtmlHiLink mkdLink htmlLink
  82. HtmlHiLink mkdURL htmlString
  83. HtmlHiLink mkdID Identifier
  84. HtmlHiLink mkdLinkDef mkdID
  85. HtmlHiLink mkdLinkDefTarget mkdURL
  86. HtmlHiLink mkdLinkTitle htmlString
  87. HtmlHiLink mkdDelimiter Delimiter
  88. let b:current_syntax = "mkd"
  89. delcommand HtmlHiLink
  90. " vim: ts=8