@mintlify/common 1.0.721 → 1.0.722
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/getMDXOptions.js +2 -1
- package/dist/mdx/plugins/remark/index.d.ts +1 -0
- package/dist/mdx/plugins/remark/index.js +1 -0
- package/dist/mdx/plugins/remark/remarkExtractTableOfContents.js +7 -1
- package/dist/mdx/plugins/remark/remarkMdxRemoveJs.js +14 -4
- package/dist/mdx/plugins/remark/remarkPrompt.d.ts +3 -0
- package/dist/mdx/plugins/remark/remarkPrompt.js +89 -0
- package/dist/mdx/utils.js +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeKeyboardSymbols, rehypeListItemText, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeTable, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames, remarkComponentIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, remarkMdxExtractPanel, remarkVideo, remarkExtractMultiView, } from './plugins/index.js';
|
|
1
|
+
import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeKeyboardSymbols, rehypeListItemText, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeTable, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames, remarkComponentIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, remarkMdxExtractPanel, remarkVideo, remarkExtractMultiView, remarkPrompt, } from './plugins/index.js';
|
|
2
2
|
import { remarkMdxRemoveUnknownJsx } from './plugins/remark/remarkMdxRemoveUnknownJsx/index.js';
|
|
3
3
|
import { remarkMermaid } from './plugins/remark/remarkMermaid.js';
|
|
4
4
|
// avoid running extractors unnecessarily
|
|
@@ -14,6 +14,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
|
|
|
14
14
|
return {
|
|
15
15
|
remarkPlugins: [
|
|
16
16
|
[remarkMdxInjectSnippets, data.snippetTreeMap],
|
|
17
|
+
remarkPrompt,
|
|
17
18
|
[remarkComponentIds, data.pageMetadata],
|
|
18
19
|
[remarkExtractTableOfContents, mdxExtracts, data.pageMetadata], // modifies tree so cannot be excluded
|
|
19
20
|
[remarkExtractChangelogFilters, mdxExtracts],
|
|
@@ -4,7 +4,13 @@ import { slugify } from '../../../slugify.js';
|
|
|
4
4
|
import { createMdxJsxAttribute, getTableOfContentsTitle } from '../../lib/remark-utils.js';
|
|
5
5
|
import { AVOIDED_PAGE_MODES, HEADING_LEVELS } from './remarkComponentIds.js';
|
|
6
6
|
const HEADING_NAMES = ['h1', 'h2', 'h3', 'h4'];
|
|
7
|
-
const COMPONENTS_TO_EXCLUDE_HEADINGS = [
|
|
7
|
+
const COMPONENTS_TO_EXCLUDE_HEADINGS = [
|
|
8
|
+
'Accordion',
|
|
9
|
+
'AccordionGroup',
|
|
10
|
+
'Expandable',
|
|
11
|
+
'Update',
|
|
12
|
+
'Prompt',
|
|
13
|
+
];
|
|
8
14
|
function getStringAttribute(attributes, name) {
|
|
9
15
|
const attr = attributes.find((a) => 'name' in a && a.name === name);
|
|
10
16
|
if (attr && 'value' in attr && typeof attr.value === 'string') {
|
|
@@ -261,6 +261,14 @@ function isFunction(estree) {
|
|
|
261
261
|
});
|
|
262
262
|
return hasFunctionDeclaration;
|
|
263
263
|
}
|
|
264
|
+
function isArrayOfStringLiterals(estree) {
|
|
265
|
+
const stmt = estree.body[0];
|
|
266
|
+
if (estree.body.length !== 1 || (stmt === null || stmt === void 0 ? void 0 : stmt.type) !== 'ExpressionStatement')
|
|
267
|
+
return false;
|
|
268
|
+
if (stmt.expression.type !== 'ArrayExpression')
|
|
269
|
+
return false;
|
|
270
|
+
return stmt.expression.elements.every((el) => (el === null || el === void 0 ? void 0 : el.type) === 'Literal' && typeof el.value === 'string');
|
|
271
|
+
}
|
|
264
272
|
export function remarkMdxRemoveJs() {
|
|
265
273
|
return (tree) => {
|
|
266
274
|
remove(tree, ['mdxTextExpression', 'mdxFlowExpression']);
|
|
@@ -278,7 +286,7 @@ export function remarkMdxRemoveJs() {
|
|
|
278
286
|
if (!('attributes' in node))
|
|
279
287
|
return CONTINUE;
|
|
280
288
|
const newAttributes = node.attributes.map((attr) => {
|
|
281
|
-
var _a, _b, _c, _d, _e;
|
|
289
|
+
var _a, _b, _c, _d, _e, _f;
|
|
282
290
|
if (attr.type === 'mdxJsxAttribute' && !(attr.value instanceof Object))
|
|
283
291
|
return attr;
|
|
284
292
|
if (typeof attr.value === 'string' && isStringSafe(attr.value))
|
|
@@ -286,7 +294,9 @@ export function remarkMdxRemoveJs() {
|
|
|
286
294
|
if (attr.type === 'mdxJsxAttribute' && attr.value instanceof Object) {
|
|
287
295
|
if (isStringSafe(attr.value.value))
|
|
288
296
|
return attr;
|
|
289
|
-
if (
|
|
297
|
+
if (((_a = attr.value.data) === null || _a === void 0 ? void 0 : _a.estree) && isArrayOfStringLiterals(attr.value.data.estree))
|
|
298
|
+
return attr;
|
|
299
|
+
if (attr.name === 'style' && ((_b = attr.value.data) === null || _b === void 0 ? void 0 : _b.estree)) {
|
|
290
300
|
const filteredEstree = filterStyleProperties(attr.value.data.estree);
|
|
291
301
|
if (filteredEstree) {
|
|
292
302
|
const stmt = filteredEstree.body[0];
|
|
@@ -300,9 +310,9 @@ export function remarkMdxRemoveJs() {
|
|
|
300
310
|
return undefined;
|
|
301
311
|
}
|
|
302
312
|
if (Object.keys(DEFAULT_PROP_EXPRESSIONS).includes(attr.name)) {
|
|
303
|
-
attr.value.value = (
|
|
313
|
+
attr.value.value = (_d = (_c = DEFAULT_PROP_EXPRESSIONS[attr.name]) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : '{}';
|
|
304
314
|
attr.value.data = {
|
|
305
|
-
estree: (
|
|
315
|
+
estree: (_f = (_e = DEFAULT_PROP_EXPRESSIONS[attr.name]) === null || _e === void 0 ? void 0 : _e.estree) !== null && _f !== void 0 ? _f : objectEstree,
|
|
306
316
|
};
|
|
307
317
|
return attr;
|
|
308
318
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
const dedent = (text) => {
|
|
3
|
+
const lines = text.split('\n');
|
|
4
|
+
const indents = lines
|
|
5
|
+
.filter((line) => line.trim().length > 0)
|
|
6
|
+
.map((line) => { var _a, _b, _c; return (_c = (_b = (_a = line.match(/^(\s*)/)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0; });
|
|
7
|
+
const minIndent = indents.length > 0 ? Math.min(...indents) : 0;
|
|
8
|
+
if (minIndent === 0)
|
|
9
|
+
return text;
|
|
10
|
+
return lines.map((line) => line.slice(minIndent)).join('\n');
|
|
11
|
+
};
|
|
12
|
+
export const remarkPrompt = () => {
|
|
13
|
+
return (tree, file) => {
|
|
14
|
+
const source = String(file.value);
|
|
15
|
+
visit(tree, 'mdxJsxFlowElement', (node) => {
|
|
16
|
+
if (node.name !== 'Prompt')
|
|
17
|
+
return;
|
|
18
|
+
if (!node.position)
|
|
19
|
+
return;
|
|
20
|
+
if (node.children.length === 0)
|
|
21
|
+
return;
|
|
22
|
+
const startOffset = node.position.start.offset;
|
|
23
|
+
const endOffset = node.position.end.offset;
|
|
24
|
+
if (startOffset === undefined || endOffset === undefined)
|
|
25
|
+
return;
|
|
26
|
+
const nodeSource = source.slice(startOffset, endOffset);
|
|
27
|
+
let inString = false;
|
|
28
|
+
let braceDepth = 0;
|
|
29
|
+
let openTagEnd = -1;
|
|
30
|
+
for (let i = 1; i < nodeSource.length; i++) {
|
|
31
|
+
const ch = nodeSource[i];
|
|
32
|
+
if (inString) {
|
|
33
|
+
if (ch === inString && nodeSource[i - 1] !== '\\')
|
|
34
|
+
inString = false;
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (ch === '"' || ch === "'") {
|
|
38
|
+
inString = ch;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (ch === '{') {
|
|
42
|
+
braceDepth++;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
if (ch === '}') {
|
|
46
|
+
braceDepth--;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (ch === '>' && braceDepth === 0) {
|
|
50
|
+
openTagEnd = i + 1;
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
if (openTagEnd === -1)
|
|
55
|
+
return;
|
|
56
|
+
const closingTagMatch = nodeSource.match(/<\/\s*Prompt\s*>$/);
|
|
57
|
+
if (!closingTagMatch)
|
|
58
|
+
return;
|
|
59
|
+
const closeTagStart = nodeSource.length - closingTagMatch[0].length;
|
|
60
|
+
const rawContent = nodeSource.slice(openTagEnd, closeTagStart);
|
|
61
|
+
const trimmedContent = dedent(rawContent.replace(/^\n/, '').replace(/\n$/, ''));
|
|
62
|
+
node.attributes.push({
|
|
63
|
+
type: 'mdxJsxAttribute',
|
|
64
|
+
name: 'children',
|
|
65
|
+
value: {
|
|
66
|
+
type: 'mdxJsxAttributeValueExpression',
|
|
67
|
+
value: JSON.stringify(trimmedContent),
|
|
68
|
+
data: {
|
|
69
|
+
estree: {
|
|
70
|
+
type: 'Program',
|
|
71
|
+
sourceType: 'module',
|
|
72
|
+
body: [
|
|
73
|
+
{
|
|
74
|
+
type: 'ExpressionStatement',
|
|
75
|
+
expression: {
|
|
76
|
+
type: 'Literal',
|
|
77
|
+
value: trimmedContent,
|
|
78
|
+
raw: JSON.stringify(trimmedContent),
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
node.children = [];
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
};
|