├── README.md └── syntax └── ghmarkdown.vim /README.md: -------------------------------------------------------------------------------- 1 | Vim-Flavored-Markdown 2 | ===================== 3 | 4 | Add-on to Tim Pope's [`markdown.vim`][mdsyntax] to highlight using Github 5 | Flavored Markdown. 6 | 7 | a syntax plugin that extends the Tim Pope's markdown syntax file to recognize 8 | github code blocks like: 9 | 10 | ```yourLanguage 11 | Some code 12 | ``` 13 | 14 | It also colors `markdownCode` blocks and in-lines as String, so they are more 15 | easily differentiable in your code. 16 | 17 | Finally, it no longer highlights multiple underscores, i.e.: 18 | 19 | ``` 20 | _this_gets_highlighted_ 21 | but_this_does_not 22 | ``` 23 | 24 | Install 25 | ------- 26 | 27 | ### Best way - use Pathogen 28 | 29 | If you use Pathogen, you can just clone this into your bundles 30 | 31 | ```bash 32 | cd ~/.vim/bundle 33 | git clone git://github.com/jtratner/vim-flavored-markdown.git 34 | ``` 35 | 36 | ### Otherwise, copy the file to your syntax folder 37 | 38 | ```bash 39 | curl https://raw.githubusercontent.com/jtratner/vim-flavored-markdown/master/syntax/ghmarkdown.vim -o ~/.vim/syntax/ghmarkdown.vim 40 | ``` 41 | 42 | ### Use flavored-markdown by default 43 | 44 | Add the following `autocmd` to your `.vimrc`: 45 | 46 | ```viml 47 | augroup markdown 48 | au! 49 | au BufNewFile,BufRead *.md,*.markdown setlocal filetype=ghmarkdown 50 | augroup END 51 | ``` 52 | 53 | See it in action 54 | ---------------- 55 | 56 | After installing, open up this readme, and you'll see fenced awesomeness. 57 | 58 | License 59 | ------- 60 | 61 | MIT 62 | 63 | Contributors to Vim-Flavored-Markdown 64 | ------------------------------------- 65 | 66 | Vim-Flavored-Markdown author: Jeff Tratner ([jtratner][jtr]) 67 | 68 | [markdown.vim][mdsyntax] author: Tim Pope ([tpope][tpope]) 69 | 70 | Along with all of the various [contributors to markdown.vim][contrib] 71 | 72 | [tpope]: https://github.com/tpope 73 | [jtr]: https://github.com/jtratner 74 | [mdsyntax]: https://github.com/tpope/vim-markdown 75 | [contrib]: https://github.com/tpope/vim-markdown/contributors 76 | 77 | Thanks to @dankosaur, @knewter, and @Niggler for contributing. 78 | 79 | 80 | 83 | -------------------------------------------------------------------------------- /syntax/ghmarkdown.vim: -------------------------------------------------------------------------------- 1 | " Vim syntax file 2 | " Language: Github Flavored Markdown 3 | " Markdown.vim Maintainer: Tim Pope 4 | " GFM Maintainer: Jeff Tratner 5 | " Filenames: *.ghmarkdown 6 | " Last Change: 2013 June 8 7 | " (nearly the same as tpope's markdown.vim, with a few 8 | " add-ons for Github Flavored Markdown) 9 | 10 | if exists("b:current_syntax") 11 | finish 12 | endif 13 | 14 | if !exists('main_syntax') 15 | let main_syntax = 'ghmarkdown' 16 | endif 17 | 18 | runtime! syntax/html.vim 19 | unlet! b:current_syntax 20 | 21 | syn sync minlines=10 22 | syn case ignore 23 | 24 | syn match markdownValid '[<>]\c[a-z/$!]\@!' 25 | syn match markdownValid '&\%(#\=\w*;\)\@!' 26 | 27 | syn match markdownLineStart "^[<@]\@!" nextgroup=@markdownBlock,htmlSpecialChar 28 | 29 | syn cluster markdownBlock contains=markdownH1,markdownH2,markdownH3,markdownH4,markdownH5,markdownH6,markdownBlockquote,markdownListMarker,markdownOrderedListMarker,markdownCodeBlock,markdownRule,markdownGHCodeBlock 30 | syn cluster markdownInline contains=markdownLineBreak,markdownLinkText,markdownItalic,markdownBold,markdownCode,markdownEscape,@htmlTop,markdownError 31 | 32 | syn match markdownH1 "^.\+\n=\+$" contained contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink 33 | syn match markdownH2 "^.\+\n-\+$" contained contains=@markdownInline,markdownHeadingRule,markdownAutomaticLink 34 | 35 | syn match markdownHeadingRule "^[=-]\+$" contained 36 | 37 | syn region markdownH1 matchgroup=markdownHeadingDelimiter start="##\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained 38 | syn region markdownH2 matchgroup=markdownHeadingDelimiter start="###\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained 39 | syn region markdownH3 matchgroup=markdownHeadingDelimiter start="####\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained 40 | syn region markdownH4 matchgroup=markdownHeadingDelimiter start="#####\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained 41 | syn region markdownH5 matchgroup=markdownHeadingDelimiter start="######\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained 42 | syn region markdownH6 matchgroup=markdownHeadingDelimiter start="#######\@!" end="#*\s*$" keepend oneline contains=@markdownInline,markdownAutomaticLink contained 43 | 44 | syn match markdownBlockquote ">\%(\s\|$\)" contained nextgroup=@markdownBlock 45 | 46 | syn region markdownCodeBlock start=" \|\t" end="$" contained 47 | 48 | " TODO: real nesting 49 | syn match markdownListMarker "\%(\t\| \{0,4\}\)[-*+]\%(\s\+\S\)\@=" contained 50 | syn match markdownOrderedListMarker "\%(\t\| \{0,4}\)\<\d\+\.\%(\s\+\S\)\@=" contained 51 | 52 | syn match markdownRule "\* *\* *\*[ *]*$" contained 53 | syn match markdownRule "- *- *-[ -]*$" contained 54 | 55 | syn match markdownLineBreak " \{2,\}$" 56 | 57 | syn region markdownIdDeclaration matchgroup=markdownLinkDelimiter start="^ \{0,3\}!\=\[" end="\]:" oneline keepend nextgroup=markdownUrl skipwhite 58 | syn match markdownUrl "\S\+" nextgroup=markdownUrlTitle skipwhite contained 59 | syn region markdownUrl matchgroup=markdownUrlDelimiter start="<" end=">" oneline keepend nextgroup=markdownUrlTitle skipwhite contained 60 | syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+"+ end=+"+ keepend contained 61 | syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+'+ end=+'+ keepend contained 62 | syn region markdownUrlTitle matchgroup=markdownUrlTitleDelimiter start=+(+ end=+)+ keepend contained 63 | 64 | syn region markdownLinkText matchgroup=markdownLinkTextDelimiter start="!\=\[\%(\_[^]]*]\%( \=[[(]\)\)\@=" end="\]\%( \=[[(]\)\@=" keepend nextgroup=markdownLink,markdownId skipwhite contains=@markdownInline,markdownLineStart 65 | syn region markdownLink matchgroup=markdownLinkDelimiter start="(" end=")" contains=markdownUrl keepend contained 66 | syn region markdownId matchgroup=markdownIdDelimiter start="\[" end="\]" keepend contained 67 | syn region markdownAutomaticLink matchgroup=markdownUrlDelimiter start="<\%(\w\+:\|[[:alnum:]_+-]\+@\)\@=" end=">" keepend oneline 68 | 69 | syn region markdownItalic start="\<\*\|\*\>" end="\<\*\|\*\>" keepend contains=markdownLineStart 70 | syn region markdownItalic start="\<_\|_\>" end="\<_\|_\>" keepend contains=markdownLineStart 71 | syn region markdownBold start="\<\*\*\|\*\*\>" end="\<\*\*\|\*\*\>" keepend contains=markdownLineStart,markdownItalic 72 | syn region markdownBold start="\<__\|__\>" end="\<__\|__\>" keepend contains=markdownLineStart,markdownItalic 73 | syn region markdownBoldItalic start="\<\*\*\*\|\*\*\*\>" end="\<\*\*\*\|\*\*\*\>" keepend contains=markdownLineStart 74 | syn region markdownBoldItalic start="\<___\|___\>" end="\<___\|___\>" keepend contains=markdownLineStart 75 | syn region markdownCode matchgroup=markdownCodeDelimiter start="`" end="`" keepend contains=markdownLineStart 76 | syn region markdownCode matchgroup=markdownCodeDelimiter start="``` \=" end=" \=```" keepend contains=markdownLineStart 77 | syn region markdownGHCodeBlock matchgroup=markdownCodeDelimiter start="^\s*$\n\s*```\s\?\S*\s*$" end="\s*```$\n\s*\n" contained keepend 78 | 79 | syn match markdownEscape "\\[][\\`*_{}()#+.!-]" 80 | 81 | " Copying rst's method of using literal strings 82 | hi def link markdownGHCodeBlock String 83 | hi def link markdownCodeBlock String 84 | hi def link markdownCode String 85 | hi def link markdownH1 htmlH1 86 | hi def link markdownH2 htmlH2 87 | hi def link markdownH3 htmlH3 88 | hi def link markdownH4 htmlH4 89 | hi def link markdownH5 htmlH5 90 | hi def link markdownH6 htmlH6 91 | hi def link markdownHeadingRule markdownRule 92 | hi def link markdownHeadingDelimiter Delimiter 93 | hi def link markdownOrderedListMarker markdownListMarker 94 | hi def link markdownListMarker htmlTagName 95 | hi def link markdownBlockquote Comment 96 | hi def link markdownRule PreProc 97 | 98 | hi def link markdownLinkText htmlLink 99 | hi def link markdownIdDeclaration Typedef 100 | hi def link markdownId Type 101 | hi def link markdownAutomaticLink markdownUrl 102 | hi def link markdownUrl Float 103 | hi def link markdownUrlTitle String 104 | hi def link markdownIdDelimiter markdownLinkDelimiter 105 | hi def link markdownUrlDelimiter htmlTag 106 | hi def link markdownUrlTitleDelimiter Delimiter 107 | 108 | hi def link markdownItalic htmlItalic 109 | hi def link markdownBold htmlBold 110 | hi def link markdownBoldItalic htmlBoldItalic 111 | hi def link markdownCodeDelimiter Delimiter 112 | 113 | hi def link markdownEscape Special 114 | 115 | let b:current_syntax = "ghmarkdown" 116 | 117 | if main_syntax ==# 'ghmarkdown' 118 | unlet main_syntax 119 | endif 120 | " vim:set sw=2: 121 | --------------------------------------------------------------------------------