Skip to content

Fix encoding of ampersands in attribute values - #21

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

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

Conversation

@mkantautas

Copy link
Copy Markdown

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤞 phase/open Post is being triaged manually

Development

Successfully merging this pull request may close these issues.

1 participant