import fs from "fs"; import path from "path"; import { fileURLToPath } from "url"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const contentDir = path.join(__dirname, "..", "content", "resources"); const files = fs.readdirSync(contentDir).filter((f) => f.endsWith(".mdx")); let totalFixed = 0; for (const file of files) { const filePath = path.join(contentDir, file); const raw = fs.readFileSync(filePath, "utf-8"); // Split frontmatter from content const fmMatch = raw.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/); if (!fmMatch) continue; const frontmatter = fmMatch[1]; const content = fmMatch[2]; const lines = content.split("\n"); let insideFencedBlock = false; let changed = false; const result = []; for (let line of lines) { // Toggle fenced code block state if (/^```/.test(line.trimStart())) { insideFencedBlock = !insideFencedBlock; result.push(line); continue; } if (insideFencedBlock) { // Inside fenced code block: unescape HTML entities const newLine = line.replace(/</g, "<").replace(/>/g, ">"); if (newLine !== line) changed = true; result.push(newLine); } else { // Outside fenced block: fix inline code spans const newLine = line.replace(/`[^`]+`/g, (match) => { return match.replace(/</g, "<").replace(/>/g, ">"); }); if (newLine !== line) changed = true; result.push(newLine); } } if (changed) { const output = `---\n${frontmatter}\n---\n${result.join("\n")}`; fs.writeFileSync(filePath, output, "utf-8"); totalFixed++; console.log(`Fixed: ${file}`); } } console.log(`\nDone. Fixed ${totalFixed} files.`);