From 4be0ec4a0f3fa1b25fb723266d62fef0f7e6b277 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Wed, 24 Feb 2010 21:09:34 -0500 Subject: [PATCH] Initial commit --- ftdetect/markdown.vim | 4 ++ ftplugin/markdown.vim | 18 ++++++++ syntax/markdown.vim | 102 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 ftdetect/markdown.vim create mode 100644 ftplugin/markdown.vim create mode 100644 syntax/markdown.vim diff --git a/ftdetect/markdown.vim b/ftdetect/markdown.vim new file mode 100644 index 0000000..1f64ba9 --- /dev/null +++ b/ftdetect/markdown.vim @@ -0,0 +1,4 @@ +augroup markdown + autocmd! + autocmd BufNewFile,BufRead *.markdown,*.mkdn,*.mdown,*.md set ft=markdown +augroup END diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim new file mode 100644 index 0000000..28cac11 --- /dev/null +++ b/ftplugin/markdown.vim @@ -0,0 +1,18 @@ +" Vim filetype plugin +" Language: Markdown +" Maintainer: Tim Pope + +if exists("b:did_ftplugin") + finish +endif + +runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim +unlet! b:did_ftplugin + +setlocal comments=fb:*,fb:-,fb:+,n:> commentstring=>\ %s +setlocal formatoptions+=tcqln +setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^[-*+]\\s\\+ + +let b:undo_ftplugin .= "|setl cms< com< fo<" + +" vim:set sw=2: diff --git a/syntax/markdown.vim b/syntax/markdown.vim new file mode 100644 index 0000000..95f96f2 --- /dev/null +++ b/syntax/markdown.vim @@ -0,0 +1,102 @@ +" Vim syntax file +" Language: Markdown +" Maintainer: Tim Pope +" Filenames: *.markdown + +if exists("b:current_syntax") + finish +endif + +runtime! syntax/html.vim +unlet! b:current_syntax +syn include @markdownYamlTop syntax/yaml.vim + +syn sync minlines=10 +syn case ignore + +syn match markdownValid '[<>]\S\@!' +syn match markdownValid '&\%(#\=\w*;\)\@!' + +syn match markdownLineStart "^[<@]\@!" nextgroup=@markdownBlock + +syn cluster markdownBlock contains=markdownH1,markdownH2,markdownH3,markdownH4,markdownH5,markdownH6,markdownBlockquote,markdownListMarker,markdownOrderedListMarker,markdownCodeBlock,markdownRule +syn cluster markdownInline contains=markdownLinkText,markdownItalic,markdownBold,markdownCode,markdownEscape,@htmlTop + +syn match markdownH1 ".\+\n=\+$" contained contains=@markdownInline,markdownHeadingRule +syn match markdownH2 ".\+\n-\+$" contained contains=@markdownInline,markdownHeadingRule + +syn match markdownHeadingRule "^[=-]\+$" contained + +syn region markdownH1 matchgroup=markdownHeadingDelimiter start="##\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained +syn region markdownH2 matchgroup=markdownHeadingDelimiter start="###\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained +syn region markdownH3 matchgroup=markdownHeadingDelimiter start="####\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained +syn region markdownH4 matchgroup=markdownHeadingDelimiter start="#####\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained +syn region markdownH5 matchgroup=markdownHeadingDelimiter start="######\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained +syn region markdownH6 matchgroup=markdownHeadingDelimiter start="#######\@!" end="#*\s*$" keepend oneline contains=@markdownInline contained + +syn match markdownBlockquote ">\s" contained nextgroup=@markdownBlock + +syn region markdownCodeBlock start=" \|\t" end="$" contained + +" TODO: real nesting +syn match markdownListMarker " \{0,4\}[-*+]\%(\s\+\S\)\@=" contained +syn match markdownOrderedListMarker " \{0,4}\<\d\+\.\%(\s*\S\)\@=" contained + +syn match markdownRule "\* *\* *\*[ *]*$" contained +syn match markdownRule "- *- *-[ -]*$" contained + +syn region markdownYamlHead start="\%^---$" end="^---\s*$" keepend contains=@markdownYamlTop + +syn region markdownIdDeclaration matchgroup=markdownLinkDelimiter start="^\s\{0,2\}!\=\[" end="\]:" oneline keepend nextgroup=markdownUrl skipwhite +syn match markdownUrl "\S\+" nextgroup=markdownUrlTitle skipwhite contained +syn region markdownUrl matchgroup=markdownUrlDelimiter start="<" end=">" oneline keepend nextgroup=markdownUrlTitle skipwhite contained +syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+"+ end=+"+ keepend contained +syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+'+ end=+'+ keepend contained +syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+(+ end=+)+ keepend contained + +syn region markdownLinkText matchgroup=markdownLinkTextDelimiter start="!\=\[\%(\_[^]]*]\%((\| \=\[\)\)\@=" end="\]\%((\| \=\[\)\@=" keepend nextgroup=markdownLink,markdownId skipwhite contains=@markdownInline,markdownLineStart +syn region markdownLink matchgroup=markdownLinkDelimiter start="(" end=")" contains=markdownUrl keepend contained +syn region markdownId matchgroup=markdownIdDelimiter start="\[" end="\]" keepend contained +syn region markdownAutomaticLink matchgroup=markdownUrlDelimiter start="<\%(\w\+:\|\S\+@\)\@=" end=">" keepend oneline + +syn region markdownItalic start="\S\@<=\*\|\*\S\@=" end="\S\@<=\*\|\*\S\@=" +syn region markdownItalic start="\S\@<=_\|_\S\@=" end="\S\@<=_\|_\S\@=" +syn region markdownBold start="\S\@<=\*\*\|\*\*\S\@=" end="\S\@<=\*\*\|\*\*\S\@=" +syn region markdownBold start="\S\@<=__\|__\S\@=" end="\S\@<=__\|__\S\@=" +syn region markdownCode matchgroup=markdownCodeDelimiter start="`" end="`" +syn region markdownCode matchgroup=markdownCodeDelimiter start="`` \=" end=" \=``" + +syn match markdownEscape "\\[][\\`*_{}()#+.!-]" + +hi def link markdownH1 htmlH1 +hi def link markdownH2 htmlH2 +hi def link markdownH3 htmlH3 +hi def link markdownH4 htmlH4 +hi def link markdownH5 htmlH5 +hi def link markdownH6 htmlH6 +hi def link markdownHeadingRule markdownRule +hi def link markdownHeadingDelimiter Delimiter +hi def link markdownOrderedListMarker markdownListMarker +hi def link markdownListMarker htmlTagName +hi def link markdownBlockquote Comment +hi def link markdownRule PreProc + +hi def link markdownLinkText htmlLink +hi def link markdownIdDeclaration Typedef +hi def link markdownId Type +hi def link markdownAutomaticLink markdownUrl +hi def link markdownUrl Float +hi def link markdownUrlTitle String +hi def link markdownIdDelimiter markdownLinkDelimiter +hi def link markdownUrlDelimiter htmlTag +hi def link markdownUrlTitleDelimiter Delimiter + +hi def link markdownItalic htmlItalic +hi def link markdownBold htmlBold +hi def link markdownCodeDelimiter Delimiter + +hi def link markdownEscape Special + +let b:current_syntax = "markdown" + +" vim:set sw=2: