
























@@ -1,9 +1,19 @@
11export const MINTLIFY_ACCORDION_INDENT_MESSAGE =
2-"Accordion closing tag is indented deeper than its opening tag; Mintlify can parse following markdown as nested content.";
2+"Mintlify component closing tag is indented deeper than its opening tag; Mintlify can parse following markdown as nested content.";
334-function visitAccordionIndentation(raw, onMisindentedClose) {
4+const MINTLIFY_REPAIRED_COMPONENTS = new Set([
5+"Accordion",
6+"Warning",
7+"Note",
8+"Tip",
9+"ParamField",
10+"Steps",
11+"Step",
12+]);
13+14+function visitMintlifyComponentIndentation(raw, onMisindentedClose) {
515const lines = raw.split(/\r?\n/u);
6-const accordionStack = [];
16+const componentStack = [];
717let inCodeFence = false;
818919for (let index = 0; index < lines.length; index += 1) {
@@ -16,22 +26,23 @@ function visitAccordionIndentation(raw, onMisindentedClose) {
1626continue;
1727}
182819-const openAccordion = line.match(/^(\s*)<Accordion\b/u);
20-if (openAccordion) {
21-accordionStack.push({
22-indent: openAccordion[1].length,
29+const openComponent = line.match(/^(\s*)<([A-Z][A-Za-z0-9]*)\b/u);
30+if (openComponent && MINTLIFY_REPAIRED_COMPONENTS.has(openComponent[2])) {
31+componentStack.push({
32+indent: openComponent[1].length,
33+name: openComponent[2],
2334});
2435continue;
2536}
263727-const closeAccordion = line.match(/^(\s*)<\/Accordion>/u);
28-if (!closeAccordion) {
38+const closeComponent = line.match(/^(\s*)<\/([A-Z][A-Za-z0-9]*)>/u);
39+if (!closeComponent || !MINTLIFY_REPAIRED_COMPONENTS.has(closeComponent[2])) {
2940continue;
3041}
314232-const opening = accordionStack.pop();
33-if (opening && closeAccordion[1].length > opening.indent) {
34-onMisindentedClose({ closeAccordion, index, line, lines, opening });
43+const opening = componentStack.pop();
44+if (opening?.name === closeComponent[2] && closeComponent[1].length > opening.indent) {
45+onMisindentedClose({ closeComponent, index, line, lines, opening });
3546}
3647}
3748@@ -40,10 +51,10 @@ function visitAccordionIndentation(raw, onMisindentedClose) {
40514152export function checkMintlifyAccordionIndentation(raw) {
4253const errors = [];
43-visitAccordionIndentation(raw, ({ closeAccordion, index }) => {
54+visitMintlifyComponentIndentation(raw, ({ closeComponent, index }) => {
4455errors.push({
4556line: index + 1,
46-column: closeAccordion[1].length + 1,
57+column: closeComponent[1].length + 1,
4758message: MINTLIFY_ACCORDION_INDENT_MESSAGE,
4859});
4960});
@@ -52,10 +63,10 @@ export function checkMintlifyAccordionIndentation(raw) {
52635364export function repairMintlifyAccordionIndentation(raw) {
5465let changed = false;
55-const lines = visitAccordionIndentation(
66+const lines = visitMintlifyComponentIndentation(
5667raw,
57-({ closeAccordion, index, line, lines, opening }) => {
58-lines[index] = `${" ".repeat(opening.indent)}${line.slice(closeAccordion[1].length)}`;
68+({ closeComponent, index, line, lines, opening }) => {
69+lines[index] = `${" ".repeat(opening.indent)}${line.slice(closeComponent[1].length)}`;
5970changed = true;
6071},
6172);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。