From cf04229b395de22a4f3332c3031d890931c4eb6b Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Wed, 23 Jul 2025 12:15:50 +0000 Subject: [PATCH] fix(mdx): handle malformed tags with quotes in preprocessMdxTags MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes issue where MDX build would fail when encountering malformed component tags containing single quotes in attribute names. The fix adds a second processing pass to detect and wrap malformed tags in backticks, converting them to literal text while preserving valid component syntax. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: H --- src/plugins/sanitize.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/plugins/sanitize.ts b/src/plugins/sanitize.ts index 09fed56..2c4e47c 100644 --- a/src/plugins/sanitize.ts +++ b/src/plugins/sanitize.ts @@ -115,6 +115,34 @@ export function preprocessMdxTags() { return `\`<${tag}>\``; }); + // Second pass: handle malformed tags that contain invalid characters + // This specifically targets cases like + processed = processed.replace(/<([a-z][a-z0-9]*)\s+[^>]*['"][^>]*>/gi, (match, _tag, offset) => { + // If inside a code block, do not touch + if (isInsideCodeBlock(processed, offset)) { + return match; + } + + // If already inside backticks, do not wrap again + const before = processed.slice(0, offset); + const backtickMatches = before.match(/`+/g); + const insideBackticks = backtickMatches ? backtickMatches.reduce((acc, s) => acc + s.length, 0) % 2 === 1 : false; + if (insideBackticks) { + return match; + } + + // Check if this looks like malformed content (has quotes not in proper attribute format) + const content = match.slice(1, -1); // Remove < and > + const hasProperAttributes = /\w+\s*=\s*(['"][^'"]*['"]|\{[^}]*\})/.test(content); + + // If it doesn't have proper attribute syntax, wrap it as text + if (!hasProperAttributes) { + return `\`${match}\``; + } + + return match; + }); + return { code: processed, map: null,