| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | " Vim syntax file | 
					
						
							| 
									
										
										
										
											2005-06-29 22:40:58 +00:00
										 |  |  |  | " Language:         reStructuredText documentation format | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  | " Maintainer:       Nikolai Weibull <now@bitwi.se> | 
					
						
							| 
									
										
										
										
											2010-02-11 14:19:15 +01:00
										 |  |  |  | " Latest Revision:  2010-01-23 | 
					
						
							| 
									
										
										
										
											2005-06-29 22:40:58 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | if exists("b:current_syntax") | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  |   finish | 
					
						
							|  |  |  |  | endif | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-29 22:40:58 +00:00
										 |  |  |  | let s:cpo_save = &cpo | 
					
						
							|  |  |  |  | set cpo&vim | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | syn case ignore | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  |  | syn match   rstSections "^\%(\([=`:.'"~^_*+#-]\)\1\+\n\)\=.\+\n\([=`:.'"~^_*+#-]\)\2\+$" | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  |  | syn match   rstTransition  /^[=`:.'"~^_*+#-]\{4,}\s*$/ | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  | syn cluster rstCruft                contains=rstEmphasis,rstStrongEmphasis, | 
					
						
							|  |  |  |  |       \ rstInterpretedText,rstInlineLiteral,rstSubstitutionReference, | 
					
						
							|  |  |  |  |       \ rstInlineInternalTargets,rstFootnoteReference,rstHyperlinkReference | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  | syn region  rstLiteralBlock         matchgroup=rstDelimiter | 
					
						
							|  |  |  |  |       \ start='::\_s*\n\ze\z(\s\+\)' skip='^$' end='^\z1\@!' | 
					
						
							|  |  |  |  |       \ contains=@NoSpell | 
					
						
							| 
									
										
										
										
											2005-06-29 22:40:58 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  | syn region  rstQuotedLiteralBlock   matchgroup=rstDelimiter | 
					
						
							|  |  |  |  |       \ start="::\_s*\n\ze\z([!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]\)" | 
					
						
							|  |  |  |  |       \ end='^\z1\@!' contains=@NoSpell | 
					
						
							| 
									
										
										
										
											2005-06-29 22:40:58 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  | syn region  rstDoctestBlock         oneline display matchgroup=rstDelimiter | 
					
						
							|  |  |  |  |       \ start='^>>>\s' end='^$' | 
					
						
							| 
									
										
										
										
											2005-06-29 22:40:58 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  | syn region  rstTable                transparent start='^\n\s*+[-=+]\+' end='^$' | 
					
						
							|  |  |  |  |       \ contains=rstTableLines,@rstCruft | 
					
						
							|  |  |  |  | syn match   rstTableLines           contained display '|\|+\%(=\+\|-\+\)\=' | 
					
						
							| 
									
										
										
										
											2005-06-29 22:40:58 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  | syn region  rstSimpleTable          transparent | 
					
						
							|  |  |  |  |       \ start='^\n\%(\s*\)\@>\%(\%(=\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(=\+\)\@>\%(\s*\)\@>\)\+\)\@>$' | 
					
						
							|  |  |  |  |       \ end='^$' | 
					
						
							|  |  |  |  |       \ contains=rstSimpleTableLines,@rstCruft | 
					
						
							|  |  |  |  | syn match   rstSimpleTableLines     contained display | 
					
						
							|  |  |  |  |       \ '^\%(\s*\)\@>\%(\%(=\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(=\+\)\@>\%(\s*\)\@>\)\+\)\@>$' | 
					
						
							|  |  |  |  | syn match   rstSimpleTableLines     contained display | 
					
						
							|  |  |  |  |       \ '^\%(\s*\)\@>\%(\%(-\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(-\+\)\@>\%(\s*\)\@>\)\+\)\@>$' | 
					
						
							| 
									
										
										
										
											2005-06-29 22:40:58 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  | syn cluster rstDirectives           contains=rstFootnote,rstCitation, | 
					
						
							|  |  |  |  |       \ rstHyperlinkTarget,rstExDirective | 
					
						
							| 
									
										
										
										
											2005-06-29 22:40:58 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-05-10 19:06:20 +00:00
										 |  |  |  | syn match   rstExplicitMarkup       '^\.\.\_s' | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  |       \ nextgroup=@rstDirectives,rstComment,rstSubstitutionDefinition | 
					
						
							| 
									
										
										
										
											2005-06-29 22:40:58 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  | let s:ReferenceName = '[[:alnum:]]\+\%([_.-][[:alnum:]]\+\)*' | 
					
						
							| 
									
										
										
										
											2005-06-29 22:40:58 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  | syn keyword     rstTodo             contained FIXME TODO XXX NOTE | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  | execute 'syn region rstComment contained' . | 
					
						
							|  |  |  |  |       \ ' start=/.*/' | 
					
						
							|  |  |  |  |       \ ' end=/^\s\@!/ contains=rstTodo' | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | execute 'syn region rstFootnote contained matchgroup=rstDirective' . | 
					
						
							|  |  |  |  |       \ ' start=+\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]\_s+' . | 
					
						
							|  |  |  |  |       \ ' skip=+^$+' . | 
					
						
							|  |  |  |  |       \ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell' | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | execute 'syn region rstCitation contained matchgroup=rstDirective' . | 
					
						
							|  |  |  |  |       \ ' start=+\[' . s:ReferenceName . '\]\_s+' . | 
					
						
							|  |  |  |  |       \ ' skip=+^$+' . | 
					
						
							|  |  |  |  |       \ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell' | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | syn region rstHyperlinkTarget contained matchgroup=rstDirective | 
					
						
							|  |  |  |  |       \ start='_\%(_\|[^:\\]*\%(\\.[^:\\]*\)*\):\_s' skip=+^$+ end=+^\s\@!+ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | syn region rstHyperlinkTarget contained matchgroup=rstDirective | 
					
						
							|  |  |  |  |       \ start='_`[^`\\]*\%(\\.[^`\\]*\)*`:\_s' skip=+^$+ end=+^\s\@!+ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | syn region rstHyperlinkTarget matchgroup=rstDirective | 
					
						
							|  |  |  |  |       \ start=+^__\_s+ skip=+^$+ end=+^\s\@!+ | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | execute 'syn region rstExDirective contained matchgroup=rstDirective' . | 
					
						
							|  |  |  |  |       \ ' start=+' . s:ReferenceName . '::\_s+' . | 
					
						
							|  |  |  |  |       \ ' skip=+^$+' . | 
					
						
							|  |  |  |  |       \ ' end=+^\s\@!+ contains=@rstCruft' | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | execute 'syn match rstSubstitutionDefinition contained' . | 
					
						
							|  |  |  |  |       \ ' /|' . s:ReferenceName . '|\_s\+/ nextgroup=@rstDirectives' | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | function! s:DefineOneInlineMarkup(name, start, middle, end, char_left, char_right) | 
					
						
							|  |  |  |  |   execute 'syn region rst' . a:name . | 
					
						
							|  |  |  |  |         \ ' start=+' . a:char_left . '\zs' . a:start . | 
					
						
							| 
									
										
										
										
											2007-05-10 19:06:20 +00:00
										 |  |  |  |         \ '\ze[^[:space:]' . a:char_right . a:start[strlen(a:start) - 1] . ']+' . | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  |         \ a:middle . | 
					
						
							|  |  |  |  |         \ ' end=+\S' . a:end . '\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+' | 
					
						
							|  |  |  |  | endfunction | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | function! s:DefineInlineMarkup(name, start, middle, end) | 
					
						
							|  |  |  |  |   let middle = a:middle != "" ? | 
					
						
							|  |  |  |  |         \ (' skip=+\\\\\|\\' . a:middle . '+') : | 
					
						
							|  |  |  |  |         \ "" | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, "'", "'") | 
					
						
							|  |  |  |  |   call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '"', '"')  | 
					
						
							|  |  |  |  |   call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '(', ')')  | 
					
						
							|  |  |  |  |   call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '\[', '\]')  | 
					
						
							|  |  |  |  |   call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '{', '}')  | 
					
						
							|  |  |  |  |   call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '<', '>')  | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '\%(^\|\s\|[/:]\)', '') | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   execute 'syn match rst' . a:name . | 
					
						
							|  |  |  |  |         \ ' +\%(^\|\s\|[''"([{</:]\)\zs' . a:start . | 
					
						
							|  |  |  |  |         \ '[^[:space:]' . a:start[strlen(a:start) - 1] . ']' | 
					
						
							|  |  |  |  |         \ a:end . '\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+' | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |   execute 'hi def link rst' . a:name . 'Delimiter' . ' rst' . a:name | 
					
						
							|  |  |  |  | endfunction | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | call s:DefineInlineMarkup('Emphasis', '\*', '\*', '\*') | 
					
						
							|  |  |  |  | call s:DefineInlineMarkup('StrongEmphasis', '\*\*', '\*', '\*\*') | 
					
						
							|  |  |  |  | call s:DefineInlineMarkup('InterpretedTextOrHyperlinkReference', '`', '`', '`_\{0,2}') | 
					
						
							|  |  |  |  | call s:DefineInlineMarkup('InlineLiteral', '``', "", '``') | 
					
						
							|  |  |  |  | call s:DefineInlineMarkup('SubstitutionReference', '|', '|', '|_\{0,2}') | 
					
						
							|  |  |  |  | call s:DefineInlineMarkup('InlineInternalTargets', '_`', '`', '`') | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | " TODO: Can’t remember why these two can’t be defined like the ones above. | 
					
						
							|  |  |  |  | execute 'syn match rstFootnoteReference contains=@NoSpell' . | 
					
						
							|  |  |  |  |       \ ' +\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]_+' | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | execute 'syn match rstCitationReference contains=@NoSpell' . | 
					
						
							| 
									
										
										
										
											2007-05-10 19:06:20 +00:00
										 |  |  |  |       \ ' +\[' . s:ReferenceName . '\]_\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+' | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | execute 'syn match rstHyperlinkReference' . | 
					
						
							| 
									
										
										
										
											2007-05-10 19:06:20 +00:00
										 |  |  |  |       \ ' /\<' . s:ReferenceName . '__\=\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)/' | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | syn match   rstStandaloneHyperlink  contains=@NoSpell | 
					
						
							|  |  |  |  |       \ "\<\%(\%(\%(https\=\|file\|ftp\|gopher\)://\|\%(mailto\|news\):\)[^[:space:]'\"<>]\+\|www[[:alnum:]_-]*\.[[:alnum:]_-]\+\.[^[:space:]'\"<>]\+\)[[:alnum:]/]" | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | " TODO: Use better syncing.  I don’t know the specifics of syncing well enough, | 
					
						
							|  |  |  |  | " though. | 
					
						
							| 
									
										
										
										
											2010-02-11 14:19:15 +01:00
										 |  |  |  | syn sync minlines=50 linebreaks=1 | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  | hi def link rstTodo                         Todo | 
					
						
							|  |  |  |  | hi def link rstComment                      Comment | 
					
						
							| 
									
										
										
										
											2010-01-06 20:54:52 +01:00
										 |  |  |  | hi def link rstSections                     Type | 
					
						
							|  |  |  |  | hi def link rstTransition                   Type | 
					
						
							| 
									
										
										
										
											2006-04-10 14:55:34 +00:00
										 |  |  |  | hi def link rstLiteralBlock                 String | 
					
						
							|  |  |  |  | hi def link rstQuotedLiteralBlock           String | 
					
						
							|  |  |  |  | hi def link rstDoctestBlock                 PreProc | 
					
						
							|  |  |  |  | hi def link rstTableLines                   rstDelimiter | 
					
						
							|  |  |  |  | hi def link rstSimpleTableLines             rstTableLines | 
					
						
							|  |  |  |  | hi def link rstExplicitMarkup               rstDirective | 
					
						
							|  |  |  |  | hi def link rstDirective                    Keyword | 
					
						
							|  |  |  |  | hi def link rstFootnote                     String | 
					
						
							|  |  |  |  | hi def link rstCitation                     String | 
					
						
							|  |  |  |  | hi def link rstHyperlinkTarget              String | 
					
						
							|  |  |  |  | hi def link rstExDirective                  String | 
					
						
							|  |  |  |  | hi def link rstSubstitutionDefinition       rstDirective | 
					
						
							|  |  |  |  | hi def link rstDelimiter                    Delimiter | 
					
						
							|  |  |  |  | " TODO: I dunno... | 
					
						
							|  |  |  |  | hi def      rstEmphasis                     term=italic cterm=italic gui=italic | 
					
						
							|  |  |  |  | hi def link rstStrongEmphasis               Special | 
					
						
							|  |  |  |  | "term=bold cterm=bold gui=bold | 
					
						
							|  |  |  |  | hi def link rstInterpretedTextOrHyperlinkReference  Identifier | 
					
						
							|  |  |  |  | hi def link rstInlineLiteral                String | 
					
						
							|  |  |  |  | hi def link rstSubstitutionReference        PreProc | 
					
						
							|  |  |  |  | hi def link rstInlineInternalTargets        Identifier | 
					
						
							|  |  |  |  | hi def link rstFootnoteReference            Identifier | 
					
						
							|  |  |  |  | hi def link rstCitationReference            Identifier | 
					
						
							|  |  |  |  | hi def link rstHyperLinkReference           Identifier | 
					
						
							|  |  |  |  | hi def link rstStandaloneHyperlink          Identifier | 
					
						
							| 
									
										
										
										
											2004-06-13 20:20:40 +00:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | let b:current_syntax = "rst" | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-06-29 22:40:58 +00:00
										 |  |  |  | let &cpo = s:cpo_save | 
					
						
							|  |  |  |  | unlet s:cpo_save |