@mintlify/common 1.0.1244 → 1.0.1246
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.
- package/dist/mdx/lib/index.d.ts +1 -0
- package/dist/mdx/lib/index.js +1 -0
- package/dist/mdx/lib/node-text.d.ts +9 -0
- package/dist/mdx/lib/node-text.js +14 -0
- package/dist/mdx/plugins/rehype/rehypeTable.js +2 -13
- package/dist/mdx/plugins/remark/remarkFileTree.js +3 -8
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +5 -5
package/dist/mdx/lib/index.d.ts
CHANGED
package/dist/mdx/lib/index.js
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ElementContent } from 'hast';
|
|
2
|
+
type ValueTree = {
|
|
3
|
+
type: string;
|
|
4
|
+
value?: unknown;
|
|
5
|
+
children?: readonly ValueTree[];
|
|
6
|
+
};
|
|
7
|
+
export declare const mdastToText: (node: ValueTree) => string;
|
|
8
|
+
export declare const hastToText: (node: ElementContent) => string;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const mdastToText = (node) => {
|
|
2
|
+
if (typeof node.value === 'string')
|
|
3
|
+
return node.value;
|
|
4
|
+
if (!node.children)
|
|
5
|
+
return '';
|
|
6
|
+
return node.children.map(mdastToText).join('');
|
|
7
|
+
};
|
|
8
|
+
export const hastToText = (node) => {
|
|
9
|
+
if (node.type === 'text')
|
|
10
|
+
return node.value;
|
|
11
|
+
if (node.type === 'element')
|
|
12
|
+
return node.children.map(hastToText).join('');
|
|
13
|
+
return '';
|
|
14
|
+
};
|
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
import { u } from 'unist-builder';
|
|
2
2
|
import { visit } from 'unist-util-visit';
|
|
3
|
+
import { hastToText } from '../../lib/node-text.js';
|
|
3
4
|
import { createMdxJsxAttribute } from '../../lib/remark-utils.js';
|
|
4
|
-
const extractTextContent = (node) => {
|
|
5
|
-
let text = '';
|
|
6
|
-
for (const child of node.children) {
|
|
7
|
-
if (child.type === 'text') {
|
|
8
|
-
text += child.value;
|
|
9
|
-
}
|
|
10
|
-
else if (child.type === 'element') {
|
|
11
|
-
text += extractTextContent(child);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return text;
|
|
15
|
-
};
|
|
16
5
|
const PROCESS_NUMERIC_CELLS_THRESHOLD = 0.8;
|
|
17
6
|
const UNITS = '(GiB|MiB|KiB|TiB|PiB|EiB|ZiB|' + // Storage (binary prefixes - IEC)
|
|
18
7
|
'GB|MB|KB|TB|PB|EB|ZB|' + // Storage (decimal prefixes)
|
|
@@ -118,7 +107,7 @@ const isPrimarilyNumeric = (text) => {
|
|
|
118
107
|
const processTableCells = (node) => {
|
|
119
108
|
visit(node, 'element', (cellNode) => {
|
|
120
109
|
if (cellNode.tagName === 'td') {
|
|
121
|
-
const textContent =
|
|
110
|
+
const textContent = hastToText(cellNode);
|
|
122
111
|
if (isPrimarilyNumeric(textContent)) {
|
|
123
112
|
cellNode.properties['data-numeric'] = 'true';
|
|
124
113
|
}
|
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import { visit } from 'unist-util-visit';
|
|
2
|
+
import { mdastToText } from '../../lib/node-text.js';
|
|
2
3
|
const isList = (node) => node.type === 'list';
|
|
3
4
|
const isTreeItemElement = (node) => node.type === 'mdxJsxFlowElement' &&
|
|
4
5
|
'name' in node &&
|
|
5
6
|
(node.name === 'Tree.Folder' ||
|
|
6
7
|
node.name === 'Tree.File');
|
|
7
8
|
const isExpression = (node) => node.type === 'mdxFlowExpression' || node.type === 'mdxTextExpression';
|
|
8
|
-
const getNodeText = (node) => {
|
|
9
|
-
var _a;
|
|
10
|
-
if (typeof node.value === 'string')
|
|
11
|
-
return node.value;
|
|
12
|
-
return ((_a = node.children) !== null && _a !== void 0 ? _a : []).map(getNodeText).join('');
|
|
13
|
-
};
|
|
14
9
|
const describeNode = (node) => {
|
|
15
10
|
if (node.type === 'mdxJsxFlowElement' && 'name' in node && node.name) {
|
|
16
11
|
return `<${String(node.name)}>`;
|
|
17
12
|
}
|
|
18
|
-
const text =
|
|
13
|
+
const text = mdastToText(node).trim().replace(/\s+/g, ' ');
|
|
19
14
|
const preview = text.length > 40 ? `${text.slice(0, 40)}…` : text;
|
|
20
15
|
return preview ? `Text ("${preview}")` : `A ${node.type} node`;
|
|
21
16
|
};
|
|
@@ -23,7 +18,7 @@ const parseListItems = (list) => list.children.map((item) => {
|
|
|
23
18
|
const nestedList = item.children.find(isList);
|
|
24
19
|
const name = item.children
|
|
25
20
|
.filter((child) => !isList(child))
|
|
26
|
-
.map(
|
|
21
|
+
.map(mdastToText)
|
|
27
22
|
.join('')
|
|
28
23
|
.trim();
|
|
29
24
|
return {
|