blob: 6e24251ffec12f592a926f3785974a5f0fb2fa54 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim syntax file
Bram Moolenaar42eeac32005-06-29 22:40:58 +00002" Language: reStructuredText documentation format
Bram Moolenaar779b74b2006-04-10 14:55:34 +00003" Maintainer: Nikolai Weibull <now@bitwi.se>
4" Latest Revision: 2006-04-09
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
Bram Moolenaar42eeac32005-06-29 22:40:58 +00006if exists("b:current_syntax")
Bram Moolenaar071d4272004-06-13 20:20:40 +00007 finish
8endif
9
Bram Moolenaar42eeac32005-06-29 22:40:58 +000010let s:cpo_save = &cpo
11set cpo&vim
12
Bram Moolenaar071d4272004-06-13 20:20:40 +000013syn case ignore
14
Bram Moolenaar779b74b2006-04-10 14:55:34 +000015" 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[=`:.'"~^_*+#-]\+$/
Bram Moolenaar071d4272004-06-13 20:20:40 +000019
Bram Moolenaar779b74b2006-04-10 14:55:34 +000020" syn match rstTransition /^\s*[=`:.'"~^_*+#-]\{4,}\s*$/
Bram Moolenaar071d4272004-06-13 20:20:40 +000021
Bram Moolenaar779b74b2006-04-10 14:55:34 +000022syn cluster rstCruft contains=rstEmphasis,rstStrongEmphasis,
23 \ rstInterpretedText,rstInlineLiteral,rstSubstitutionReference,
24 \ rstInlineInternalTargets,rstFootnoteReference,rstHyperlinkReference
Bram Moolenaar071d4272004-06-13 20:20:40 +000025
Bram Moolenaar779b74b2006-04-10 14:55:34 +000026syn region rstLiteralBlock matchgroup=rstDelimiter
27 \ start='::\_s*\n\ze\z(\s\+\)' skip='^$' end='^\z1\@!'
28 \ contains=@NoSpell
Bram Moolenaar071d4272004-06-13 20:20:40 +000029
Bram Moolenaar779b74b2006-04-10 14:55:34 +000030syn region rstQuotedLiteralBlock matchgroup=rstDelimiter
31 \ start="::\_s*\n\ze\z([!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]\)"
32 \ end='^\z1\@!' contains=@NoSpell
Bram Moolenaar071d4272004-06-13 20:20:40 +000033
Bram Moolenaar779b74b2006-04-10 14:55:34 +000034syn region rstDoctestBlock oneline display matchgroup=rstDelimiter
35 \ start='^>>>\s' end='^$'
Bram Moolenaar071d4272004-06-13 20:20:40 +000036
Bram Moolenaar779b74b2006-04-10 14:55:34 +000037syn region rstTable transparent start='^\n\s*+[-=+]\+' end='^$'
38 \ contains=rstTableLines,@rstCruft
39syn match rstTableLines contained display '|\|+\%(=\+\|-\+\)\='
Bram Moolenaar071d4272004-06-13 20:20:40 +000040
Bram Moolenaar779b74b2006-04-10 14:55:34 +000041syn 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*\)\@>\)\+\)\@>$'
Bram Moolenaar071d4272004-06-13 20:20:40 +000049
Bram Moolenaar779b74b2006-04-10 14:55:34 +000050syn cluster rstDirectives contains=rstFootnote,rstCitation,
51 \ rstHyperlinkTarget,rstExDirective
Bram Moolenaar071d4272004-06-13 20:20:40 +000052
Bram Moolenaar779b74b2006-04-10 14:55:34 +000053syn match rstExplicitMarkup '^\.\.\s'
54 \ nextgroup=@rstDirectives,rstComment,rstSubstitutionDefinition
Bram Moolenaar071d4272004-06-13 20:20:40 +000055
Bram Moolenaar779b74b2006-04-10 14:55:34 +000056let s:ReferenceName = '[[:alnum:]]\+\%([_.-][[:alnum:]]\+\)*'
Bram Moolenaar071d4272004-06-13 20:20:40 +000057
Bram Moolenaar779b74b2006-04-10 14:55:34 +000058syn keyword rstTodo contained FIXME TODO XXX NOTE
Bram Moolenaar071d4272004-06-13 20:20:40 +000059
Bram Moolenaar779b74b2006-04-10 14:55:34 +000060execute 'syn region rstComment contained' .
61 \ ' start=/.*/'
62 \ ' end=/^\s\@!/ contains=rstTodo'
Bram Moolenaar071d4272004-06-13 20:20:40 +000063
Bram Moolenaar779b74b2006-04-10 14:55:34 +000064execute '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.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000143syn sync minlines=50
144
Bram Moolenaar779b74b2006-04-10 14:55:34 +0000145hi 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
Bram Moolenaar071d4272004-06-13 20:20:40 +0000174
175let b:current_syntax = "rst"
176
Bram Moolenaar42eeac32005-06-29 22:40:58 +0000177let &cpo = s:cpo_save
178unlet s:cpo_save