@mintlify/common 1.0.1258 → 1.0.1260
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/plugins/rehype/rehypeDynamicTailwindCss.js +871 -58
- package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.d.ts +1 -0
- package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.js +1 -1
- package/dist/mdx/server-only/getMdx/getReferencedSnippetPaths.d.ts +1 -0
- package/dist/mdx/server-only/getMdx/getReferencedSnippetPaths.js +29 -0
- package/dist/mdx/server-only/getMdx/snippets.d.ts +1 -0
- package/dist/mdx/server-only/getMdx/snippets.js +49 -0
- package/dist/mdx/server-only/getMdx.js +9 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -3,5 +3,6 @@ import type { MdxjsEsm } from 'mdast-util-mdx';
|
|
|
3
3
|
import { Node, Parent } from 'unist';
|
|
4
4
|
import { VFile } from 'vfile';
|
|
5
5
|
export declare const injectedSnippetFile: (node: MdxjsEsm) => string | undefined;
|
|
6
|
+
export declare const snippetFileOf: (node: Node) => string | undefined;
|
|
6
7
|
export declare const findSnippetCycle: (tree: Node, snippetTreeMap: Record<string, Root>) => string[] | undefined;
|
|
7
8
|
export declare const remarkMdxInjectSnippets: (snippetTreeMap: Record<string, Root>) => (tree: Parent, file: VFile) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getReferencedSnippetPaths(content: string): string[];
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const SNIPPET_TAG = /<Snippet\s/g;
|
|
2
|
+
const FILE_ATTR = /\bfile\s*=\s*["']([^"']+)["']/g;
|
|
3
|
+
const SEARCH_WINDOW = 1000;
|
|
4
|
+
export function getReferencedSnippetPaths(content) {
|
|
5
|
+
var _a;
|
|
6
|
+
if (!content.includes('<Snippet'))
|
|
7
|
+
return [];
|
|
8
|
+
const tagStarts = [...content.matchAll(SNIPPET_TAG)].map((tag) => tag.index);
|
|
9
|
+
if (tagStarts.length === 0)
|
|
10
|
+
return [];
|
|
11
|
+
const paths = new Set();
|
|
12
|
+
let nearest = 0;
|
|
13
|
+
for (const attr of content.matchAll(FILE_ATTR)) {
|
|
14
|
+
while (nearest + 1 < tagStarts.length && ((_a = tagStarts[nearest + 1]) !== null && _a !== void 0 ? _a : 0) <= attr.index)
|
|
15
|
+
nearest++;
|
|
16
|
+
const start = tagStarts[nearest];
|
|
17
|
+
if (start === undefined || start > attr.index)
|
|
18
|
+
continue;
|
|
19
|
+
if (attr.index - start > SEARCH_WINDOW)
|
|
20
|
+
continue;
|
|
21
|
+
const path = attr[1];
|
|
22
|
+
if (path === undefined)
|
|
23
|
+
continue;
|
|
24
|
+
paths.add(path);
|
|
25
|
+
if (path.startsWith('/'))
|
|
26
|
+
paths.add(path.slice(1));
|
|
27
|
+
}
|
|
28
|
+
return [...paths];
|
|
29
|
+
}
|
|
@@ -3,4 +3,5 @@ export type Snippet = {
|
|
|
3
3
|
snippetFileLocation: string;
|
|
4
4
|
content: string;
|
|
5
5
|
};
|
|
6
|
+
export declare function collectReferencedSnippets(content: string, snippets: Snippet[]): string[];
|
|
6
7
|
export declare function createSnippetTreeMap(snippets: Snippet[]): Promise<Record<string, Root>>;
|
|
@@ -12,7 +12,56 @@ import { gfmFromMarkdown } from 'mdast-util-gfm';
|
|
|
12
12
|
import { mdxFromMarkdown } from 'mdast-util-mdx';
|
|
13
13
|
import { gfm } from 'micromark-extension-gfm';
|
|
14
14
|
import { mdxjs } from 'micromark-extension-mdxjs';
|
|
15
|
+
import { visit } from 'unist-util-visit';
|
|
15
16
|
import { coreRemark, remarkMdxInjectSnippets } from '../../../index.js';
|
|
17
|
+
import { snippetFileOf } from '../../plugins/remark/remarkMdxInjectSnippets.js';
|
|
18
|
+
import { getReferencedSnippetPaths } from './getReferencedSnippetPaths.js';
|
|
19
|
+
export function collectReferencedSnippets(content, snippets) {
|
|
20
|
+
const byLocation = new Map(snippets.map((snippet) => [snippet.snippetFileLocation, snippet.content]));
|
|
21
|
+
const seen = new Set();
|
|
22
|
+
const referenced = [];
|
|
23
|
+
const pending = [content];
|
|
24
|
+
let current = pending.pop();
|
|
25
|
+
while (current !== undefined) {
|
|
26
|
+
const locations = current.includes('<Snippet') ? findSnippetReferences(current) : [];
|
|
27
|
+
for (const location of locations) {
|
|
28
|
+
if (seen.has(location))
|
|
29
|
+
continue;
|
|
30
|
+
seen.add(location);
|
|
31
|
+
const snippet = byLocation.get(location);
|
|
32
|
+
if (snippet !== undefined) {
|
|
33
|
+
referenced.push(snippet);
|
|
34
|
+
pending.push(snippet);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
current = pending.pop();
|
|
38
|
+
}
|
|
39
|
+
return referenced;
|
|
40
|
+
}
|
|
41
|
+
function findSnippetReferences(content) {
|
|
42
|
+
let tree;
|
|
43
|
+
try {
|
|
44
|
+
tree = parseSnippetTree(content);
|
|
45
|
+
}
|
|
46
|
+
catch (_a) {
|
|
47
|
+
return getReferencedSnippetPaths(content);
|
|
48
|
+
}
|
|
49
|
+
const references = [];
|
|
50
|
+
visit(tree, (node) => {
|
|
51
|
+
var _a;
|
|
52
|
+
const file = node.type === 'mdxJsxTextElement' && node.name === 'Snippet'
|
|
53
|
+
? (_a = node.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'file')) === null || _a === void 0 ? void 0 : _a.value
|
|
54
|
+
: snippetFileOf(node);
|
|
55
|
+
if (typeof file === 'string') {
|
|
56
|
+
references.push(file);
|
|
57
|
+
}
|
|
58
|
+
else if ((node.type === 'mdxFlowExpression' || node.type === 'mdxTextExpression') &&
|
|
59
|
+
node.value.includes('<Snippet')) {
|
|
60
|
+
references.push(...getReferencedSnippetPaths(node.value));
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
return references;
|
|
64
|
+
}
|
|
16
65
|
export function createSnippetTreeMap(snippets) {
|
|
17
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
18
67
|
var _a;
|
|
@@ -17,7 +17,7 @@ import { PackageIslandsError, parsePackageIslands, preprocessPageContent, } from
|
|
|
17
17
|
import { preprocessCustomHeadingIds } from '../preprocessCustomHeadingIds.js';
|
|
18
18
|
import { preprocessMdxFragmentCode } from '../preprocessMdxFragmentCode.js';
|
|
19
19
|
import { replaceVariables } from '../replaceVariables.js';
|
|
20
|
-
import { createSnippetTreeMap } from './getMdx/snippets.js';
|
|
20
|
+
import { collectReferencedSnippets, createSnippetTreeMap, } from './getMdx/snippets.js';
|
|
21
21
|
import { getSerializeExtras } from './getSerializeExtras.js';
|
|
22
22
|
const getPackageIslandOptions = (packageBuild, pagePath, processedContent) => {
|
|
23
23
|
const buildBaseUrl = packageBuildBaseUrl(packageBuild.buildId);
|
|
@@ -54,7 +54,14 @@ export function getMdx(_a) {
|
|
|
54
54
|
if (!tailwindSelectors) {
|
|
55
55
|
const hasClasses = [processedContent, ...processedSnippets.map(({ content }) => content)].some(hasClassAttribute);
|
|
56
56
|
tailwindSelectors = hasClasses
|
|
57
|
-
? yield traceFn('getMdx.getTailwindSelectors', () => __awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
? yield traceFn('getMdx.getTailwindSelectors', () => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
return getTailwindSelectors({
|
|
59
|
+
content: [
|
|
60
|
+
processedContent,
|
|
61
|
+
...collectReferencedSnippets(processedContent, processedSnippets),
|
|
62
|
+
].join('\n'),
|
|
63
|
+
});
|
|
64
|
+
}))
|
|
58
65
|
: [];
|
|
59
66
|
}
|
|
60
67
|
const snippetTreeMap = yield traceFn('getMdx.createSnippetTreeMap', () => __awaiter(this, void 0, void 0, function* () { return createSnippetTreeMap(processedSnippets); }));
|