summaryrefslogtreecommitdiff
path: root/runtime/syntax/rst.vim
blob: 02d43c66d81ae26048b8aa614b59d34fa0bda6c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
" Vim syntax file
" Language:	    reStructuredText Documentation Format
" Maintainer:	    Nikolai Weibull <source@pcppopper.org>
" URL:		    http://www.pcppopper.org/vim/syntax/pcp/rst/
" Latest Revision:  2004-05-13
" arch-tag:	    6fae09da-d5d4-49d8-aec1-e49008ea21e6

if version < 600
  syntax clear
elseif exists("b:current_syntax")
  finish
endif

" todo
syn keyword	rstTodo		contained FIXME TODO XXX NOTE

syn case ignore

" comments
syn region	rstComment 	matchgroup=rstComment start="^\.\.\%( \%([a-z0-9_.-]\+::\)\@!\|$\)" end="^\s\@!" contains=rstTodo

syn cluster	rstCruft    contains=rstFootnoteLabel,rstCitationLabel,rstSubstitutionLabel,rstInline,rstHyperlinks,rstInternalTarget

" blocks
" syn region	rstBlock	matchgroup=rstDelimiter start=":\@<!:$" skip="^$" end="^\s\@!" contains=@rstCruft
syn region	rstBlock	matchgroup=rstDelimiter start="::$" skip="^$" end="^\s\@!"
syn region	rstDoctestBlock	matchgroup=rstDelimiter start="^>>>\s" end="^$"

" tables
" TODO: these may actually be a bit too complicated to match correctly and
" should perhaps be removed.  Whon really needs it anyway?
syn region	rstTable	transparent start="^\n\s*+[-=+]\+" end="^$" contains=rstTableLines,@rstCruft
syn match	rstTableLines	contained "^\s*[|+=-]\+$"
syn region	rstSimpleTable	transparent start="^\n\s*\%(=\+\s\+\)\%(=\+\s*\)\+$" end="^$" contains=rstSimpleTableLines,@rstCruft
syn match	rstSimpleTableLines contained "^\s*\%(=\+\s\+\)\%(=\+\s*\)\+$"

" footnotes
syn region	rstFootnote 	matchgroup=rstDirective start="^\.\. \[\%([#*]\|[0-9]\+\|#[a-z0-9_.-]\+\)\]\s" end="^\s\@!" contains=@rstCruft
syn match	rstFootnoteLabel "\[\%([#*]\|[0-9]\+\|#[a-z0-9_.-]\+\)\]_"

" citations
syn region	rstCitation 	matchgroup=rstDirective start="^\.\. \[[a-z0-9_.-]\+\]\s" end="^\s\@!" contains=@rstCruft
syn match	rstCitationLabel "\[[a-z0-9_.-]\+\]_"

" directives
syn region	rstDirectiveBody matchgroup=rstDirective start="^\.\. [a-z0-9_.-]\+::" end="^\s\@!"

" substitutions
syn region	rstSubstitution matchgroup=rstDirective start="^\.\. |[a-z0-9_.-]|\s[a-z0-9_.-]\+::\s" end="^\s\@!" contains=@rstCruft
syn match	rstSubstitutionLabel "|[a-z0-9_.-]|"

" inline markup
syn match	rstInline	"\*\{1,2}\S\%([^*]*\S\)\=\*\{1,2}"
syn match	rstInline	"`\{1,2}\S\%([^`]*\S\)\=`\{1,2}"

" hyperlinks
syn region	rstHyperlinks	matchgroup=RstDirective start="^\.\. _[a-z0-9_. -]\+:\s" end="^\s\@!" contains=@rstCruft

syn match	rstHyperlinksLabel	"`\S\%([^`]*\S\)\=`__\=\>"
syn match	rstHyperlinksLabel	"\w\+__\=\>"

" internal targets
syn match	rstInternalTarget "_`\S\%([^`]*\S\)\=`"

" lists
syn match	rstListItem	"^:\%(\w\+\s*\)\+:"
syn match	rstListItem	"^\s*[-*+]\s\+"

syn sync minlines=50

" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_rst_syn_inits")
  if version < 508
    let did_rst_syn_inits = 1
    command -nargs=+ HiLink hi link <args>
  else
    command -nargs=+ HiLink hi def link <args>
  endif

  HiLink rstTodo Todo
  HiLink rstComment Comment
  HiLink rstDelimiter Delimiter
  HiLink rstBlock String
  HiLink rstDoctestBlock PreProc
  HiLink rstTableLines Delimiter
  HiLink rstSimpleTableLines rstTableLines
  HiLink rstFootnote String
  HiLink rstFootnoteLabel Identifier
  HiLink rstCitation String
  HiLink rstCitationLabel Identifier
  HiLink rstDirective Keyword
  HiLink rstDirectiveBody Type
  HiLink rstSubstitution String
  HiLink rstSubstitutionLabel Identifier
  HiLink rstHyperlinks String
  HiLink rstHyperlinksLabel Identifier
  HiLink rstListItem Identifier
  hi def rstInline term=italic cterm=italic gui=italic
  hi def rstInternalTarget term=italic cterm=italic gui=italic
  delcommand HiLink
endif

let b:current_syntax = "rst"

" vim: set sts=2 sw=2: