feat: block-level attributes and single-child block component fold#150
Open
farnabaz wants to merge 1 commit into
Open
feat: block-level attributes and single-child block component fold#150farnabaz wants to merge 1 commit into
farnabaz wants to merge 1 commit into
Conversation
…nents
Attach a trailing `{attr}` to the nearest block element (paragraphs,
headings, list items and blockquote paragraphs), and fold
`::ul`/`::ol`/`::table`/`::blockquote` wrapping a single same-tagged child
into that element so the wrapper's attributes land on the actual node.
Closes #122
commit: |
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.
Summary
Two related improvements to block-level attribute handling.
1. Attach a trailing
{attr}to the nearest block element. A{attr="value"}at the end of a line now attaches to the enclosing block — paragraphs, headings (h1–h6), bullet/ordered/task list items, and blockquote paragraphs:A paragraph {style="color: red"} ## Sample Markdown Title {#id} - a list item {.highlight} - [x] a task {data-done} > A note {.note}The attributes only lift to the block when they sit at the very end of the line, so
A {x} paragraphstays literal and**bold**{.x}keeps targeting the<strong>. List-item attributes attach to thelistItem, not its inner paragraph. Auto-unwrap lifts an unwrapped paragraph's attributes onto its container (container wins).2. Fold
::ul/::ol/::table/::blockquoteinto their single same-tag child. These elements have no native trailing-attribute syntax, so the matching block component is now a first-class way to attach attributes to them. When the wrapper contains exactly one same-tagged child, it folds into that element and applies its attributes directly (outer attrs win), instead of producing a nested duplicate:parses to a
listcarrying{.menu}and round-trips back to the::ul{…}form. Same for::ol,::table, and multi-paragraph::blockquote; single-content blockquotes round-trip to the natural> text {attr}form.Implementation spans the attribute tokenizer (accept trailing
{after text),from-markdown(block attachment, unwrap lift, AST fold), andto-markdown(suffix + wrapper serialization, composing with gfm'stable/listItemserializers rather than clobbering them).Closes #122