Mercurial > vim
annotate runtime/syntax/rst.vim @ 9402:165d9b2513e9
Added tag v7.4.1982 for changeset 160cb082819e3ee4494d219dc7e903bb7e657357
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 02 Jul 2016 19:30:06 +0200 |
parents | 1472ed67c36f |
children | 2b6654519a7c |
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> |
9319
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
5 " Latest Revision: 2016-06-17 |
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 rstTransition /^[=`:.'"~^_*+#-]\{4,}\s*$/ |
825 | 17 |
18 syn cluster rstCruft contains=rstEmphasis,rstStrongEmphasis, | |
19 \ rstInterpretedText,rstInlineLiteral,rstSubstitutionReference, | |
20 \ rstInlineInternalTargets,rstFootnoteReference,rstHyperlinkReference | |
7 | 21 |
825 | 22 syn region rstLiteralBlock matchgroup=rstDelimiter |
23 \ start='::\_s*\n\ze\z(\s\+\)' skip='^$' end='^\z1\@!' | |
24 \ contains=@NoSpell | |
7 | 25 |
825 | 26 syn region rstQuotedLiteralBlock matchgroup=rstDelimiter |
27 \ start="::\_s*\n\ze\z([!\"#$%&'()*+,-./:;<=>?@[\]^_`{|}~]\)" | |
28 \ end='^\z1\@!' contains=@NoSpell | |
29 | |
30 syn region rstDoctestBlock oneline display matchgroup=rstDelimiter | |
31 \ start='^>>>\s' end='^$' | |
32 | |
33 syn region rstTable transparent start='^\n\s*+[-=+]\+' end='^$' | |
34 \ contains=rstTableLines,@rstCruft | |
35 syn match rstTableLines contained display '|\|+\%(=\+\|-\+\)\=' | |
375 | 36 |
825 | 37 syn region rstSimpleTable transparent |
38 \ start='^\n\%(\s*\)\@>\%(\%(=\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(=\+\)\@>\%(\s*\)\@>\)\+\)\@>$' | |
39 \ end='^$' | |
40 \ contains=rstSimpleTableLines,@rstCruft | |
41 syn match rstSimpleTableLines contained display | |
42 \ '^\%(\s*\)\@>\%(\%(=\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(=\+\)\@>\%(\s*\)\@>\)\+\)\@>$' | |
43 syn match rstSimpleTableLines contained display | |
44 \ '^\%(\s*\)\@>\%(\%(-\+\)\@>\%(\s\+\)\@>\)\%(\%(\%(-\+\)\@>\%(\s*\)\@>\)\+\)\@>$' | |
45 | |
46 syn cluster rstDirectives contains=rstFootnote,rstCitation, | |
47 \ rstHyperlinkTarget,rstExDirective | |
48 | |
6159 | 49 syn match rstExplicitMarkup '^\s*\.\.\_s' |
825 | 50 \ nextgroup=@rstDirectives,rstComment,rstSubstitutionDefinition |
51 | |
52 let s:ReferenceName = '[[:alnum:]]\+\%([_.-][[:alnum:]]\+\)*' | |
7 | 53 |
825 | 54 syn keyword rstTodo contained FIXME TODO XXX NOTE |
55 | |
56 execute 'syn region rstComment contained' . | |
57 \ ' start=/.*/' | |
58 \ ' end=/^\s\@!/ contains=rstTodo' | |
59 | |
60 execute 'syn region rstFootnote contained matchgroup=rstDirective' . | |
61 \ ' start=+\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]\_s+' . | |
62 \ ' skip=+^$+' . | |
63 \ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell' | |
64 | |
65 execute 'syn region rstCitation contained matchgroup=rstDirective' . | |
66 \ ' start=+\[' . s:ReferenceName . '\]\_s+' . | |
67 \ ' skip=+^$+' . | |
68 \ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell' | |
69 | |
70 syn region rstHyperlinkTarget contained matchgroup=rstDirective | |
71 \ start='_\%(_\|[^:\\]*\%(\\.[^:\\]*\)*\):\_s' skip=+^$+ end=+^\s\@!+ | |
7 | 72 |
825 | 73 syn region rstHyperlinkTarget contained matchgroup=rstDirective |
74 \ start='_`[^`\\]*\%(\\.[^`\\]*\)*`:\_s' skip=+^$+ end=+^\s\@!+ | |
75 | |
76 syn region rstHyperlinkTarget matchgroup=rstDirective | |
77 \ start=+^__\_s+ skip=+^$+ end=+^\s\@!+ | |
78 | |
79 execute 'syn region rstExDirective contained matchgroup=rstDirective' . | |
80 \ ' start=+' . s:ReferenceName . '::\_s+' . | |
81 \ ' skip=+^$+' . | |
7100
f717d96a39b3
commit https://github.com/vim/vim/commit/12969c04fe7bd27dc0cbf37709eb40a86d4a27f9
Christian Brabandt <cb@256bit.org>
parents:
6292
diff
changeset
|
82 \ ' end=+^\s\@!+ contains=@rstCruft,rstLiteralBlock' |
7 | 83 |
825 | 84 execute 'syn match rstSubstitutionDefinition contained' . |
85 \ ' /|' . s:ReferenceName . '|\_s\+/ nextgroup=@rstDirectives' | |
7 | 86 |
825 | 87 function! s:DefineOneInlineMarkup(name, start, middle, end, char_left, char_right) |
88 execute 'syn region rst' . a:name . | |
89 \ ' start=+' . a:char_left . '\zs' . a:start . | |
1224 | 90 \ '\ze[^[:space:]' . a:char_right . a:start[strlen(a:start) - 1] . ']+' . |
825 | 91 \ a:middle . |
92 \ ' end=+\S' . a:end . '\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+' | |
93 endfunction | |
94 | |
95 function! s:DefineInlineMarkup(name, start, middle, end) | |
96 let middle = a:middle != "" ? | |
97 \ (' skip=+\\\\\|\\' . a:middle . '+') : | |
98 \ "" | |
7 | 99 |
825 | 100 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, "'", "'") |
6159 | 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, '<', '>') | |
7 | 106 |
825 | 107 call s:DefineOneInlineMarkup(a:name, a:start, middle, a:end, '\%(^\|\s\|[/:]\)', '') |
108 | |
109 execute 'syn match rst' . a:name . | |
110 \ ' +\%(^\|\s\|[''"([{</:]\)\zs' . a:start . | |
111 \ '[^[:space:]' . a:start[strlen(a:start) - 1] . ']' | |
112 \ a:end . '\ze\%($\|\s\|[''")\]}>/:.,;!?\\-]\)+' | |
113 | |
114 execute 'hi def link rst' . a:name . 'Delimiter' . ' rst' . a:name | |
115 endfunction | |
7 | 116 |
825 | 117 call s:DefineInlineMarkup('Emphasis', '\*', '\*', '\*') |
118 call s:DefineInlineMarkup('StrongEmphasis', '\*\*', '\*', '\*\*') | |
119 call s:DefineInlineMarkup('InterpretedTextOrHyperlinkReference', '`', '`', '`_\{0,2}') | |
120 call s:DefineInlineMarkup('InlineLiteral', '``', "", '``') | |
121 call s:DefineInlineMarkup('SubstitutionReference', '|', '|', '|_\{0,2}') | |
122 call s:DefineInlineMarkup('InlineInternalTargets', '_`', '`', '`') | |
123 | |
7597
3012eaddb6b2
commit https://github.com/vim/vim/commit/345efa013dc6d1754ba06e5596a26c48c9935937
Christian Brabandt <cb@256bit.org>
parents:
7100
diff
changeset
|
124 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
|
125 |
825 | 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 |
9319
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
140 \ start=+\%(sourcecode\|code\%(-block\)\=\)::\s\+\w*\_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 | |
6292
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
153 " 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
|
154 let prior_isk = &l:iskeyword |
3920 | 155 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
|
156 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
|
157 \.' 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
|
158 \.' skip=#^$#' |
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
159 \.' end=#^\z1\@!#' |
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
160 \.' contains=@NoSpell,@rst'.code |
3920 | 161 exe 'syn cluster rstDirectives add=rstDirective'.code |
6292
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
162 " reset 'isk' setting, if it has been changed |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
163 if &l:iskeyword !=# prior_isk |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
164 let &l:iskeyword = prior_isk |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
165 endif |
31f7581068a9
Update runtime files and translations.
Bram Moolenaar <bram@vim.org>
parents:
6159
diff
changeset
|
166 unlet! prior_isk |
3920 | 167 endfor |
168 | |
4780 | 169 " TODO: Use better syncing. |
170 syn sync minlines=50 linebreaks=2 | |
171 | |
825 | 172 hi def link rstTodo Todo |
173 hi def link rstComment Comment | |
3750 | 174 hi def link rstSections Title |
175 hi def link rstTransition rstSections | |
825 | 176 hi def link rstLiteralBlock String |
177 hi def link rstQuotedLiteralBlock String | |
178 hi def link rstDoctestBlock PreProc | |
179 hi def link rstTableLines rstDelimiter | |
180 hi def link rstSimpleTableLines rstTableLines | |
181 hi def link rstExplicitMarkup rstDirective | |
182 hi def link rstDirective Keyword | |
183 hi def link rstFootnote String | |
184 hi def link rstCitation String | |
185 hi def link rstHyperlinkTarget String | |
186 hi def link rstExDirective String | |
187 hi def link rstSubstitutionDefinition rstDirective | |
188 hi def link rstDelimiter Delimiter | |
9319
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
189 hi def link rstEmphasis Underlined |
825 | 190 hi def link rstStrongEmphasis Special |
9319
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
191 " TODO Append these atttributes somehow |
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
192 "hi def rstEmphasis term=italic cterm=italic gui=italic |
1472ed67c36f
commit https://github.com/vim/vim/commit/a02a551e18209423584fcb923e93c6be18f3aa45
Christian Brabandt <cb@256bit.org>
parents:
7597
diff
changeset
|
193 "hi def rstStrongEmphasis 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 |