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