Skip to content

fix(core/markdown): skip entity unescaping for data-include content - #5288

Draft
marcoscaceres wants to merge 3 commits into
mainfrom
fix/4096-markdown-entity-escape
Draft

fix(core/markdown): skip entity unescaping for data-include content#5288
marcoscaceres wants to merge 3 commits into
mainfrom
fix/4096-markdown-entity-escape

Conversation

@marcoscaceres

@marcoscaceres marcoscaceres commented May 9, 2026

Copy link
Copy Markdown
Contributor

Partially addresses #4096

Skip the &/> entity replacement in markdownToHtml when the
text comes from a raw fetch (data-include) rather than innerHTML.

Written with AI: this change was generated by Claude. Per AI_POLICY.md.

markdownToHtml() unconditionally replaced & with & and > with >,
assuming input always comes from innerHTML (where the browser
re-serializes entities). For data-include fetched text, this caused
double-escaping: authors had to write & to get & in output.

Add a fromHTML option (default true for backward compat) that skips
the replacement when the text comes from a raw fetch.

Partially addresses #4096
@marcoscaceres marcoscaceres added the AI Contains AI-generated logic; see AI_POLICY.md label Aug 5, 2026
Comment thread src/core/markdown.js
.replace(gtEntity, ">")
.replace(ampEntity, "&");
// When text comes from a raw fetch (data-include), skip this step.
const potentialMarkdown =

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot can you add a test?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test in tests/spec/core/data-include-spec.js (commit test(core/data-include): add test for entity unescape fix in raw markdown).

The test covers the regression case: &gt; in raw data-include markdown must not be converted to > (which would incorrectly produce a blockquote). It also verifies that a literal > in raw content still correctly becomes a <blockquote> element.

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

Labels

AI Contains AI-generated logic; see AI_POLICY.md

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants