Skip to content

Parse multi-line tag openings inside blockquotes - #642

Merged
joelzwarrington merged 3 commits into
markdoc:mainfrom
nsafai:fix-tag-in-blockquote
Sep 16, 2026
Merged

joelzwarrington merged 3 commits into
markdoc:mainfrom
nsafai:fix-tag-in-blockquote

Conversation

@nsafai

@nsafai nsafai commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #641: a tag opening that spans several lines parses everywhere except inside a blockquote, where the > markers of the continuation lines end up inside the tag text and the grammar rejects it.

This isn't just a hand-written edge case. format() wraps any tag opening longer than maxTagOpeningWidth, so a tool that formats on save (Keystatic, for one) turns a long callout inside a quote into an error node on the next parse.

Fix: read the tag's lines through state.getLines, which strips container markers the same way markdown-it's own block rules do. Single-line tags are unaffected. Test added beside the existing multi-line tag tests; it fails on main.

Independent of #640, which fixes the formatter side of the same round trip.

The block rule sliced a tag's text straight out of the raw source, from
the opening on the first line to the closing on a later one. Inside a
blockquote that slice included the "> " markers of the continuation
lines, so the tag grammar rejected it and the tag became an error node.

Read the tag's lines through state.getLines, which returns them with
container markers already stripped, and take what lies between the
opening and closing delimiters.

Fixes #641
@nsafai
nsafai marked this pull request as ready for review September 11, 2026 04:39

@joelzwarrington joelzwarrington left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, changes look good to me, but would love to see a few more test cases that might catch some other issues. Let me know what you think!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind adding a few more test cases here? I'm thinking we might want to test the following scenarios to confirm:

  1. List-item containers work with multi-line tags
- {% test #foo .bar
        baz=1 %}
    This is a test
    {% /test %}
  1. Nested containers with multi-line tags, can do either blockquotes → list item or vice-versa
> - {% test #foo .bar
>     baz=1 %}
>   This is a test
>   {% /test %}
  1. Parsing after a multi-line tag within a blockquote works as expected
> {% test #foo .bar
>   baz=1 %}
> This is a test
> {% /test %}
After the blockquote
  1. A single-line tag inside a blockquote works as expected
> {% test #foo .bar baz=1 %}
> This is a test
> {% /test %}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joelzwarrington good ideas, just added these 4 tests, should be ready for ur review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for adding the tests @nsafai! ❤️

Cover list items, blockquote + list nesting, content following a
blockquote, and single-line tags in a blockquote.
@nsafai

nsafai commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Overall, changes look good to me, but would love to see a few more test cases that might catch some other issues. Let me know what you think!

Thanks for the quick review @joelzwarrington! Since this is approved now, any chance you could merge it, and then cut a patch release that includes both this and #640?

I'm hoping to bump Keystatic's Markdoc dependency to pick up both blockquote fixes, since its editor writes files with format(), and the last published version (0.5.9) predates both.

Happy to help if there's anything else needed to get a release out.

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.

Multi-line tag opening is not parsed inside a blockquote

2 participants