Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 5, 2023
Merged

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

merged 1 commit into from
Nov 5, 2023

Conversation

hendrikvanantwerpen
Copy link
Contributor

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`

@hendrikvanantwerpen hendrikvanantwerpen changed the title Do not capture whitespace around ATX headings Do not capture whitespace between ATX heading's marker and content Oct 9, 2023
@MDeiml
Copy link
Collaborator

MDeiml commented Nov 5, 2023

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

@MDeiml MDeiml merged commit cd705f1 into tree-sitter-grammars:split_parser Nov 5, 2023
2 checks passed
@hendrikvanantwerpen hendrikvanantwerpen deleted the fix-heading-whitespace branch November 7, 2023 18:19
@hendrikvanantwerpen
Copy link
Contributor Author

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
Copy link

petobens commented Nov 7, 2023

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

@hendrikvanantwerpen
Copy link
Contributor Author

@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
Copy link

petobens commented Nov 8, 2023

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

@MDeiml
Copy link
Collaborator

MDeiml commented Nov 11, 2023

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.

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.

3 participants