runtime(rst): Recognise numeric footnotes [1] correctly
Commit:
https://github.com/vim/vim/commit/5485827c5f872884dab83607e89562c8db4899c4
Author: Kirk Roemer <[email protected]>
Date: Mon Oct 13 18:30:48 2025 +0000
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 <[email protected]>
Signed-off-by: Marshall Ward <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/runtime/syntax/rst.vim b/runtime/syntax/rst.vim
index 8094d8771..308ae5d68 100644
--- a/runtime/syntax/rst.vim
+++ b/runtime/syntax/rst.vim
@@ -66,17 +66,20 @@ syn region rstComment
\ start=' ^\z(\s*)\.\.(\_s+[\[|_]|\_s+.*::)@!' skip=+^$+ end=/^\(\z1
\)\@!/
\ contains=@Spell,rstTodo
+" Note: Order matters for rstCitation and rstFootnote as the regex for
+" citations also matches numeric only patterns, e.g. [1], which are footnotes.
+" Since we define rstFootnote after rstCitation, it takes precedence, see
+" |:syn-define|.
+execute 'syn region rstCitation contained matchgroup=rstDirective' .
+ \ ' start=+\[' . s:ReferenceName . '\]\_s+' .
+ \ ' skip=+^$+' .
+ \ ' end=+^\s\@!+ contains=@Spell,@rstCruft'
execute 'syn region rstFootnote contained matchgroup=rstDirective' .
\ ' start=+\[\%(\d\+\|#\%(' . s:ReferenceName . '\)\=\|\*\)\]\_s+' .
\ ' skip=+^$+' .
\ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell'
-execute 'syn region rstCitation contained matchgroup=rstDirective' .
- \ ' start=+\[' . s:ReferenceName . '\]\_s+' .
- \ ' skip=+^$+' .
- \ ' end=+^\s\@!+ contains=@rstCruft,@NoSpell'
-
syn region rstHyperlinkTarget contained matchgroup=rstDirective
\ start='_\%(_\|[^:\]*\%(\.[^:\]*\)*\):\_s' skip=+^$+ end=+^\s\@!+
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/vim_dev/E1v8NXj-00Cgpu-Ds%40256bit.org.