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