1" Vim syntax file 2" Language: reStructuredText documentation format 3" Maintainer: Nikolai Weibull <[email protected]> 4" Latest Revision: 2006-04-09 5 6if exists("b:current_syntax") 7 finish 8endif 9 10let s:cpo_save = &cpo 11set cpo&vim 12 13syn case ignore 14 15" FIXME: The problem with these two is that Vim doesn’t seem to like 16" matching across line boundaries. 17" 18" syn match rstSections /^.*\n[=`:.'"~^_*+#-]\+$/ 19 20" syn match rstTransition /^\s*[=`:.'"~^_*+#-]\{4,}\s*$/ 21 22syn cluster rstCruft contains=rstEmphasis,rstStrongEmphasis, 23 \ rstInterpretedText,rstInlineLiteral,rstSubstitutionReference, 24 \ rstInlineInternalTargets,rstFootnoteReference,rstHyperlinkReference 25 26syn region rstLiteralBlock matchgroup=rstDelimiter 27 \ start='::\_s*\n\ze\z(\s\+\)' skip='^$' end='^\z1\@!' 28 \ contains=@NoSpell 29 30syn region rstQuotedLiteralBlock matchgroup=rstDelimiter 31 \ start="::\_s*\n\ze\z([!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]\)" 32 \ end='^\z1\@!' contains=@NoSpell 33 34syn region rstDoctestBlock oneline display matchgroup=rstDelimiter 35 \ start='^>>>\s' end='^$' 36 37syn region rstTable transparent start='^\n\s*+[-=+]\+' end='^$' 38 \ contains=rstTableLines,@rstCruft 39syn match rstTableLines contained display '|\|+\%(=\+\|-\+\)\=' 40 41syn region rstSimpleTable transparent 42 \ start='^\n\%(\s*\)\@>\%(\%(=\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(=\+\)\@>\%(\s*\)\@>\)\+\)\@>$' 43 \ end='^$' 44 \ contains=rstSimpleTableLines,@rstCruft 45syn match rstSimpleTableLines contained display 46 \ '^\%(\s*\)\@>\%(\%(=\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(=\+\)\@>\%(\s*\)\@>\)\+\)\@>$' 47syn match rstSimpleTableLines contained display 48 \ '^\%(\s*\)\@>\%(\%(-\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(-\+\)\@>\%(\s*\)\@>\)\+\)\@>$' 49 50syn cluster rstDirectives contains=rstFootnote,rstCitation, 51 \ rstHyperlinkTarget,rstExDirective 52 53syn match rstExplicitMarkup '^\.\.\s' 54 \ nextgroup=@rstDirectives,rstComment,rstSubstitutionDefinition 55 56let s:ReferenceName = '[[:alnum:]]\+\%([_.-][[:alnum:]]\+\)*' 57 58syn keyword rstTodo contained FIXME TODO XXX NOTE 59 60execute 'syn region rstComment contained' . 61 \ ' start=/.*/' 62 \ ' end=/^\s\@!/ contains=rstTodo' 63 64execute 'syn region rstFootnote contained matchgroup=rstDirective' . 65 \ ' start=+\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]\_s+' . 66 \ ' skip=+^$+' . 67 \ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell' 68 69execute 'syn region rstCitation contained matchgroup=rstDirective' . 70 \ ' start=+\[' . s:ReferenceName . '\]\_s+' . 71 \ ' skip=+^$+' . 72 \ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell' 73 74syn region rstHyperlinkTarget contained matchgroup=rstDirective 75 \ start='_\%(_\|[^:\\]*\%(\\.[^:\\]*\)*\):\_s' skip=+^$+ end=+^\s\@!+ 76 77syn region rstHyperlinkTarget contained matchgroup=rstDirective 78 \ start='_`[^`\\]*\%(\\.[^`\\]*\)*`:\_s' skip=+^$+ end=+^\s\@!+ 79 80syn region rstHyperlinkTarget matchgroup=rstDirective 81 \ start=+^__\_s+ skip=+^$+ end=+^\s\@!+ 82 83execute 'syn region rstExDirective contained matchgroup=rstDirective' . 84 \ ' start=+' . s:ReferenceName . '::\_s+' . 85 \ ' skip=+^$+' . 86 \ ' end=+^\s\@!+ contains=@rstCruft' 87 88execute 'syn match rstSubstitutionDefinition contained' . 89 \ ' /|' . s:ReferenceName . '|\_s\+/ nextgroup=@rstDirectives' 90 91function! s:DefineOneInlineMarkup(name, start, middle, end, char_left, char_right) 92 execute 'syn region rst' . a:name . 93 \ ' start=+' . a:char_left . '\zs' . a:start . 94 \ '[^[:space:]' . a:char_right . a:start[strlen(a:start) - 1] . ']+' . 95 \ a:middle . 96 \ ' end=+\S' . a:end . '\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+' 97endfunction 98 99function! s:DefineInlineMarkup(name, start, middle, end) 100 let middle = a:middle != "" ? 101 \ (' skip=+\\\\\|\\' . a:middle . '+') : 102 \ "" 103 104 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, "'", "'") 105 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '"', '"') 106 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '(', ')') 107 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '\[', '\]') 108 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '{', '}') 109 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '<', '>') 110 111 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '\%(^\|\s\|[/:]\)', '') 112 113 execute 'syn match rst' . a:name . 114 \ ' +\%(^\|\s\|[''"([{</:]\)\zs' . a:start . 115 \ '[^[:space:]' . a:start[strlen(a:start) - 1] . ']' 116 \ a:end . '\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+' 117 118 execute 'hi def link rst' . a:name . 'Delimiter' . ' rst' . a:name 119endfunction 120 121call s:DefineInlineMarkup('Emphasis', '\*', '\*', '\*') 122call s:DefineInlineMarkup('StrongEmphasis', '\*\*', '\*', '\*\*') 123call s:DefineInlineMarkup('InterpretedTextOrHyperlinkReference', '`', '`', '`_\{0,2}') 124call s:DefineInlineMarkup('InlineLiteral', '``', "", '``') 125call s:DefineInlineMarkup('SubstitutionReference', '|', '|', '|_\{0,2}') 126call s:DefineInlineMarkup('InlineInternalTargets', '_`', '`', '`') 127 128" TODO: Can’t remember why these two can’t be defined like the ones above. 129execute 'syn match rstFootnoteReference contains=@NoSpell' . 130 \ ' +\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]_+' 131 132execute 'syn match rstCitationReference contains=@NoSpell' . 133 \ ' +\[' . s:ReferenceName . '\]_+' 134 135execute 'syn match rstHyperlinkReference' . 136 \ ' /\<' . s:ReferenceName . '__\=/' 137 138syn match rstStandaloneHyperlink contains=@NoSpell 139 \ "\<\%(\%(\%(https\=\|file\|ftp\|gopher\)://\|\%(mailto\|news\):\)[^[:space:]'\"<>]\+\|www[[:alnum:]_-]*\.[[:alnum:]_-]\+\.[^[:space:]'\"<>]\+\)[[:alnum:]/]" 140 141" TODO: Use better syncing. I don’t know the specifics of syncing well enough, 142" though. 143syn sync minlines=50 144 145hi def link rstTodo Todo 146hi def link rstComment Comment 147"hi def link rstSections Type 148"hi def link rstTransition Type 149hi def link rstLiteralBlock String 150hi def link rstQuotedLiteralBlock String 151hi def link rstDoctestBlock PreProc 152hi def link rstTableLines rstDelimiter 153hi def link rstSimpleTableLines rstTableLines 154hi def link rstExplicitMarkup rstDirective 155hi def link rstDirective Keyword 156hi def link rstFootnote String 157hi def link rstCitation String 158hi def link rstHyperlinkTarget String 159hi def link rstExDirective String 160hi def link rstSubstitutionDefinition rstDirective 161hi def link rstDelimiter Delimiter 162" TODO: I dunno... 163hi def rstEmphasis term=italic cterm=italic gui=italic 164hi def link rstStrongEmphasis Special 165"term=bold cterm=bold gui=bold 166hi def link rstInterpretedTextOrHyperlinkReference Identifier 167hi def link rstInlineLiteral String 168hi def link rstSubstitutionReference PreProc 169hi def link rstInlineInternalTargets Identifier 170hi def link rstFootnoteReference Identifier 171hi def link rstCitationReference Identifier 172hi def link rstHyperLinkReference Identifier 173hi def link rstStandaloneHyperlink Identifier 174 175let b:current_syntax = "rst" 176 177let &cpo = s:cpo_save 178unlet s:cpo_save 179