diff --git a/.agents/skills/impeccable/scripts/live-wrap.mjs b/.agents/skills/impeccable/scripts/live-wrap.mjs index 965f6a160..7c585f32d 100644 --- a/.agents/skills/impeccable/scripts/live-wrap.mjs +++ b/.agents/skills/impeccable/scripts/live-wrap.mjs @@ -115,10 +115,12 @@ The agent should insert variant HTML at insertLine.`); const content = fs.readFileSync(targetFile, 'utf-8'); const lines = content.split('\n'); - // Find the element, trying each query in priority order + // Find the element, trying each query in priority order. + // Pass tag hint so findElement can reject matches inside wrong element types + // and walk backward to the real opener on multi-line JSX tags. let match = null; for (const q of queries) { - match = findElement(lines, q); + match = findElement(lines, q, tag); if (match) break; } if (!match) { @@ -128,16 +130,22 @@ The agent should insert variant HTML at insertLine.`); const { startLine, endLine } = match; const commentSyntax = detectCommentSyntax(targetFile); + const isJsx = commentSyntax.open === '{/*'; const indent = lines[startLine].match(/^(\s*)/)[1]; // Extract the original element const originalLines = lines.slice(startLine, endLine + 1); const originalIndented = originalLines.map(l => indent + ' ' + l.trimStart()).join('\n'); + // Wrapper attributes differ by syntax. HTML allows plain string attrs; + // JSX requires object-literal style and parses string attrs as HTML (which + // either type-errors or renders a literal CSS string). + const styleContents = isJsx ? 'style={{ display: "contents" }}' : 'style="display: contents"'; + // Build the wrapper const wrapperLines = [ indent + commentSyntax.open + ' impeccable-variants-start ' + id + ' ' + commentSyntax.close, - indent + '