Skip to content

fix(markdown-toolkit): accept parsed values with formatting in template and blockTemplate - #163

Open
Jason3S wants to merge 2 commits into
mainfrom
claude/fix-template-parsed-values-71bd5a
Open

Jason3S wants to merge 2 commits into
mainfrom
claude/fix-template-parsed-values-71bd5a

Conversation

@Jason3S

@Jason3S Jason3S commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Rendering template or blockTemplate could throw an error when a value came from parsed text and had formatting. Those values now work, as they already did in templateDocument and inlineTemplate.

The template's style was read after the values went in, so a value's positions in its own text were looked up in the template's text. The style now comes from the template's own text.

What failed

A value with emphasis, strong text, a list or a rule could fail, depending on which characters of the template its positions landed on. It could come from any of these:

  • parse
  • parseDocument
  • another template
md.template('Hi {@x@}.', { x: md.parse('*a*') }).toString();
// Cannot serialize emphasis with `H` for `options.emphasis`, expected `*`, or `_`
md.template('{@x@}', { x: md.parse('- a') }).toString();
// Cannot serialize items with `{` for `options.bullet`, expected `*`, `+`, or `-`

What else changes

When those characters were valid markers, the value set the template's markers with no error. That output changes:

md.template('**t** {@x@}', { x: md.parse('*a*') }).toString();
// Before: **t** *a*
// Now: **t** _a_
Usage
md.template('Hi {@x@}.', { x: md.parse('*a*') });
// Hi _a_.
md.template('{@x@}', { x: md.parse('- a') });
// - a

…te and blockTemplate

Both functions read the template's style after substituting. A value from
parse, parseDocument or another template keeps positions from its own text,
so its markers were looked up in the template's text. A character such as
`H` was then taken for a marker, and rendering threw.

Read the style before substituting, as documentOf already does, so it comes
from the template's own text.
…s with parsed values

Say why the style is read before substituting, so nobody inlines it back.
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.

1 participant