Skip to content

Commit 5485827

Browse files
Kirk Roemerchrisbra
authored andcommitted
runtime(rst): Recognise numeric footnotes [1] correctly
The markup for footonotes [1] and citations [2] are almost identical. The difference is that footnotes allow numeric values but citations allow every valid reference name except numeric values. The regex for matching citations currently only checks for valid reference names but does not exclude number-only labels, thus also matches numeric footnotes. To match such footnotes, e.g. ``[1]`` define the syntax rule for footnotes after the syntax rule for citations so it gets higher precedence and matches first. [1] https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#footnotes [2] https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#citations related: #18566 Signed-off-by: Kirk Roemer <91125534+kirk-roemer@users.noreply.github.com> Signed-off-by: Marshall Ward <marshall.ward@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
1 parent 4e9f16d commit 5485827

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

runtime/syntax/rst.vim

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,20 @@ syn region rstComment
6666
\ start='\v^\z(\s*)\.\.(\_s+[\[|_]|\_s+.*::)@!' skip=+^$+ end=/^\(\z1 \)\@!/
6767
\ contains=@Spell,rstTodo
6868

69+
" Note: Order matters for rstCitation and rstFootnote as the regex for
70+
" citations also matches numeric only patterns, e.g. [1], which are footnotes.
71+
" Since we define rstFootnote after rstCitation, it takes precedence, see
72+
" |:syn-define|.
73+
execute 'syn region rstCitation contained matchgroup=rstDirective' .
74+
\ ' start=+\[' . s:ReferenceName . '\]\_s+' .
75+
\ ' skip=+^$+' .
76+
\ ' end=+^\s\@!+ contains=@Spell,@rstCruft'
6977

7078
execute 'syn region rstFootnote contained matchgroup=rstDirective' .
7179
\ ' start=+\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]\_s+' .
7280
\ ' skip=+^$+' .
7381
\ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell'
7482

75-
execute 'syn region rstCitation contained matchgroup=rstDirective' .
76-
\ ' start=+\[' . s:ReferenceName . '\]\_s+' .
77-
\ ' skip=+^$+' .
78-
\ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell'
79-
8083
syn region rstHyperlinkTarget contained matchgroup=rstDirective
8184
\ start='_\%(_\|[^:\\]*\%(\\.[^:\\]*\)*\):\_s' skip=+^$+ end=+^\s\@!+
8285

0 commit comments

Comments
 (0)