Skip to content

Add verbose option for positional info of attributes - #20

Closed
chimeyrock999 wants to merge 1 commit into
syntax-tree:mainfrom
chimeyrock999:attribute-positions
Closed

chimeyrock999 wants to merge 1 commit into
syntax-tree:mainfrom
chimeyrock999:attribute-positions

Conversation

@chimeyrock999

Copy link
Copy Markdown
Contributor

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and discussions and couldn’t find anything or linked relevant results below
  • I made sure the docs are up to date
  • I included tests (or that’s not needed)

Description of changes

Closes #19.

Adds an opt-in verbose option to directiveFromMarkdown, mirroring verbose in hast-util-from-parse5.
When on, directives with attributes get data.position.attributes: one DirectiveAttributePosition per attribute, in source order, with:

  • name: the attribute name (id for #a, class for .a)
  • start / end: the whole attribute (#a, .a, a, a=b, a="b")
  • value: the raw value without quotes; empty between the quotes for a=""; not present for a

It is a list rather than a record keyed by name because duplicates are allowed and class values are joined:
every occurrence is included, and for a given name the last one is the one whose value is in attributes (all of them, for class).

attributes itself is unchanged, and without verbose the tree is exactly what it was before.

Notes on the implementation:

  • positions come from the existing name / value / id / class value tokens, plus a new exit handler for directive*AttributeValueLiteral to cover the quotes (and to give empty quoted values a place)
  • the whole-attribute token (directive*Attribute) is not used for start / end, because it includes trailing whitespace for value-less attributes ({a b} gives "a ")
  • the # / . marker and quotes are one character on the same line, so those points are shifted by one instead of tracking the marker tokens

Types (FromMarkdownOptions, DirectiveAttributePosition, DirectiveDataPosition, data.position on the three *DirectiveData interfaces) and the readme are updated.
npm test passes, with 100% coverage.

@github-actions github-actions Bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Oct 22, 2026
@wooorm wooorm closed this in db5cf23 Oct 30, 2026
@wooorm wooorm added the 💪 phase/solved Post is done label Oct 30, 2026
@github-actions

This comment has been minimized.

@github-actions github-actions Bot removed the 🤞 phase/open Post is being triaged manually label Oct 30, 2026
@wooorm

wooorm commented Oct 30, 2026

Copy link
Copy Markdown
Member

thanks, released in 3.2.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💪 phase/solved Post is done

Development

Successfully merging this pull request may close these issues.

Add positional info of attributes

2 participants