From 33afae908c5944e547b697fee9880fa08d7327df Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 4 Oct 2022 21:03:19 +0200 Subject: [PATCH] fix: taglinks |-x| |==| not recognized 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. --- corpus/taglink.txt | 27 +++++++++++++++++++++++++-- grammar.js | 7 +++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/corpus/taglink.txt b/corpus/taglink.txt index 71ef01c..6d363fa 100644 --- a/corpus/taglink.txt +++ b/corpus/taglink.txt @@ -17,6 +17,11 @@ taglink in text ================================================================================ Hello |world| hello +|-+| +[num] line +|-e| -e Ex +|-| - minus + + -------------------------------------------------------------------------------- @@ -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)))) ================================================================================ @@ -78,8 +99,10 @@ Note: ":autocmd" can... (word)) (line (word) - (word) - (word))) + (taglink + (word)) + (taglink + (word)))) (block (line_li (line diff --git a/grammar.js b/grammar.js index c7dee8e..4c86661 100644 --- a/grammar.js +++ b/grammar.js @@ -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. @@ -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, @@ -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/,