Skip to content

feat: block-level attributes and single-child block component fold#150

Open
farnabaz wants to merge 1 commit into
mainfrom
feat/block-level-attributes
Open

feat: block-level attributes and single-child block component fold#150
farnabaz wants to merge 1 commit into
mainfrom
feat/block-level-attributes

Conversation

@farnabaz

Copy link
Copy Markdown
Collaborator

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} paragraph stays literal and **bold**{.x} keeps targeting the <strong>. List-item attributes attach to the listItem, not its inner paragraph. Auto-unwrap lifts an unwrapped paragraph's attributes onto its container (container wins).

2. Fold ::ul / ::ol / ::table / ::blockquote into 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:

::ul{.menu}
- item 1
- item 2
::

parses to a list carrying {.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), and to-markdown (suffix + wrapper serialization, composing with gfm's table/listItem serializers rather than clobbering them).

Closes #122

…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
@pkg-pr-new

pkg-pr-new Bot commented Jun 12, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/remark-mdc@150

commit: 4a9d49d

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.

Feature: new syntax for heading with custom attributes

1 participant