Skip to content

Commit 75e952a

Browse files
committed
fix(parsers, markdown_inline, tags): Fixed tag ranges
`range.end_col` is now correctly calculated. Closes #497 fix(parsers, markdown_inline, tags): Do not allow non-space characters before `#` Parity change with Obsidian's tags.
1 parent e3829d3 commit 75e952a

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

lua/markview/parsers/markdown_inline.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,11 @@ end
499499
-- Special cases such as `#1` are not considered tags in **Obsidian**,
500500
-- but the extra matching required isn't worth the effort in my opinion.
501501
local tag_text = lpeg.R("az", "AZ", "09") + lpeg.S("_-");
502-
local tag = lpeg.C(
502+
503+
-- NOTE: Tags in Obsidian can't have non-whitespace text before `#`.
504+
local boundary = -lpeg.B(1) + lpeg.B(lpeg.S(" \t") );
505+
506+
local tag = lpeg.P(boundary) * lpeg.C(
503507
lpeg.Cp() * -- Start byte
504508
lpeg.P("#") * tag_text^1 *
505509
lpeg.Cp() -- End byte
@@ -520,9 +524,10 @@ inline.tag = function (_, _, text, range)
520524
while index < #tags do
521525
local match = tags[index];
522526
local col_start = _col_start + tags[index + 1] - 1;
523-
local col_end = tags[index + 2] - 1;
527+
local col_end = _col_start + tags[index + 2] - 1;
524528

525529
if match and col_start and col_end then
530+
526531
inline.insert({
527532
class = "inline_tag",
528533
label = match:gsub("^#", ""),

0 commit comments

Comments
 (0)