@mintlify/common 1.0.322 → 1.0.323

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,3 +8,6 @@ export * from './remarkReplaceAllImages.js';
8
8
  export * from './remarkMermaid.js';
9
9
  export * from './remarkMdxRemoveJs.js';
10
10
  export * from './remarkExtractChangelogFilters.js';
11
+ export * from './remarkExpandContent.js';
12
+ export * from './remarkSplitCodeGroup.js';
13
+ export * from './remarkSplitTabs.js';
@@ -8,3 +8,6 @@ export * from './remarkReplaceAllImages.js';
8
8
  export * from './remarkMermaid.js';
9
9
  export * from './remarkMdxRemoveJs.js';
10
10
  export * from './remarkExtractChangelogFilters.js';
11
+ export * from './remarkExpandContent.js';
12
+ export * from './remarkSplitCodeGroup.js';
13
+ export * from './remarkSplitTabs.js';
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const remarkExpandContent: () => (tree: Root) => void;
@@ -0,0 +1,21 @@
1
+ import { visit } from 'unist-util-visit';
2
+ export const remarkExpandContent = () => (tree) => {
3
+ visit(tree, 'mdxJsxFlowElement', (node) => {
4
+ if (node.name === 'Accordion' || node.name === 'Expandable') {
5
+ const defaultOpenAttr = node.attributes.find(isDefaultOpenAttr);
6
+ if (defaultOpenAttr) {
7
+ defaultOpenAttr.value = 'true';
8
+ }
9
+ else {
10
+ node.attributes.push({
11
+ type: 'mdxJsxAttribute',
12
+ name: 'defaultOpen',
13
+ value: 'true',
14
+ });
15
+ }
16
+ }
17
+ });
18
+ };
19
+ const isDefaultOpenAttr = (attr) => {
20
+ return attr.type === 'mdxJsxAttribute' && attr.name === 'defaultOpen';
21
+ };
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const remarkSplitCodeGroup: () => (tree: Root) => void;
@@ -0,0 +1,19 @@
1
+ import { visit } from 'unist-util-visit';
2
+ export const remarkSplitCodeGroup = () => (tree) => {
3
+ const codeGroupCompoenents = ['CodeGroup', 'RequestExample', 'ResponseExample'];
4
+ const groupsToProcess = [];
5
+ visit(tree, 'mdxJsxFlowElement', (node, index, parent) => {
6
+ if (node.name && codeGroupCompoenents.includes(node.name) && index && parent) {
7
+ groupsToProcess.push({ node, index, parent });
8
+ }
9
+ });
10
+ // Split the code group into multiple CodeBlock nodes
11
+ // basically remove the CodeGroup component and replace it with the codeblocks
12
+ for (const { node, index, parent } of groupsToProcess) {
13
+ const numberOfCodeBlocks = node.children.length;
14
+ if (numberOfCodeBlocks <= 1)
15
+ continue;
16
+ const newNodes = node.children;
17
+ parent.children.splice(index, 1, ...newNodes);
18
+ }
19
+ };
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const remarkSplitTabs: () => (tree: Root) => void;
@@ -0,0 +1,56 @@
1
+ import { visit } from 'unist-util-visit';
2
+ export const remarkSplitTabs = () => (tree) => {
3
+ const tabsToProcess = [];
4
+ visit(tree, 'mdxJsxFlowElement', (node, index, parent) => {
5
+ if (node.name === 'Tabs' && index && parent) {
6
+ tabsToProcess.push({ node, index, parent });
7
+ }
8
+ });
9
+ for (const { node, index, parent } of tabsToProcess) {
10
+ const numberOfTabs = node.children.length;
11
+ if (numberOfTabs <= 1)
12
+ continue;
13
+ const newNodes = [];
14
+ for (let i = 0; i < numberOfTabs; i++) {
15
+ const newNode = structuredClone(node);
16
+ const defaultTabIndexAttr = newNode.attributes.find(isDefaultTabIndexAttr);
17
+ if (defaultTabIndexAttr) {
18
+ defaultTabIndexAttr.value = formValueExpression(i);
19
+ }
20
+ else {
21
+ newNode.attributes.push({
22
+ type: 'mdxJsxAttribute',
23
+ name: 'defaultTabIndex',
24
+ value: formValueExpression(i),
25
+ });
26
+ }
27
+ newNodes.push(newNode);
28
+ }
29
+ parent.children.splice(index, 1, ...newNodes);
30
+ }
31
+ };
32
+ const isDefaultTabIndexAttr = (attr) => {
33
+ return attr.type === 'mdxJsxAttribute' && attr.name === 'defaultTabIndex';
34
+ };
35
+ const formValueExpression = (value) => {
36
+ return {
37
+ type: 'mdxJsxAttributeValueExpression',
38
+ value: value.toString(),
39
+ data: {
40
+ estree: {
41
+ type: 'Program',
42
+ body: [
43
+ {
44
+ type: 'ExpressionStatement',
45
+ expression: {
46
+ type: 'Literal',
47
+ value: value,
48
+ raw: value.toString(),
49
+ },
50
+ },
51
+ ],
52
+ sourceType: 'module',
53
+ },
54
+ },
55
+ };
56
+ };