Skip to content

fix: keep raw text elements out of Markdown parsing - #40

Merged
brendt merged 1 commit into
tempestphp:mainfrom
RobinDev:fix/raw-html-content
Sep 15, 2026
Merged

brendt merged 1 commit into
tempestphp:mainfrom
RobinDev:fix/raw-html-content

Conversation

@RobinDev

Copy link
Copy Markdown
Contributor

Closes part of #37 (point 3).

HtmlToken::parse() re-parses its own content with the inline rules, so the body of a <script> or <style> element was treated as Markdown:

new Markdown(highlighter: null)->parse('<script>const x = "**a**";</script>')->html;
// <script>const x = "<strong>a</strong>";</script>

CommonMark calls these raw text elements — pre, script, style, textarea, §4.6 type 1 — and never parses their content.

HtmlRule now marks those tokens raw (case-insensitively) and HtmlToken::parse() returns their content untouched. Every other element keeps parsing Markdown inside it, which is Tempest's own behaviour and unrelated to #20:

'<div>**a**</div>' // still <div><strong>a</strong></div>

This is the parsing half of point 3. Escaping literal text (a\*b, a_b_c, quotes and entities in text tokens) is the other half and is not in this PR.

composer test (333 tests), lint and analyse are clean.

@github-actions

Copy link
Copy Markdown

Benchmark Results

Comparison of fix/raw-html-content against main (5e06bea775768b2af19579ec592d17d625bac4ef).

Open to see the benchmark results

No benchmark changes above ±5%.

Generated by phpbench against commit 2ce1e2d

@brendt
brendt merged commit 8449b00 into tempestphp:main Sep 15, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants