7
|
1 " Vim syntax file
|
375
|
2 " Language: reStructuredText documentation format
|
6159
|
3 " Maintainer: Marshall Ward <marshall.ward@gmail.com>
|
|
4 " Previous Maintainer: Nikolai Weibull <now@bitwi.se>
|
|
5 " Latest Revision: 2014-08-23
|
7
|
6
|
375
|
7 if exists("b:current_syntax")
|
7
|
8 finish
|
|
9 endif
|
|
10
|
375
|
11 let s:cpo_save = &cpo
|
|
12 set cpo&vim
|
|
13
|
7
|
14 syn case ignore
|
|
15
|
2034
|
16 syn match rstSections "^\%(\([=`:.'"~^_*+#-]\)\1\+\n\)\=.\+\n\([=`:.'"~^_*+#-]\)\2\+$"
|
825
|
17
|
2034
|
18 syn match rstTransition /^[=`:.'"~^_*+#-]\{4,}\s*$/
|
825
|
19
|
|
20 syn cluster rstCruft contains=rstEmphasis,rstStrongEmphasis,
|
|
21 \ rstInterpretedText,rstInlineLiteral,rstSubstitutionReference,
|
|
22 \ rstInlineInternalTargets,rstFootnoteReference,rstHyperlinkReference
|
7
|
23
|
825
|
24 syn region rstLiteralBlock matchgroup=rstDelimiter
|
|
25 \ start='::\_s*\n\ze\z(\s\+\)' skip='^$' end='^\z1\@!'
|
|
26 \ contains=@NoSpell
|
7
|
27
|
825
|
28 syn region rstQuotedLiteralBlock matchgroup=rstDelimiter
|
|
29 \ start="::\_s*\n\ze\z([!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]\)"
|
|
30 \ end='^\z1\@!' contains=@NoSpell
|
|
31
|
|
32 syn region rstDoctestBlock oneline display matchgroup=rstDelimiter
|
|
33 \ start='^>>>\s' end='^$'
|
|
34
|
|
35 syn region rstTable transparent start='^\n\s*+[-=+]\+' end='^$'
|
|
36 \ contains=rstTableLines,@rstCruft
|
|
37 syn match rstTableLines contained display '|\|+\%(=\+\|-\+\)\='
|
375
|
38
|
825
|
39 syn region rstSimpleTable transparent
|
|
40 \ start='^\n\%(\s*\)\@>\%(\%(=\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(=\+\)\@>\%(\s*\)\@>\)\+\)\@>$'
|
|
41 \ end='^$'
|
|
42 \ contains=rstSimpleTableLines,@rstCruft
|
|
43 syn match rstSimpleTableLines contained display
|
|
44 \ '^\%(\s*\)\@>\%(\%(=\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(=\+\)\@>\%(\s*\)\@>\)\+\)\@>$'
|
|
45 syn match rstSimpleTableLines contained display
|
|
46 \ '^\%(\s*\)\@>\%(\%(-\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(-\+\)\@>\%(\s*\)\@>\)\+\)\@>$'
|
|
47
|
|
48 syn cluster rstDirectives contains=rstFootnote,rstCitation,
|
|
49 \ rstHyperlinkTarget,rstExDirective
|
|
50
|
6159
|
51 syn match rstExplicitMarkup '^\s*\.\.\_s'
|
825
|
52 \ nextgroup=@rstDirectives,rstComment,rstSubstitutionDefinition
|
|
53
|
|
54 let s:ReferenceName = '[[:alnum:]]\+\%([_.-][[:alnum:]]\+\)*'
|
7
|
55
|
825
|
56 syn keyword rstTodo contained FIXME TODO XXX NOTE
|
|
57
|
|
58 execute 'syn region rstComment contained' .
|
|
59 \ ' start=/.*/'
|
|
60 \ ' end=/^\s\@!/ contains=rstTodo'
|
|
61
|
|
62 execute 'syn region rstFootnote contained matchgroup=rstDirective' .
|
|
63 \ ' start=+\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]\_s+' .
|
|
64 \ ' skip=+^$+' .
|
|
65 \ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell'
|
|
66
|
|
67 execute 'syn region rstCitation contained matchgroup=rstDirective' .
|
|
68 \ ' start=+\[' . s:ReferenceName . '\]\_s+' .
|
|
69 \ ' skip=+^$+' .
|
|
70 \ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell'
|
|
71
|
|
72 syn region rstHyperlinkTarget contained matchgroup=rstDirective
|
|
73 \ start='_\%(_\|[^:\\]*\%(\\.[^:\\]*\)*\):\_s' skip=+^$+ end=+^\s\@!+
|
7
|
74
|
825
|
75 syn region rstHyperlinkTarget contained matchgroup=rstDirective
|
|
76 \ start='_`[^`\\]*\%(\\.[^`\\]*\)*`:\_s' skip=+^$+ end=+^\s\@!+
|
|
77
|
|
78 syn region rstHyperlinkTarget matchgroup=rstDirective
|
|
79 \ start=+^__\_s+ skip=+^$+ end=+^\s\@!+
|
|
80
|
|
81 execute 'syn region rstExDirective contained matchgroup=rstDirective' .
|
|
82 \ ' start=+' . s:ReferenceName . '::\_s+' .
|
|
83 \ ' skip=+^$+' .
|
|
84 \ ' end=+^\s\@!+ contains=@rstCruft'
|
7
|
85
|
825
|
86 execute 'syn match rstSubstitutionDefinition contained' .
|
|
87 \ ' /|' . s:ReferenceName . '|\_s\+/ nextgroup=@rstDirectives'
|
7
|
88
|
825
|
89 function! s:DefineOneInlineMarkup(name, start, middle, end, char_left, char_right)
|
|
90 execute 'syn region rst' . a:name .
|
|
91 \ ' start=+' . a:char_left . '\zs' . a:start .
|
1224
|
92 \ '\ze[^[:space:]' . a:char_right . a:start[strlen(a:start) - 1] . ']+' .
|
825
|
93 \ a:middle .
|
|
94 \ ' end=+\S' . a:end . '\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+'
|
|
95 endfunction
|
|
96
|
|
97 function! s:DefineInlineMarkup(name, start, middle, end)
|
|
98 let middle = a:middle != "" ?
|
|
99 \ (' skip=+\\\\\|\\' . a:middle . '+') :
|
|
100 \ ""
|
7
|
101
|
825
|
102 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, "'", "'")
|
6159
|
103 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '"', '"')
|
|
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, '<', '>')
|
7
|
108
|
825
|
109 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '\%(^\|\s\|[/:]\)', '')
|
|
110
|
|
111 execute 'syn match rst' . a:name .
|
|
112 \ ' +\%(^\|\s\|[''"([{</:]\)\zs' . a:start .
|
|
113 \ '[^[:space:]' . a:start[strlen(a:start) - 1] . ']'
|
|
114 \ a:end . '\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+'
|
|
115
|
|
116 execute 'hi def link rst' . a:name . 'Delimiter' . ' rst' . a:name
|
|
117 endfunction
|
7
|
118
|
825
|
119 call s:DefineInlineMarkup('Emphasis', '\*', '\*', '\*')
|
|
120 call s:DefineInlineMarkup('StrongEmphasis', '\*\*', '\*', '\*\*')
|
|
121 call s:DefineInlineMarkup('InterpretedTextOrHyperlinkReference', '`', '`', '`_\{0,2}')
|
|
122 call s:DefineInlineMarkup('InlineLiteral', '``', "", '``')
|
|
123 call s:DefineInlineMarkup('SubstitutionReference', '|', '|', '|_\{0,2}')
|
|
124 call s:DefineInlineMarkup('InlineInternalTargets', '_`', '`', '`')
|
|
125
|
|
126 " TODO: Can’t remember why these two can’t be defined like the ones above.
|
|
127 execute 'syn match rstFootnoteReference contains=@NoSpell' .
|
|
128 \ ' +\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]_+'
|
7
|
129
|
825
|
130 execute 'syn match rstCitationReference contains=@NoSpell' .
|
1224
|
131 \ ' +\[' . s:ReferenceName . '\]_\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+'
|
825
|
132
|
|
133 execute 'syn match rstHyperlinkReference' .
|
1224
|
134 \ ' /\<' . s:ReferenceName . '__\=\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)/'
|
375
|
135
|
825
|
136 syn match rstStandaloneHyperlink contains=@NoSpell
|
|
137 \ "\<\%(\%(\%(https\=\|file\|ftp\|gopher\)://\|\%(mailto\|news\):\)[^[:space:]'\"<>]\+\|www[[:alnum:]_-]*\.[[:alnum:]_-]\+\.[^[:space:]'\"<>]\+\)[[:alnum:]/]"
|
7
|
138
|
3920
|
139 syn region rstCodeBlock contained matchgroup=rstDirective
|
6159
|
140 \ start=+\%(sourcecode\|code\%(-block\)\=\)::\_s*\n\ze\z(\s\+\)+
|
3920
|
141 \ skip=+^$+
|
6159
|
142 \ end=+^\z1\@!+
|
3920
|
143 \ contains=@NoSpell
|
|
144 syn cluster rstDirectives add=rstCodeBlock
|
|
145
|
|
146 if !exists('g:rst_syntax_code_list')
|
6159
|
147 let g:rst_syntax_code_list = ['vim', 'java', 'cpp', 'lisp', 'php',
|
|
148 \ 'python', 'perl', 'sh']
|
3920
|
149 endif
|
|
150
|
|
151 for code in g:rst_syntax_code_list
|
|
152 unlet! b:current_syntax
|
|
153 exe 'syn include @rst'.code.' syntax/'.code.'.vim'
|
|
154 exe 'syn region rstDirective'.code.' matchgroup=rstDirective fold '
|
6159
|
155 \.'start=#\%(sourcecode\|code\%(-block\)\=\)::\s\+'.code.'\_s*\n\ze\z(\s\+\)# '
|
3920
|
156 \.'skip=#^$# '
|
6159
|
157 \.'end=#^\z1\@!# contains=@NoSpell,@rst'.code
|
3920
|
158 exe 'syn cluster rstDirectives add=rstDirective'.code
|
|
159 endfor
|
|
160
|
4780
|
161 " TODO: Use better syncing.
|
|
162 syn sync minlines=50 linebreaks=2
|
|
163
|
825
|
164 hi def link rstTodo Todo
|
|
165 hi def link rstComment Comment
|
3750
|
166 hi def link rstSections Title
|
|
167 hi def link rstTransition rstSections
|
825
|
168 hi def link rstLiteralBlock String
|
|
169 hi def link rstQuotedLiteralBlock String
|
|
170 hi def link rstDoctestBlock PreProc
|
|
171 hi def link rstTableLines rstDelimiter
|
|
172 hi def link rstSimpleTableLines rstTableLines
|
|
173 hi def link rstExplicitMarkup rstDirective
|
|
174 hi def link rstDirective Keyword
|
|
175 hi def link rstFootnote String
|
|
176 hi def link rstCitation String
|
|
177 hi def link rstHyperlinkTarget String
|
|
178 hi def link rstExDirective String
|
|
179 hi def link rstSubstitutionDefinition rstDirective
|
|
180 hi def link rstDelimiter Delimiter
|
|
181 " TODO: I dunno...
|
|
182 hi def rstEmphasis term=italic cterm=italic gui=italic
|
|
183 hi def link rstStrongEmphasis Special
|
|
184 "term=bold cterm=bold gui=bold
|
|
185 hi def link rstInterpretedTextOrHyperlinkReference Identifier
|
|
186 hi def link rstInlineLiteral String
|
|
187 hi def link rstSubstitutionReference PreProc
|
|
188 hi def link rstInlineInternalTargets Identifier
|
|
189 hi def link rstFootnoteReference Identifier
|
|
190 hi def link rstCitationReference Identifier
|
|
191 hi def link rstHyperLinkReference Identifier
|
|
192 hi def link rstStandaloneHyperlink Identifier
|
3920
|
193 hi def link rstCodeBlock String
|
7
|
194
|
|
195 let b:current_syntax = "rst"
|
|
196
|
375
|
197 let &cpo = s:cpo_save
|
|
198 unlet s:cpo_save
|