From 8831d2cf0aae8e34c75229831bcb33b31003bd0c Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 28 Apr 2026 07:52:17 +0100 Subject: [PATCH] fix: normalize docs mintlify components --- docs/plugins/sdk-channel-plugins.md | 2 +- scripts/lib/mintlify-accordion.mjs | 45 ++++++++++++++++++----------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/docs/plugins/sdk-channel-plugins.md b/docs/plugins/sdk-channel-plugins.md index 16507e8fbc1..2f823ae268b 100644 --- a/docs/plugins/sdk-channel-plugins.md +++ b/docs/plugins/sdk-channel-plugins.md @@ -644,7 +644,7 @@ Write colocated tests in `src/channel.test.ts`: For shared test helpers, see [Testing](/plugins/sdk-testing). - + ## File structure diff --git a/scripts/lib/mintlify-accordion.mjs b/scripts/lib/mintlify-accordion.mjs index eee309a04bd..ee99e177fa0 100644 --- a/scripts/lib/mintlify-accordion.mjs +++ b/scripts/lib/mintlify-accordion.mjs @@ -1,9 +1,19 @@ export const MINTLIFY_ACCORDION_INDENT_MESSAGE = - "Accordion closing tag is indented deeper than its opening tag; Mintlify can parse following markdown as nested content."; + "Mintlify component closing tag is indented deeper than its opening tag; Mintlify can parse following markdown as nested content."; -function visitAccordionIndentation(raw, onMisindentedClose) { +const MINTLIFY_REPAIRED_COMPONENTS = new Set([ + "Accordion", + "Warning", + "Note", + "Tip", + "ParamField", + "Steps", + "Step", +]); + +function visitMintlifyComponentIndentation(raw, onMisindentedClose) { const lines = raw.split(/\r?\n/u); - const accordionStack = []; + const componentStack = []; let inCodeFence = false; for (let index = 0; index < lines.length; index += 1) { @@ -16,22 +26,23 @@ function visitAccordionIndentation(raw, onMisindentedClose) { continue; } - const openAccordion = line.match(/^(\s*)/u); - if (!closeAccordion) { + const closeComponent = line.match(/^(\s*)<\/([A-Z][A-Za-z0-9]*)>/u); + if (!closeComponent || !MINTLIFY_REPAIRED_COMPONENTS.has(closeComponent[2])) { continue; } - const opening = accordionStack.pop(); - if (opening && closeAccordion[1].length > opening.indent) { - onMisindentedClose({ closeAccordion, index, line, lines, opening }); + const opening = componentStack.pop(); + if (opening?.name === closeComponent[2] && closeComponent[1].length > opening.indent) { + onMisindentedClose({ closeComponent, index, line, lines, opening }); } } @@ -40,10 +51,10 @@ function visitAccordionIndentation(raw, onMisindentedClose) { export function checkMintlifyAccordionIndentation(raw) { const errors = []; - visitAccordionIndentation(raw, ({ closeAccordion, index }) => { + visitMintlifyComponentIndentation(raw, ({ closeComponent, index }) => { errors.push({ line: index + 1, - column: closeAccordion[1].length + 1, + column: closeComponent[1].length + 1, message: MINTLIFY_ACCORDION_INDENT_MESSAGE, }); }); @@ -52,10 +63,10 @@ export function checkMintlifyAccordionIndentation(raw) { export function repairMintlifyAccordionIndentation(raw) { let changed = false; - const lines = visitAccordionIndentation( + const lines = visitMintlifyComponentIndentation( raw, - ({ closeAccordion, index, line, lines, opening }) => { - lines[index] = `${" ".repeat(opening.indent)}${line.slice(closeAccordion[1].length)}`; + ({ closeComponent, index, line, lines, opening }) => { + lines[index] = `${" ".repeat(opening.indent)}${line.slice(closeComponent[1].length)}`; changed = true; }, );