Skip to content

Commit

Permalink
feat: add (note) node for highlighted notes and warnings
Browse files Browse the repository at this point in the history
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?`.
  • Loading branch information
clason committed Dec 21, 2023
1 parent 60045f7 commit 4f8ba9e
Show file tree
Hide file tree
Showing 7 changed files with 9,127 additions and 4,820 deletions.
2 changes: 1 addition & 1 deletion corpus/taglink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Note: ":autocmd" can...
(line)))
(block
(line
(word)
(note)
(word)
(word))
(line
Expand Down
44 changes: 44 additions & 0 deletions corpus/text.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,47 @@ line
(block
(line
(word))))

================================================================================
notes
================================================================================
NOTE: this is a note

Note that this is not a note.

This is DEPRECATED:

This is not DEPRECATED.


--------------------------------------------------------------------------------

(help_file
(block
(line
(note)
(word)
(word)
(word)
(word)))
(block
(line
(word)
(word)
(word)
(word)
(word)
(word)
(word)))
(block
(line
(word)
(word)
(note)))
(block
(line
(word)
(word)
(word)
(word))))

7 changes: 7 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module.exports = grammar({
$.codespan,
$.argument,
$.keycode,
$.note,
),

// Explicit special cases: these are plaintext, not errors.
Expand Down Expand Up @@ -84,6 +85,12 @@ module.exports = grammar({
',',
),

note: () => choice(
'Note:', 'NOTE:', 'Notes:',
'Warning:', 'WARNING:',
'Deprecated', 'DEPRECATED:'
),

keycode: () => choice(
/<[-a-zA-Z0-9_]+>/,
/<[SCMAD]-.>/,
Expand Down
6 changes: 6 additions & 0 deletions queries/help/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,9 @@
(argument) @parameter
(keycode) @string.special
(url) @text.uri
((note) @text.note
(#any-of? @text.note "Note:" "NOTE:" "Notes:"))
((note) @text.warning
(#any-of? @text.warning "Warning:" "WARNING:"))
((note) @text.danger
(#any-of? @text.danger "Deprecated:" "DEPRECATED:"))
37 changes: 37 additions & 0 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 53 additions & 0 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4f8ba9e

Please sign in to comment.