From f9da326c88b9d6ab6c385a63a0cc98dbb299d618 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 23 Apr 2026 19:20:27 +0100 Subject: [PATCH] fix: repair generated docs accordion indentation --- scripts/docs-sync-publish.mjs | 92 +++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/scripts/docs-sync-publish.mjs b/scripts/docs-sync-publish.mjs index 5a225e8af9a..28267c08afd 100644 --- a/scripts/docs-sync-publish.mjs +++ b/scripts/docs-sync-publish.mjs @@ -167,6 +167,28 @@ function ensureDir(dirPath) { fs.mkdirSync(dirPath, { recursive: true }); } +function walkMarkdownFiles(entryPath, out = []) { + if (!fs.existsSync(entryPath)) { + return out; + } + + const stat = fs.statSync(entryPath); + if (stat.isFile()) { + if (/\.mdx?$/i.test(entryPath)) { + out.push(entryPath); + } + return out; + } + + for (const entry of fs.readdirSync(entryPath, { withFileTypes: true })) { + if (entry.name === "node_modules" || entry.name === ".git") { + continue; + } + walkMarkdownFiles(path.join(entryPath, entry.name), out); + } + return out; +} + function readJson(filePath) { return JSON.parse(fs.readFileSync(filePath, "utf8")); } @@ -262,6 +284,75 @@ function composeDocsConfig() { }; } +function repairMintlifyAccordionIndentation(raw) { + const lines = raw.split(/\r?\n/u); + const accordionStack = []; + let inCodeFence = false; + let changed = false; + + for (let index = 0; index < lines.length; index += 1) { + const line = lines[index]; + if (/^\s*(```|~~~)/u.test(line)) { + inCodeFence = !inCodeFence; + continue; + } + if (inCodeFence) { + continue; + } + + const openAccordion = line.match(/^(\s*)/u); + if (!closeAccordion) { + continue; + } + + const opening = accordionStack.pop(); + if (opening && opening.hasOutdentedListItem && closeAccordion[1].length > opening.indent) { + lines[index] = `${" ".repeat(opening.indent)}${line.slice(closeAccordion[1].length)}`; + changed = true; + } + } + + return changed ? lines.join("\n") : raw; +} + +function repairGeneratedLocaleDocs(targetDocsDir) { + let repaired = 0; + for (const locale of GENERATED_LOCALES) { + const localeDir = path.join(targetDocsDir, locale.dir); + for (const filePath of walkMarkdownFiles(localeDir)) { + const raw = fs.readFileSync(filePath, "utf8"); + const repairedRaw = repairMintlifyAccordionIndentation(raw); + if (repairedRaw === raw) { + continue; + } + fs.writeFileSync(filePath, repairedRaw); + repaired += 1; + } + } + + if (repaired > 0) { + console.log(`Repaired Mintlify accordion indentation in ${repaired} generated locale doc(s).`); + } +} + function syncDocsTree(targetRoot) { const targetDocsDir = path.join(targetRoot, "docs"); ensureDir(targetDocsDir); @@ -298,6 +389,7 @@ function syncDocsTree(targetRoot) { } } + repairGeneratedLocaleDocs(targetDocsDir); writeJson(path.join(targetDocsDir, "docs.json"), composeDocsConfig()); }