Skip to content

Fix encoding of ampersands in attribute values - #21

Closed
mkantautas wants to merge 1 commit into
syntax-tree:mainfrom
mkantautas:fix/attribute-character-references
Closed

mkantautas wants to merge 1 commit into
syntax-tree:mainfrom
mkantautas:fix/attribute-character-references

Conversation

@mkantautas

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

Character references in attribute values are decoded when parsing, but directiveToMarkdown writes & as it is.
So a value that contains text such as & or   changes when the markdown is parsed again:
{title: 'Write   here'} is serialized as title="Write   here", which parses back with a no-break space.
With remark and remark-directive, every formatting pass decodes one more level:

::tip{title="Write   to keep two words together"}

becomes title="Write   …" after one pass and a literal no-break space after the next.

This encodes the & of each character reference that would be decoded, as &.
It uses parse-entities with the same settings as the parser, so other ampersands (a & b, ?a=1&b=2, &param) are serialized as before.
That applies to quoted and unquoted values.
The # and . shortcuts are not used for such values, as & cannot be in a shortcut.

@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 23, 2026
wooorm added a commit that referenced this pull request Oct 30, 2026
Related-to: GH-21.

Co-authored-by: Mantas Kantautas <mantas.kantautas@gmail.com>
@wooorm wooorm closed this 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.

2 participants