From 6e4b78a63c183da70cd233a4623e6e880ed2f9f3 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Wed, 23 Jul 2025 11:24:44 +0000 Subject: [PATCH] fix: handle malformed JSX tags with quotes in invalid positions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes issue where single quotes inside malformed JSX attributes would cause MDX parsing errors. The preprocessMdxTags function now detects and escapes such malformed tags by wrapping them in backticks to treat them as literal text. Example: becomes backtick wrapped text 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: H --- src/plugins/sanitize.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/plugins/sanitize.ts b/src/plugins/sanitize.ts index 09fed56..f55969f 100644 --- a/src/plugins/sanitize.ts +++ b/src/plugins/sanitize.ts @@ -83,6 +83,22 @@ export function preprocessMdxTags() { // Remove leading whitespace from code fence blocks let processed = code.replace(/^(\s+)(```\w*)/gm, '$2'); + // Handle malformed tags with single quotes appearing where attribute names should be + // Very specific pattern: =\s]*?['"][^>=]*?>/gi, (match, _tag, offset) => { + // If inside a code block, do not touch + if (isInsideCodeBlock(processed, offset)) { + return match; + } + // Check if this looks like a malformed attribute (quote not preceded by =) + const beforeQuote = match.match(/<[a-z][a-z0-9]*\s+([^>=]*?)['"][^>=]*?>/i); + if (beforeQuote && beforeQuote[1] && !beforeQuote[1].endsWith('=')) { + // This is malformed - quote appears where it shouldn't + return `\`${match}\``; + } + return match; + }); + // Only replace unrecognized with `""` if NOT inside a code block // This regex finds all occurrences processed = processed.replace(/<([a-z][a-z0-9]*)>/gi, (match, tag, offset) => {