fix: normalize docs mintlify components

This commit is contained in:
Peter Steinberger
2026-04-28 07:52:17 +01:00
parent fb40ed99a7
commit 8831d2cf0a
2 changed files with 29 additions and 18 deletions

View File

@@ -644,7 +644,7 @@ Write colocated tests in `src/channel.test.ts`:
For shared test helpers, see [Testing](/plugins/sdk-testing).
</Step>
</Step>
</Steps>
## File structure

View File

@@ -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*)<Accordion\b/u);
if (openAccordion) {
accordionStack.push({
indent: openAccordion[1].length,
const openComponent = line.match(/^(\s*)<([A-Z][A-Za-z0-9]*)\b/u);
if (openComponent && MINTLIFY_REPAIRED_COMPONENTS.has(openComponent[2])) {
componentStack.push({
indent: openComponent[1].length,
name: openComponent[2],
});
continue;
}
const closeAccordion = line.match(/^(\s*)<\/Accordion>/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;
},
);