Skip to content

Commit

Permalink
feat: support modelines
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime authored and clason committed Mar 11, 2024
1 parent 3320dbd commit 12cce60
Show file tree
Hide file tree
Showing 6 changed files with 5,054 additions and 4,840 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ Known issues
- `column_heading` currently only recognizes tilde `~` preceded by space (i.e.
`foo ~` not `foo~`). This covers 99% of :help files.
- `column_heading` children should be plaintext, but currently are parsed as `$._atom`.
- `modeline` must be preceded by a blank line.

TODO
----

- `line_modeline` ?
- `tag_heading` : line(s) containing only tags, typically implies a "heading"
before a block.

Expand Down
4 changes: 4 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = grammar({
seq(
repeat($._blank), // Eat blank lines at top of file.
repeat($.block),
repeat($.modeline),
),

_atom: ($) => choice(
Expand Down Expand Up @@ -169,6 +170,9 @@ module.exports = grammar({
choice($.codeblock, '\n')
),

// Modeline: must start with "vim:" (optionally preceded by whitespace)
modeline: ($) => token(prec(2, /[\t ]*vim:[^\n]+\n/)),

// "Column heading": plaintext followed by "~".
// Intended for table column names per `:help help-writing`.
// TODO: children should be $.word (plaintext), not $.atom.
Expand Down
2 changes: 2 additions & 0 deletions queries/vimdoc/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@

(url) @string.special.url

(modeline) @keyword.directive

((note) @comment.hint
(#any-of? @comment.hint "Note:" "NOTE:" "Notes:"))

Expand Down
18 changes: 18 additions & 0 deletions src/grammar.json

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

8 changes: 8 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 12cce60

Please sign in to comment.