tree-sitter-grammars / tree-sitter-markdown

Markdown grammar for tree-sitter
MIT License
374 stars 45 forks source link

Do not capture whitespace between ATX heading's marker and content #119

Closed hendrikvanantwerpen closed 8 months ago

hendrikvanantwerpen commented 9 months ago

Problem

The heading_content of ATX headings would include the whitespace between the heading marker and the heading text.

Example

Given an example file

# Top Heading 

Some contents

Executing the query

(section (atx_heading (atx_h1_marker) heading_content: (inline) @heading))

results in

pattern: 0
  capture: 0 - heading, start: (0, 1), end: (0, 13), text: ` Top Heading`

Changes

A new $_atx_heading_content rule allows optional whitespace before the line content that is captured in heading_content.

For the given example, the query now returns

pattern: 0
  capture: 0 - heading, start: (0, 2), end: (0, 13), text: `Top Heading`
MDeiml commented 8 months ago

Looks good and is going to make this node a bit more consistent. Thank you!

hendrikvanantwerpen commented 8 months ago

Thank you @MDeiml! In a related note, would it be possible to release a new version and publish it to crates.io? We're currently depending on the commit, but cargo is much slower with these than with releases, and we also cannot release our own crate if we want.

petobens commented 8 months ago

Hi @hendrikvanantwerpen! is it possible for you to implement a similar fix for #41?

hendrikvanantwerpen commented 8 months ago

@petobens I'm not able to do that at the moment. Perhaps my PR will give you an idea of how to try it?

petobens commented 8 months ago

Would love to but I'm afraid it's beyond my skill set.

MDeiml commented 7 months ago

As mentioned in the issue this change is a lot more complex than the one for ATX heading markers, but the workaround described there should be enough for almost all use cases.