--- import { runHighlighterWithAstro } from '../../node_modules/@astrojs/prism/dist/highlighter.js'; interface Props { code: string; hints: string[]; file?: string; } const { code, hints, file } = Astro.props; const id = `dv-${Math.random().toString(36).substring(2, 9)}`; const originalLines = code.split('\n'); const fileExtension = (file?.split('/').pop() || 'file').split('.').pop() || ''; const langMap: Record = { js: 'javascript', jsx: 'jsx', ts: 'typescript', tsx: 'tsx', html: 'html', css: 'css', json: 'json', py: 'python', rb: 'ruby', java: 'java', c: 'c', cpp: 'cpp', cs: 'csharp', go: 'go', rs: 'rust', php: 'php', swift: 'swift', kt: 'kotlin', sh: 'bash', yaml: 'yaml', yml: 'yaml', md: 'markdown', sql: 'sql', xml: 'xml', dockerfile: 'dockerfile', gitignore: 'bash', astro: 'astro', }; const language = langMap[fileExtension] || undefined; let highlightedLines: string[] = []; if (language) { try { const { html } = runHighlighterWithAstro(language, code); const parsed = html.split('\n'); if (parsed.length > originalLines.length && parsed[parsed.length - 1] === '') { parsed.pop(); } highlightedLines = parsed.length === originalLines.length ? parsed : []; } catch { // Fallback: no highlighting } } const highlightedMap = new Map(); highlightedLines.forEach((hl, i) => { highlightedMap.set(String(i + 1), hl); }); const lineContentMap = new Map(); originalLines.forEach((line, i) => { const lineNum = String(i + 1); lineContentMap.set(lineNum, highlightedMap.get(lineNum) || line); }); ---
{file?.split('/').pop() || 'file'}.{fileExtension} | {originalLines.length} lines
Original (Buggy) Read-only
{originalLines.map((_, index) => { const lineNum = index + 1; const hasHint = hints.some(h => h.includes(`Line ${lineNum}`)); return (
{lineNum}
); })}
{originalLines.map((line, index) => { const lineNum = index + 1; const hasHint = hints.some(h => h.includes(`Line ${lineNum}`)); const hintText = hints.find(h => h.includes(`Line ${lineNum}`)); const content = highlightedMap.get(String(lineNum)) || line || ' '; return (
{hasHint && ( )}
); })}
Your Fix Editable
{originalLines.map((_, index) => (
{index + 1}
))}
{originalLines.map((_, index) => { const lineNum = index + 1; return (
); })}
0 added 0 removed 0 changed
Click lines on the left to mark as buggy