Skip to content

Commit

Permalink
fix: taglinks |-x| |==| not recognized
Browse files Browse the repository at this point in the history
Problem:
taglinks like `|-x|` and `|==|` are matched against the $.word pattern
`/\|---[-+]+\|/` and `/\|===[=+]+\|/`, respectively (treesitter bug?).
This prevents valid taglinks from being recognized.

Solution:
Give up on "|====|" and "|----|" plaintext nodes. These will now be
parsed as taglinks. Consumers must ignore these cases manually.
  • Loading branch information
justinmk committed Oct 5, 2022
1 parent ecb4300 commit 33afae9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
27 changes: 25 additions & 2 deletions corpus/taglink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ taglink in text
================================================================================
Hello |world| hello

|-+| +[num] line
|-e| -e Ex
|-| - minus



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

Expand All @@ -26,6 +31,22 @@ Hello |world| hello
(word)
(taglink
(word))
(word)))
(block
(line
(taglink
(word))
(word)
(word))
(line
(taglink
(word))
(word)
(word))
(line
(taglink
(word))
(word)
(word))))

================================================================================
Expand Down Expand Up @@ -78,8 +99,10 @@ Note: ":autocmd" can...
(word))
(line
(word)
(word)
(word)))
(taglink
(word))
(taglink
(word))))
(block
(line_li
(line
Expand Down
7 changes: 3 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ module.exports = grammar({

// Explicit special cases: these are plaintext, not errors.
_word_common: () => choice(
// "|====|" and "|----|" are (plain text) table borders, not taglinks.
/\|(([+=][+=][+=][+=]+)|([+-][+-][+-][+-]+))\|/,
// NOT optionlink: single "'".
/[\t ]'[\t ]/,
// NOT optionlink: contains any non-lowercase char.
Expand Down Expand Up @@ -115,7 +113,7 @@ module.exports = grammar({
$.codeblock,
$._line_noli,
),
// Listitem line: consumes "*" line and all adjacent non-list lines.
// Listitem: consumes prefixed line and all adjacent non-prefixed lines.
line_li: ($) => prec.right(1, seq(
optional(token.immediate('<')), // Treat codeblock-terminating "<" as whitespace.
_li_token,
Expand All @@ -136,8 +134,9 @@ module.exports = grammar({

// "Column heading": plaintext followed by "~".
// Intended for table column names per `:help help-writing`.
// TODO: children should be $.word (plaintext), not $.atom.
column_heading: ($) => seq(
field('name', seq(choice($._atom_noli, $._uppercase_words), repeat($._atom))), // TODO: should be $.word (plaintext).
field('name', seq(choice($._atom_noli, $._uppercase_words), repeat($._atom))),
choice(
token.immediate(/~[\t ]*\n/),
/~[\t ]*\n/,
Expand Down

0 comments on commit 33afae9

Please sign in to comment.