Skip to content

Commit f2ef26e

Browse files
committed
feat: add (note) node for highlighted notes and warnings
Add support for highlighting common call-out terms in documentation, like the legacy syntax's `helpNote`, `helpWarning`, `helpDeprecated`. However, only the variants with a colon are supported, as these account for 99% of use in Nvim documentation without the danger of false positives (and to keep symbol count low). To keep state count low, all these are parsed as a single `(note)` node that captures can disambiguate using `#any-of?`.
1 parent 60045f7 commit f2ef26e

File tree

7 files changed

+9127
-4820
lines changed

7 files changed

+9127
-4820
lines changed

corpus/taglink.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Note: ":autocmd" can...
146146
(line)))
147147
(block
148148
(line
149-
(word)
149+
(note)
150150
(word)
151151
(word))
152152
(line

corpus/text.txt

+44
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,47 @@ line
6464
(block
6565
(line
6666
(word))))
67+
68+
================================================================================
69+
notes
70+
================================================================================
71+
NOTE: this is a note
72+
73+
Note that this is not a note.
74+
75+
This is DEPRECATED:
76+
77+
This is not DEPRECATED.
78+
79+
80+
--------------------------------------------------------------------------------
81+
82+
(help_file
83+
(block
84+
(line
85+
(note)
86+
(word)
87+
(word)
88+
(word)
89+
(word)))
90+
(block
91+
(line
92+
(word)
93+
(word)
94+
(word)
95+
(word)
96+
(word)
97+
(word)
98+
(word)))
99+
(block
100+
(line
101+
(word)
102+
(word)
103+
(note)))
104+
(block
105+
(line
106+
(word)
107+
(word)
108+
(word)
109+
(word))))
110+

grammar.js

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ module.exports = grammar({
5454
$.codespan,
5555
$.argument,
5656
$.keycode,
57+
$.note,
5758
),
5859

5960
// Explicit special cases: these are plaintext, not errors.
@@ -84,6 +85,12 @@ module.exports = grammar({
8485
',',
8586
),
8687

88+
note: () => choice(
89+
'Note:', 'NOTE:', 'Notes:',
90+
'Warning:', 'WARNING:',
91+
'Deprecated', 'DEPRECATED:'
92+
),
93+
8794
keycode: () => choice(
8895
/<[-a-zA-Z0-9_]+>/,
8996
/<[SCMAD]-.>/,

queries/help/highlights.scm

+6
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,9 @@
2323
(argument) @parameter
2424
(keycode) @string.special
2525
(url) @text.uri
26+
((note) @text.note
27+
(#any-of? "Note:" "NOTE:" "Notes:"))
28+
((note) @text.warning
29+
(#any-of? "Warning:" "WARNING:"))
30+
((note) @text.danger
31+
(#any-of? "Deprecated:" "DEPRECATED:"))

src/grammar.json

+37
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/node-types.json

+53
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)