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.

140 lines
7.7 KiB

11 years ago
13 years ago
13 years ago
  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. " TODO: Handle stuff contained within stuff (e.g. headings within blockquotes)
  7. " Read the HTML syntax to start with
  8. if version < 600
  9. so <sfile>:p:h/html.vim
  10. else
  11. runtime! syntax/html.vim
  12. if exists('b:current_syntax')
  13. unlet b:current_syntax
  14. endif
  15. endif
  16. if version < 600
  17. syntax clear
  18. elseif exists("b:current_syntax")
  19. finish
  20. endif
  21. " don't use standard HiLink, it will not work with included syntax files
  22. if version < 508
  23. command! -nargs=+ HtmlHiLink hi link <args>
  24. else
  25. command! -nargs=+ HtmlHiLink hi def link <args>
  26. endif
  27. syn spell toplevel
  28. syn case ignore
  29. syn sync linebreaks=1
  30. "additions to HTML groups
  31. syn region htmlItalic start="\\\@<!\*\S\@=" end="\S\@<=\\\@<!\*" keepend oneline
  32. syn region htmlItalic start="\(^\|\s\)\@<=_\|\\\@<!_\([^_]\+\s\)\@=" end="\S\@<=_\|_\S\@=" keepend oneline
  33. syn region htmlBold start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" keepend oneline
  34. syn region htmlBold start="\S\@<=__\|__\S\@=" end="\S\@<=__\|__\S\@=" keepend oneline
  35. syn region htmlBoldItalic start="\S\@<=\*\*\*\|\*\*\*\S\@=" end="\S\@<=\*\*\*\|\*\*\*\S\@=" keepend oneline
  36. syn region htmlBoldItalic start="\S\@<=___\|___\S\@=" end="\S\@<=___\|___\S\@=" keepend oneline
  37. " [link](URL) | [link][id] | [link][]
  38. syn region mkdFootnotes matchgroup=mkdDelimiter start="\[^" end="\]"
  39. syn region mkdID matchgroup=mkdDelimiter start="\[" end="\]" contained oneline
  40. syn region mkdURL matchgroup=mkdDelimiter start="(" end=")" contained oneline
  41. syn region mkdLink matchgroup=mkdDelimiter start="\\\@<!\[" end="\]\ze\s*[[(]" contains=@Spell nextgroup=mkdURL,mkdID skipwhite oneline
  42. " Autolink without angle brackets.
  43. " mkd inline links: protocol optional user:pass@ sub/domain .com, .co.uk, etc optional port path/querystring/hash fragment
  44. " ------------ _____________________ --------------------------- ________________________ ----------------- __
  45. syntax match mkdInlineURL /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*/
  46. " Autolink with angle brackets.
  47. syn region mkdInlineURL matchgroup=mkdDelimiter start="\\\@<!<\(\(coap\|doi\|javascript\|aaa\|aaas\|about\|acap\|cap\|cid\|crid\|data\|dav\|dict\|dns\|file\|ftp\|geo\|go\|gopher\|h323\|http\|https\|iax\|icap\|im\|imap\|info\|ipp\|iris\|iris.beep\|iris.xpc\|iris.xpcs\|iris.lwz\|ldap\|mailto\|mid\|msrp\|msrps\|mtqp\|mupdate\|news\|nfs\|ni\|nih\|nntp\|opaquelocktoken\|pop\|pres\|rtsp\|service\|session\|shttp\|sieve\|sip\|sips\|sms\|snmp,soap.beep\|soap.beeps\|tag\|tel\|telnet\|tftp\|thismessage\|tn3270\|tip\|tv\|urn\|vemmi\|ws\|wss\|xcon\|xcon-userid\|xmlrpc.beep\|xmlrpc.beeps\|xmpp\|z39.50r\|z39.50s\|adiumxtra\|afp\|afs\|aim\|apt,attachment\|aw\|beshare\|bitcoin\|bolo\|callto\|chrome,chrome-extension\|com-eventbrite-attendee\|content\|cvs,dlna-playsingle\|dlna-playcontainer\|dtn\|dvb\|ed2k\|facetime\|feed\|finger\|fish\|gg\|git\|gizmoproject\|gtalk\|hcp\|icon\|ipn\|irc\|irc6\|ircs\|itms\|jar\|jms\|keyparc\|lastfm\|ldaps\|magnet\|maps\|market,message\|mms\|ms-help\|msnim\|mumble\|mvn\|notes\|oid\|palm\|paparazzi\|platform\|proxy\|psyc\|query\|res\|resource\|rmi\|rsync\|rtmp\|secondlife\|sftp\|sgn\|skype\|smb\|soldat\|spotify\|ssh\|steam\|svn\|teamspeak\|things\|udp\|unreal\|ut2004\|ventrilo\|view-source\|webcal\|wtai\|wyciwyg\|xfire\|xri\|ymsgr\):\/\/[^> ]*>\)\@=" end=">"
  48. " Link definitions: [id]: URL (Optional Title)
  49. syn region mkdLinkDef matchgroup=mkdDelimiter start="^ \{,3}\zs\[" end="]:" oneline nextgroup=mkdLinkDefTarget skipwhite
  50. syn region mkdLinkDefTarget start="<\?\zs\S" excludenl end="\ze[>[:space:]\n]" contained nextgroup=mkdLinkTitle,mkdLinkDef skipwhite skipnl oneline
  51. syn region mkdLinkTitle matchgroup=mkdDelimiter start=+"+ end=+"+ contained
  52. syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+ end=+'+ contained
  53. syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+ end=+)+ contained
  54. "define Markdown groups
  55. syn match mkdLineContinue ".$" contained
  56. syn match mkdLineBreak / \+$/
  57. syn region mkdBlockquote start=/^\s*>/ end=/$/ contains=mkdLineBreak,mkdLineContinue,@Spell
  58. syn region mkdCode start=/\(\([^\\]\|^\)\\\)\@<!`/ end=/\(\([^\\]\|^\)\\\)\@<!`/
  59. syn region mkdCode start=/\s*``[^`]*/ end=/[^`]*``\s*/
  60. "code block...
  61. syn region mkdCode start=/^\s*```\s*[0-9A-Za-z_-]*\s*$/ end=/^\s*```\s*$/
  62. syn region mkdCode start=/^\s*```[0-9A-Za-z_$()-]*\s*[0-9A-Za-z_-]*\s*$/ end=/^\s*```\s*$/
  63. syn region mkdCode start=/\s*\~\~[^\~]*/ end=/[^\~]*\~\~\s*/
  64. syn region mkdCode start=/^\s*\~\~\~\s*[0-9A-Za-z_-]*\s*$/ end=/^\s*\~\~\~\s*$/
  65. syn region mkdCode start="<pre[^>]*>" end="</pre>"
  66. syn region mkdCode start="<code[^>]*>" end="</code>"
  67. syn region mkdFootnote start="\[^" end="\]"
  68. syn match mkdCode /^\s*\n\(\(\s\{8,}[^ ]\|\t\t\+[^\t]\).*\n\)\+/
  69. syn match mkdIndentCode /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ contained
  70. syn match mkdListItem "^\s*[-*+]\s\+"
  71. syn match mkdListItem "^\s*\d\+\.\s\+"
  72. syn region mkdNonListItemBlock start="\n\(\_^\_$\|\s\{4,}[^ ]\|\t+[^\t]\)\@!" end="^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@=" contains=@mkdNonListItem,@Spell
  73. syn match mkdRule /^\s*\*\s\{0,1}\*\s\{0,1}\*$/
  74. syn match mkdRule /^\s*-\s\{0,1}-\s\{0,1}-$/
  75. syn match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_$/
  76. syn match mkdRule /^\s*-\{3,}$/
  77. syn match mkdRule /^\s*\*\{3,5}$/
  78. "HTML headings
  79. syn region htmlH1 start="^\s*#" end="\($\|#\+\)" contains=@Spell
  80. syn region htmlH2 start="^\s*##" end="\($\|#\+\)" contains=@Spell
  81. syn region htmlH3 start="^\s*###" end="\($\|#\+\)" contains=@Spell
  82. syn region htmlH4 start="^\s*####" end="\($\|#\+\)" contains=@Spell
  83. syn region htmlH5 start="^\s*#####" end="\($\|#\+\)" contains=@Spell
  84. syn region htmlH6 start="^\s*######" end="\($\|#\+\)" contains=@Spell
  85. syn match htmlH1 /^.\+\n=\+$/ contains=@Spell
  86. syn match htmlH2 /^.\+\n-\+$/ contains=@Spell
  87. if get(g:, 'vim_markdown_math', 0)
  88. syn region mkdMath matchgroup=mkdDelimiter start="\\\@<!\$" end="\$"
  89. syn region mkdMath matchgroup=mkdDelimiter start="\\\@<!\$\$" end="\$\$"
  90. endif
  91. " YAML frontmatter
  92. if get(g:, 'vim_markdown_frontmatter', 0)
  93. syn include @yamlTop syntax/yaml.vim
  94. syn region Comment matchgroup=mkdDelimiter start="\%^---$" end="^---$" contains=@yamlTop
  95. endif
  96. syn cluster mkdNonListItem contains=htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdInlineURL,mkdLink,mkdLinkDef,mkdLineBreak,mkdBlockquote,mkdCode,mkdIndentCode,mkdListItem,mkdRule,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,mkdMath
  97. "highlighting for Markdown groups
  98. HtmlHiLink mkdString String
  99. HtmlHiLink mkdCode String
  100. HtmlHiLink mkdIndentCode String
  101. HtmlHiLink mkdFootnote Comment
  102. HtmlHiLink mkdBlockquote Comment
  103. HtmlHiLink mkdLineContinue Comment
  104. HtmlHiLink mkdListItem Identifier
  105. HtmlHiLink mkdRule Identifier
  106. HtmlHiLink mkdLineBreak Todo
  107. HtmlHiLink mkdFootnotes htmlLink
  108. HtmlHiLink mkdLink htmlLink
  109. HtmlHiLink mkdURL htmlString
  110. HtmlHiLink mkdInlineURL htmlLink
  111. HtmlHiLink mkdID Identifier
  112. HtmlHiLink mkdLinkDef mkdID
  113. HtmlHiLink mkdLinkDefTarget mkdURL
  114. HtmlHiLink mkdLinkTitle htmlString
  115. HtmlHiLink mkdMath Statement
  116. HtmlHiLink mkdDelimiter Delimiter
  117. let b:current_syntax = "mkd"
  118. delcommand HtmlHiLink
  119. " vim: ts=8