Skip to content

Conversation

@mikkihugo
Copy link

@mikkihugo mikkihugo commented Oct 14, 2025

This PR updates the tree-sitter dependency from 0.24 to 0.25, making tree-sitter-md compatible with the latest tree-sitter ecosystem.

Closes #205

Changes

  • Cargo.toml: Update tree-sitter from 0.24 to 0.25
  • bindings/rust/parser.rs:
    • Replace deprecated parse_with() with parse_with_options()
    • Update API signature to match tree-sitter 0.25
    • Fix lifetime elision warning in walk() method

Testing

✅ All existing tests pass with tree-sitter 0.25:

  • can_load_block_grammar
  • can_load_inline_grammar
  • markdown_cursor
  • table
  • inline_ranges
$ cargo test --features parser
running 5 tests
test tests::can_load_block_grammar ... ok
test parser::tests::markdown_cursor ... ok
test tests::can_load_inline_grammar ... ok
test parser::tests::table ... ok
test parser::tests::inline_ranges ... ok

test result: ok. 5 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Breaking Changes

None for library users. The public API remains unchanged. Only internal implementation updated to use newer tree-sitter APIs.

Benefits

  • ✅ Compatible with latest tree-sitter 0.25.x
  • ✅ Resolves version conflicts for projects using tree-sitter 0.25
  • ✅ Future-proof for upcoming tree-sitter features
  • ✅ No deprecation warnings

Motivation

Many Rust projects (including workspaces) are upgrading to tree-sitter 0.25 and cannot use tree-sitter-md due to native library linking conflicts when both 0.24 and 0.25 are present. This update enables them to use the latest versions.

API Migration Details

The main change is in the parse_with_options method signature:

tree-sitter 0.24:

parser.parse_with(callback, old_tree)

tree-sitter 0.25:

parser.parse_with_options(callback, old_tree, None)
// Third parameter is Option<ParseOptions> for progress callbacks

This aligns with tree-sitter's move away from timeout-based cancellation in favor of progress callbacks.

This commit updates the tree-sitter dependency from 0.24 to 0.25,
addressing API changes introduced in the newer version.

## Changes

- **Cargo.toml**: Update tree-sitter dependency from `0.24` to `0.25`
- **bindings/rust/parser.rs**:
  - Replace deprecated `parse_with()` with `parse_with_options()`
  - Update API calls to match tree-sitter 0.25 signature
  - `parse_with_options` now takes 3 args: callback, old_tree, options
  - Fix lifetime elision warning in `walk()` method

## Testing

All existing tests pass with tree-sitter 0.25:
- `can_load_block_grammar`
- `can_load_inline_grammar`
- `markdown_cursor`
- `table`
- `inline_ranges`

## Breaking Changes

None for users of this library. The public API remains unchanged.
Internal implementation updated to use newer tree-sitter APIs.

## Benefits

- Compatible with latest tree-sitter ecosystem
- No more version conflicts for projects using tree-sitter 0.25
- Future-proof for upcoming tree-sitter features
Fixes tree-sitter-grammars#174

## Problem

The `link_destination` node was incorrectly including the angle brackets
`<` and `>` when parsing links like `[text](<https://example.com>)`.

According to the CommonMark spec, angle brackets are delimiters and should
not be part of the link destination itself.

## Solution

Modified the grammar in `common/common.js` to wrap the content inside
angle brackets with an `alias()`, excluding the brackets from the
`link_destination` node range.

**Before:**
```
link_destination [0, 10] - [0, 31]  # Includes < and >
```

**After:**
```
link_destination [0, 11] - [0, 30]  # Excludes < and >
```

## Changes

- `common/common.js`: Wrapped repeated content in `alias()` for angle bracket case
- Regenerated parsers with `tree-sitter generate`

## Testing

✅ All existing tests pass
✅ Parser correctly excludes angle brackets from link destination range

Co-authored-by: Claude <[email protected]>
@mikkihugo
Copy link
Author

I've also added a fix for #174 to this PR!

Additional Fix: Exclude Angle Brackets from link_destination

The link_destination node was incorrectly including angle brackets when parsing links like [text](<https://example.com>).

Fix: Modified grammar to exclude < and > delimiters from the link_destination node range, matching CommonMark spec.

Before: link_destination [0, 10] - [0, 31] (includes <>)
After: link_destination [0, 11] - [0, 30] (excludes <>)

All tests still pass! This PR now includes:

mikkihugo added a commit to mikkihugo/tree-sitter-markdown that referenced this pull request Oct 14, 2025
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]>
@cadojo
Copy link

cadojo commented Nov 15, 2025

Thanks for this contribution! What is the status of this PR? I'd love to use this library with the newer version of tree-sitter, and I'm available to help get the PR over the finish line if that would be useful!

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.

feature: upgrade to tree-sitter 0.25

2 participants