Mercurial > vim
annotate runtime/syntax/rst.vim @ 11017:da1cbfa57265
Added tag v8.0.0397 for changeset 4e7308525fe723c6f959e2db8e880610c8aee63a
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 01 Mar 2017 20:45:06 +0100 |
parents | 2b6654519a7c |
children | 2f7e67dd088c |
rev | line source |
---|---|
7 | 1 " Vim syntax file |
6292
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
2 " Language: reStructuredText documentation format |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
3 " Maintainer: Marshall Ward <marshall.ward@gmail.com> |
6159 | 4 " Previous Maintainer: Nikolai Weibull <now@bitwi.se> |
9908
2b6654519a7c
commit https://github.com/vim/vim/commit/7571d55f7dcc009a375b2124cce2c8b21f361234
Christian Brabandt <cb@256bit.org>
parents:
9319
diff
changeset
|
5 " Website: https://github.com/marshallward/vim-restructuredtext |
2b6654519a7c
commit https://github.com/vim/vim/commit/7571d55f7dcc009a375b2124cce2c8b21f361234
Christian Brabandt <cb@256bit.org>
parents:
9319
diff
changeset
|
6 " Latest Revision: 2016-08-18 |
7 | 7 |
375 | 8 if exists("b:current_syntax") |
7 | 9 finish |
10 endif | |
11 | |
375 | 12 let s:cpo_save = &cpo |
13 set cpo&vim | |
14 | |
7 | 15 syn case ignore |
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 | |
6159 | 50 syn match rstExplicitMarkup '^\s*\.\.\_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=+^$+' . | |
7100
f717d96a39b3
commit https://github.com/vim/vim/commit/12969c04fe7bd27dc0cbf37709eb40a86d4a27f9
Christian Brabandt <cb@256bit.org>
parents:
6292
diff
changeset
|
83 \ ' end=+^\s\@!+ contains=@rstCruft,rstLiteralBlock' |
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 . |
9908
2b6654519a7c
commit https://github.com/vim/vim/commit/7571d55f7dcc009a375b2124cce2c8b21f361234
Christian Brabandt <cb@256bit.org>
parents:
9319
diff
changeset
|
93 \ ' end=+\S' . a:end . '\ze\%($\|\s\|[''"’)\]}>/:.,;!?\\-]\)+' |
825 | 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, "'", "'") |
6159 | 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, '<', '>') | |
9908
2b6654519a7c
commit https://github.com/vim/vim/commit/7571d55f7dcc009a375b2124cce2c8b21f361234
Christian Brabandt <cb@256bit.org>
parents:
9319
diff
changeset
|
107 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '’', '’') |
2b6654519a7c
commit https://github.com/vim/vim/commit/7571d55f7dcc009a375b2124cce2c8b21f361234
Christian Brabandt <cb@256bit.org>
parents:
9319
diff
changeset
|
108 " TODO: Additional Unicode Pd, Po, Pi, Pf, Ps characters |
7 | 109 |
825 | 110 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '\%(^\|\s\|[/:]\)', '') |
111 | |
112 execute 'syn match rst' . a:name . | |
113 \ ' +\%(^\|\s\|[''"([{</:]\)\zs' . a:start . | |
114 \ '[^[:space:]' . a:start[strlen(a:start) - 1] . ']' | |
115 \ a:end . '\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+' | |
116 | |
117 execute 'hi def link rst' . a:name . 'Delimiter' . ' rst' . a:name | |
118 endfunction | |
7 | 119 |
825 | 120 call s:DefineInlineMarkup('Emphasis', '\*', '\*', '\*') |
121 call s:DefineInlineMarkup('StrongEmphasis', '\*\*', '\*', '\*\*') | |
122 call s:DefineInlineMarkup('InterpretedTextOrHyperlinkReference', '`', '`', '`_\{0,2}') | |
123 call s:DefineInlineMarkup('InlineLiteral', '``', "", '``') | |
124 call s:DefineInlineMarkup('SubstitutionReference', '|', '|', '|_\{0,2}') | |
125 call s:DefineInlineMarkup('InlineInternalTargets', '_`', '`', '`') | |
126 | |
7597
3012eaddb6b2
commit https://github.com/vim/vim/commit/345efa013dc6d1754ba06e5596a26c48c9935937
Christian Brabandt <cb@256bit.org>
parents:
7100
diff
changeset
|
127 syn match rstSections "^\%(\([=`:.'"~^_*+#-]\)\1\+\n\)\=.\+\n\([=`:.'"~^_*+#-]\)\2\+$" |
3012eaddb6b2
commit https://github.com/vim/vim/commit/345efa013dc6d1754ba06e5596a26c48c9935937
Christian Brabandt <cb@256bit.org>
parents:
7100
diff
changeset
|
128 |
825 | 129 " TODO: Can’t remember why these two can’t be defined like the ones above. |
130 execute 'syn match rstFootnoteReference contains=@NoSpell' . | |
131 \ ' +\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]_+' | |
7 | 132 |
825 | 133 execute 'syn match rstCitationReference contains=@NoSpell' . |
1224 | 134 \ ' +\[' . s:ReferenceName . '\]_\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+' |
825 | 135 |
136 execute 'syn match rstHyperlinkReference' . | |
1224 | 137 \ ' /\<' . s:ReferenceName . '__\=\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)/' |
375 | 138 |
825 | 139 syn match rstStandaloneHyperlink contains=@NoSpell |
140 \ "\<\%(\%(\%(https\=\|file\|ftp\|gopher\)://\|\%(mailto\|news\):\)[^[:space:]'\"<>]\+\|www[[:alnum:]_-]*\.[[:alnum:]_-]\+\.[^[:space:]'\"<>]\+\)[[:alnum:]/]" | |
7 | 141 |
3920 | 142 syn region rstCodeBlock contained matchgroup=rstDirective |
9319
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
143 \ start=+\%(sourcecode\|code\%(-block\)\=\)::\s\+\w*\_s*\n\ze\z(\s\+\)+ |
3920 | 144 \ skip=+^$+ |
6159 | 145 \ end=+^\z1\@!+ |
3920 | 146 \ contains=@NoSpell |
147 syn cluster rstDirectives add=rstCodeBlock | |
148 | |
149 if !exists('g:rst_syntax_code_list') | |
6159 | 150 let g:rst_syntax_code_list = ['vim', 'java', 'cpp', 'lisp', 'php', |
151 \ 'python', 'perl', 'sh'] | |
3920 | 152 endif |
153 | |
154 for code in g:rst_syntax_code_list | |
155 unlet! b:current_syntax | |
6292
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
156 " guard against setting 'isk' option which might cause problems (issue #108) |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
157 let prior_isk = &l:iskeyword |
3920 | 158 exe 'syn include @rst'.code.' syntax/'.code.'.vim' |
9319
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
159 exe 'syn region rstDirective'.code.' matchgroup=rstDirective fold' |
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
160 \.' start=#\%(sourcecode\|code\%(-block\)\=\)::\s\+'.code.'\_s*\n\ze\z(\s\+\)#' |
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
161 \.' skip=#^$#' |
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
162 \.' end=#^\z1\@!#' |
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
163 \.' contains=@NoSpell,@rst'.code |
3920 | 164 exe 'syn cluster rstDirectives add=rstDirective'.code |
6292
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
165 " reset 'isk' setting, if it has been changed |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
166 if &l:iskeyword !=# prior_isk |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
167 let &l:iskeyword = prior_isk |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
168 endif |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
169 unlet! prior_isk |
3920 | 170 endfor |
171 | |
4780 | 172 " TODO: Use better syncing. |
173 syn sync minlines=50 linebreaks=2 | |
174 | |
825 | 175 hi def link rstTodo Todo |
176 hi def link rstComment Comment | |
3750 | 177 hi def link rstSections Title |
178 hi def link rstTransition rstSections | |
825 | 179 hi def link rstLiteralBlock String |
180 hi def link rstQuotedLiteralBlock String | |
181 hi def link rstDoctestBlock PreProc | |
182 hi def link rstTableLines rstDelimiter | |
183 hi def link rstSimpleTableLines rstTableLines | |
184 hi def link rstExplicitMarkup rstDirective | |
185 hi def link rstDirective Keyword | |
186 hi def link rstFootnote String | |
187 hi def link rstCitation String | |
188 hi def link rstHyperlinkTarget String | |
189 hi def link rstExDirective String | |
190 hi def link rstSubstitutionDefinition rstDirective | |
191 hi def link rstDelimiter Delimiter | |
9908
2b6654519a7c
commit https://github.com/vim/vim/commit/7571d55f7dcc009a375b2124cce2c8b21f361234
Christian Brabandt <cb@256bit.org>
parents:
9319
diff
changeset
|
192 hi def rstEmphasis ctermfg=13 term=italic cterm=italic gui=italic |
2b6654519a7c
commit https://github.com/vim/vim/commit/7571d55f7dcc009a375b2124cce2c8b21f361234
Christian Brabandt <cb@256bit.org>
parents:
9319
diff
changeset
|
193 hi def rstStrongEmphasis ctermfg=1 term=bold cterm=bold gui=bold |
825 | 194 hi def link rstInterpretedTextOrHyperlinkReference Identifier |
195 hi def link rstInlineLiteral String | |
196 hi def link rstSubstitutionReference PreProc | |
197 hi def link rstInlineInternalTargets Identifier | |
198 hi def link rstFootnoteReference Identifier | |
199 hi def link rstCitationReference Identifier | |
200 hi def link rstHyperLinkReference Identifier | |
201 hi def link rstStandaloneHyperlink Identifier | |
3920 | 202 hi def link rstCodeBlock String |
7 | 203 |
204 let b:current_syntax = "rst" | |
205 | |
375 | 206 let &cpo = s:cpo_save |
207 unlet s:cpo_save |