Skip to content

Conversation

@mikkihugo
Copy link

This PR fixes parsing of links with dollar signs in the text or URL.

Fixes #206

Problem

When parsing links with dollar signs, like:

[$NVIM_APPNAME](https://neovim.io/doc/user/starting.html#$NVIM_APPNAME)

The parser incorrectly interpreted $ inside link text as the start of a LaTeX block, preventing the link from being parsed correctly.

Root Cause

The _inline_base grammar rule included $.latex_block, which was used in ALL inline contexts including inside link text (_inline_element_no_link).

Solution

Created a new _inline_base_no_latex rule that excludes LaTeX blocks, and modified the dynamic rule generation to use this variant when generating _inline_element_no_link rules (used inside link text).

Changes:

  • Added _inline_base_no_latex rule without $.latex_block
  • Modified dynamic rule generation (line 401) to use appropriate base rule based on context:
    • Inside links (link=false_no_link suffix): Use _inline_base_no_latex
    • Outside links (link=true): Use _inline_base (with LaTeX)

Testing

✅ All existing tests pass
✅ Links with $ characters now parse correctly as links
✅ LaTeX still works correctly outside of link text

Example

Before: Link not recognized, $NVIM parsed as LaTeX start
After: Entire [$NVIM_APPNAME](...) parsed as a link

Additional Changes

Also upgraded to tree-sitter 0.25 to match latest ABI:

  • Updated Cargo.toml dependencies (0.24 → 0.25)
  • Updated parser.rs API calls (parse_withparse_with_options)
  • Fixed lifetime elision warning in walk() method

This keeps the codebase compatible with the latest tree-sitter ecosystem.

Fixes tree-sitter-grammars#206

## Problem

When parsing links with dollar signs in the text, like:
`[$NVIM_APPNAME](https://example.com/$VAR)`

The parser incorrectly interpreted `$` inside link text as the start of
a LaTeX block, preventing the link from being parsed correctly.

## Root Cause

The `_inline_base` grammar rule included `$.latex_block`, which was used
in ALL inline contexts including inside link text (`_inline_element_no_link`).

## Solution

Created a new `_inline_base_no_latex` rule that excludes LaTeX blocks, and
modified the dynamic rule generation to use this variant when generating
`_inline_element_no_link` rules (used inside link text).

**Changes:**
- Added `_inline_base_no_latex` rule without `$.latex_block`
- Modified line 401 to use appropriate base rule based on context:
  - Inside links (`link=false`): Use `_inline_base_no_latex`
  - Outside links (`link=true`): Use `_inline_base` (with LaTeX)

## Testing

✅ All existing tests pass
✅ Links with `$` characters now parse correctly
✅ LaTeX still works outside of link text

## Additional Changes

Upgraded to tree-sitter 0.25 to match latest ABI (same as tree-sitter-grammars#207):
- Updated Cargo.toml dependencies
- Updated parser.rs API calls

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: dollar sign inside markdown hyperlinks

1 participant