fix(markdown): exclude headings inside block quotes from the outline - #527
Open
Booyaka101 wants to merge 1 commit into
Open
fix(markdown): exclude headings inside block quotes from the outline#527Booyaka101 wants to merge 1 commit into
Booyaka101 wants to merge 1 commit into
Conversation
Headings written inside a block quote (e.g. `> ## Heading`) parse as atx_heading/setext_heading nodes and were added to the outline, even though they are quoted content rather than document structure. Constrain both heading patterns in queries/markdown/aerial.scm with `(#not-has-ancestor? @Level block_quote)`, so quoted headings are skipped at the query layer. Filtering here rather than in postprocess keeps the parent stack intact, so real headings surrounding a block quote still nest correctly. `has-ancestor?` and the `not-` negation are both available in Neovim 0.11+. Adds a block-quoted section to the markdown treesitter fixture as a regression test. Closes stevearc#526
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #526.
Markdown headings written inside a block quote show up in the outline:
> ## h2 nestedis quoted content, but the markdown grammar still parses it as anatx_heading(nested under ablock_quote), soqueries/markdown/aerial.scmcaptures it and it lands in the outline alongside the real headings.The fix
Add
(#not-has-ancestor? @level block_quote)to both theatx_headingandsetext_headingpatterns, so a heading anywhere inside a block quote is skipped.I did this at the query layer rather than filtering in
M.markdown.postprocesson purpose:get_parentruns (and mutates the heading stack) beforepostprocessgets a chance to drop the item, so dropping there leaves the popped parent behind and real headings around a block quote stop nesting correctly. Excluding at the query layer keeps the stack intact —# Top/> # quoted/## Substill producesTop > Sub.has-ancestor?and thenot-predicate negation are both in core since Neovim 0.11 (aerial's minimum), so this needs no new dependency.Tests
Added a block-quoted section (plus a following
# Title 8) totests/treesitter/markdown_test.mdand refreshed the snapshots. The quoted headings are absent andTitle 8confirms parsing recovers after the quote. Reverting the query change makes the treesitter snapshot fail, so the fixture guards the regression.