Skip to content

Strip generated script tags from MDX output#244

Closed
jpers1 wants to merge 1 commit into
biolab:masterfrom
jpers1:fix-expressive-code-script-tags
Closed

Strip generated script tags from MDX output#244
jpers1 wants to merge 1 commit into
biolab:masterfrom
jpers1:fix-expressive-code-script-tags

Conversation

@jpers1

@jpers1 jpers1 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Strip generated <script> elements from MDX output after rehype-expressive-code runs.

Why

Fenced code blocks are valid supported content in notes, but rehype-expressive-code injects script elements into the generated output. That output is later rendered through React in MdxContent, which triggers a client-side warning because scripts inside rendered React component output are not executed.

This shows up as a runtime warning when serving content with fenced code blocks, even though the author content itself does not contain raw <script> tags.

Changes

  • add a small rehype cleanup step that removes script elements from the generated tree
  • run that cleanup after rehype-expressive-code

Scope

This PR is intentionally narrow:

  • it does not change authoring syntax
  • it does not remove fenced code block support
  • it does not alter unrelated MDX rendering behavior

The goal is to keep the existing code-block rendering while removing the part of the generated output that React/Next warns about.

Validation

  • compiled a fenced code block through the MDX pipeline
  • confirmed the compiled MDX no longer contains a script element in its output

Notes

This is separate from Markdown table support because the issue and fix are unrelated. Tables require parser support; this issue is about generated code-block output from the rehype stage.

@jpers1 jpers1 force-pushed the fix-expressive-code-script-tags branch from 77f507f to 11ac8af Compare June 14, 2026 00:26
@jpers1

jpers1 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

Reviewer note: the script-node cleanup is intentionally after rehype-expressive-code and limited to <script> elements only. The goal is not to change code fence support, only to remove generated script tags that React/Next warns about when the compiled MDX is rendered on the client.

This should not regress copy-button behavior here because the repo already wires copy interactions separately in the client code rather than depending on inline script execution from the MDX output.

@janezd

janezd commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Closed in favour of #248.

@janezd janezd closed this Jun 14, 2026
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.

2 participants