@mintlify/common 1.0.197 → 1.0.198
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.d.ts +4 -4
- package/dist/mdx/getMDXOptions.js +2 -3
- package/dist/mdx/lib/findExportedNode.d.ts +2 -2
- package/dist/mdx/lib/findExportedNode.js +3 -1
- package/dist/mdx/lib/remark-utils.d.ts +1 -1
- package/dist/mdx/plugins/rehype/index.d.ts +0 -1
- package/dist/mdx/plugins/rehype/index.js +0 -1
- package/dist/mdx/plugins/rehype/rehypeMdxExtractEndpoint/index.d.ts +2 -2
- package/dist/mdx/plugins/rehype/rehypeMdxExtractExamples.d.ts +2 -2
- package/dist/mdx/plugins/rehype/rehypeMdxExtractExamples.js +5 -5
- package/dist/mdx/plugins/rehype/rehypeParamFieldIds.d.ts +2 -2
- package/dist/mdx/plugins/rehype/rehypeParamFieldIds.js +1 -2
- package/dist/mdx/plugins/rehype/rehypeZoomImages.d.ts +2 -2
- package/dist/mdx/plugins/rehype/rehypeZoomImages.js +3 -3
- package/dist/mdx/plugins/remark/index.d.ts +1 -0
- package/dist/mdx/plugins/remark/index.js +1 -0
- package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.d.ts +2 -1
- package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.js +19 -20
- package/dist/mdx/plugins/remark/remarkMdxRemoveJs.d.ts +2 -2
- package/dist/mdx/plugins/remark/remarkMdxRemoveJs.js +0 -1
- package/dist/mdx/plugins/remark/remarkMdxRemoveUnknownJsx/createCommentNode.d.ts +2 -0
- package/dist/mdx/plugins/remark/remarkMdxRemoveUnknownJsx/index.d.ts +2 -0
- package/dist/mdx/plugins/{rehype/rehypeMdxRemoveUnknownJsx → remark/remarkMdxRemoveUnknownJsx}/index.js +1 -2
- package/dist/mdx/plugins/remark/remarkMdxRemoveUnusedVariables.d.ts +2 -2
- package/dist/mdx/plugins/remark/remarkMermaid.d.ts +2 -2
- package/dist/mdx/plugins/remark/remarkMermaid.js +3 -4
- package/dist/mdx/plugins/remark/remarkRemoveImports.d.ts +2 -2
- package/dist/mdx/plugins/remark/remarkRemoveImports.js +2 -6
- package/dist/mdx/plugins/remark/remarkReplaceAllImages.d.ts +2 -11
- package/dist/mdx/plugins/remark/remarkReplaceAllImages.js +16 -17
- package/dist/mdx/remark.d.ts +3 -3
- package/dist/mdx/snippets/findAndRemoveImports.js +1 -3
- package/dist/mdx/snippets/getExportMap.d.ts +1 -1
- package/dist/mdx/snippets/index.d.ts +0 -1
- package/dist/mdx/snippets/index.js +0 -1
- package/dist/mdx/snippets/nodeIncludesExport.d.ts +8 -3
- package/dist/mdx/snippets/nodeIncludesExport.js +4 -11
- package/dist/mdx/utils.d.ts +9 -6
- package/dist/mdx/utils.js +4 -7
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/mdx/index.d.ts +1 -12
- package/package.json +27 -27
- package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/createCommentNode.d.ts +0 -15
- package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/index.d.ts +0 -3
- package/dist/mdx/snippets/mdxMdToHtml/code.d.ts +0 -10
- package/dist/mdx/snippets/mdxMdToHtml/code.js +0 -38
- package/dist/mdx/snippets/mdxMdToHtml/image.d.ts +0 -10
- package/dist/mdx/snippets/mdxMdToHtml/image.js +0 -31
- package/dist/mdx/snippets/mdxMdToHtml/index.d.ts +0 -11
- package/dist/mdx/snippets/mdxMdToHtml/index.js +0 -83
- package/dist/mdx/snippets/mdxMdToHtml/list.d.ts +0 -11
- package/dist/mdx/snippets/mdxMdToHtml/list.js +0 -18
- package/dist/mdx/snippets/mdxMdToHtml/table.d.ts +0 -16
- package/dist/mdx/snippets/mdxMdToHtml/table.js +0 -37
- package/dist/mdx/snippets/mdxMdToHtml/utils.d.ts +0 -10
- package/dist/mdx/snippets/mdxMdToHtml/utils.js +0 -22
- /package/dist/mdx/plugins/{rehype/rehypeMdxRemoveUnknownJsx → remark/remarkMdxRemoveUnknownJsx}/createCommentNode.js +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SerializeOptions } from '@mintlify/mdx';
|
|
2
2
|
import type { MintConfig, PageMetaTags } from '@mintlify/models';
|
|
3
|
-
import type { Root } from '
|
|
4
|
-
import type {
|
|
3
|
+
import type { Root } from 'mdast';
|
|
4
|
+
import type { PluggableList } from 'unified';
|
|
5
5
|
import { MdxExtracts } from '../types/mdx/MdxExtracts.js';
|
|
6
6
|
type MDXOptionsData = {
|
|
7
7
|
snippetTreeMap: Record<string, Root>;
|
|
@@ -12,8 +12,8 @@ type MDXOptionsData = {
|
|
|
12
12
|
};
|
|
13
13
|
export declare const getMDXOptions: ({ data, remarkPlugins, rehypePlugins, mdxExtracts, }: {
|
|
14
14
|
data: MDXOptionsData;
|
|
15
|
-
remarkPlugins?:
|
|
16
|
-
rehypePlugins?:
|
|
15
|
+
remarkPlugins?: PluggableList;
|
|
16
|
+
rehypePlugins?: PluggableList;
|
|
17
17
|
mdxExtracts?: MdxExtracts;
|
|
18
18
|
}) => SerializeOptions["mdxOptions"];
|
|
19
19
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { rehypeCodeBlocks, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeZoomImages, remarkExtractTableOfContents, remarkFrames, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, } from './plugins/index.js';
|
|
2
|
-
import
|
|
2
|
+
import { remarkMdxRemoveUnknownJsx } from './plugins/remark/remarkMdxRemoveUnknownJsx/index.js';
|
|
3
3
|
import { remarkMermaid } from './plugins/remark/remarkMermaid.js';
|
|
4
4
|
// avoid running extractors unnecessarily
|
|
5
5
|
const rehypeExtractors = (mdxExtracts, data) => {
|
|
@@ -20,9 +20,9 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
|
|
|
20
20
|
remarkRemoveImports,
|
|
21
21
|
remarkMermaid,
|
|
22
22
|
...remarkPlugins,
|
|
23
|
+
[remarkMdxRemoveUnknownJsx, data.allowedComponents],
|
|
23
24
|
],
|
|
24
25
|
rehypePlugins: [
|
|
25
|
-
[rehypeMdxRemoveUnknownJsx, data.allowedComponents],
|
|
26
26
|
rehypeCodeBlocks,
|
|
27
27
|
rehypeParamFieldIds,
|
|
28
28
|
...rehypeExtractors(mdxExtracts, data),
|
|
@@ -31,6 +31,5 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
|
|
|
31
31
|
...rehypePlugins,
|
|
32
32
|
],
|
|
33
33
|
format: 'mdx',
|
|
34
|
-
useDynamicImport: true,
|
|
35
34
|
};
|
|
36
35
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const findExportedNodes: (tree:
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
export declare const findExportedNodes: (tree: Root, ...type: string[]) => string[];
|
|
@@ -3,8 +3,10 @@ import { nodeIncludesExport } from '../snippets/index.js';
|
|
|
3
3
|
import { isExportNode } from '../utils.js';
|
|
4
4
|
export const findExportedNodes = (tree, ...type) => {
|
|
5
5
|
const exports = [];
|
|
6
|
-
visit(tree,
|
|
6
|
+
visit(tree, 'mdxjsEsm', (node) => {
|
|
7
7
|
var _a;
|
|
8
|
+
if (!nodeIncludesExport(node))
|
|
9
|
+
return;
|
|
8
10
|
const body = node.data.estree.body;
|
|
9
11
|
for (const bodyChild of body) {
|
|
10
12
|
if (isExportNode(bodyChild)) {
|
|
@@ -3,4 +3,4 @@ export function createMdxJsxAttribute(key: any, value: any): {
|
|
|
3
3
|
name: any;
|
|
4
4
|
value: any;
|
|
5
5
|
};
|
|
6
|
-
export function toMdxJsxFlowElement(input: any): import("mdast").
|
|
6
|
+
export function toMdxJsxFlowElement(input: any): import("mdast").RootContent | undefined;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export * from './rehypeCodeBlocks.js';
|
|
2
2
|
export * from './rehypeMdxExtractEndpoint/index.js';
|
|
3
3
|
export * from './rehypeMdxExtractExamples.js';
|
|
4
|
-
export * from './rehypeMdxRemoveUnknownJsx/index.js';
|
|
5
4
|
export * from './rehypeParamFieldIds.js';
|
|
6
5
|
export * from './rehypeRawComponents.js';
|
|
7
6
|
export * from './rehypeZoomImages.js';
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export * from './rehypeCodeBlocks.js';
|
|
2
2
|
export * from './rehypeMdxExtractEndpoint/index.js';
|
|
3
3
|
export * from './rehypeMdxExtractExamples.js';
|
|
4
|
-
export * from './rehypeMdxRemoveUnknownJsx/index.js';
|
|
5
4
|
export * from './rehypeParamFieldIds.js';
|
|
6
5
|
export * from './rehypeRawComponents.js';
|
|
7
6
|
export * from './rehypeZoomImages.js';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { MintConfig } from '@mintlify/models';
|
|
2
|
-
import type {
|
|
2
|
+
import type { Root } from 'hast';
|
|
3
3
|
import { MdxExtracts } from '../../../../index.js';
|
|
4
|
-
export declare const rehypeMdxExtractEndpoint: (metadata: unknown, config: MintConfig | undefined, mdxExtracts: MdxExtracts) =>
|
|
4
|
+
export declare const rehypeMdxExtractEndpoint: (metadata: unknown, config: MintConfig | undefined, mdxExtracts: MdxExtracts) => (tree: Root) => Root | undefined;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Root } from 'hast';
|
|
2
2
|
import type { MdxExtracts } from '../../../types/index.js';
|
|
3
|
-
export declare const rehypeMdxExtractExamples: (mdxExtracts: MdxExtracts) =>
|
|
3
|
+
export declare const rehypeMdxExtractExamples: (mdxExtracts: MdxExtracts) => (tree: Root) => Root;
|
|
@@ -24,7 +24,7 @@ export const rehypeMdxExtractExamples = (mdxExtracts) => {
|
|
|
24
24
|
type: node.name,
|
|
25
25
|
children: parseChildren(node),
|
|
26
26
|
};
|
|
27
|
-
if (parent && i
|
|
27
|
+
if (parent && i != null)
|
|
28
28
|
parent.children.splice(i, 1);
|
|
29
29
|
}
|
|
30
30
|
else if (node.name === 'ResponseExample') {
|
|
@@ -32,7 +32,7 @@ export const rehypeMdxExtractExamples = (mdxExtracts) => {
|
|
|
32
32
|
type: node.name,
|
|
33
33
|
children: parseChildren(node),
|
|
34
34
|
};
|
|
35
|
-
if (parent && i
|
|
35
|
+
if (parent && i != null)
|
|
36
36
|
parent.children.splice(i, 1);
|
|
37
37
|
}
|
|
38
38
|
});
|
|
@@ -45,16 +45,16 @@ export const rehypeMdxExtractExamples = (mdxExtracts) => {
|
|
|
45
45
|
};
|
|
46
46
|
const parseChildren = (node) => {
|
|
47
47
|
return node.children.filter(isMdxJsxFlowElementHast).flatMap((child) => {
|
|
48
|
-
var _a
|
|
48
|
+
var _a;
|
|
49
49
|
const preComponent = child.children[0];
|
|
50
50
|
if ((preComponent === null || preComponent === void 0 ? void 0 : preComponent.type) !== 'element')
|
|
51
51
|
return [];
|
|
52
52
|
const html = toHtml(preComponent);
|
|
53
|
-
let filename = Array.isArray(
|
|
53
|
+
let filename = Array.isArray(preComponent.properties.className) &&
|
|
54
54
|
typeof preComponent.properties.className[0] === 'string'
|
|
55
55
|
? langFilename(preComponent.properties.className[0])
|
|
56
56
|
: '';
|
|
57
|
-
if ('attributes' in child && typeof ((
|
|
57
|
+
if ('attributes' in child && typeof ((_a = child.attributes[0]) === null || _a === void 0 ? void 0 : _a.value) === 'string') {
|
|
58
58
|
filename = child.attributes[0].value;
|
|
59
59
|
}
|
|
60
60
|
return [
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const rehypeParamFieldIds: () =>
|
|
1
|
+
import type { Root } from 'hast';
|
|
2
|
+
export declare const rehypeParamFieldIds: () => (tree: Root) => Root;
|
|
@@ -3,9 +3,8 @@ import { visit } from 'unist-util-visit';
|
|
|
3
3
|
export const rehypeParamFieldIds = () => {
|
|
4
4
|
return (tree) => {
|
|
5
5
|
const paramCounts = new Map();
|
|
6
|
-
visit(tree, 'mdxJsxFlowElement', (
|
|
6
|
+
visit(tree, 'mdxJsxFlowElement', (element) => {
|
|
7
7
|
var _a;
|
|
8
|
-
const element = node;
|
|
9
8
|
if (element.name === 'ParamField' ||
|
|
10
9
|
element.name === 'Param' ||
|
|
11
10
|
element.name === 'ResponseField') {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const rehypeZoomImages: () =>
|
|
1
|
+
import type { Root } from 'hast';
|
|
2
|
+
export declare const rehypeZoomImages: () => (tree: Root) => void;
|
|
@@ -2,12 +2,12 @@ import { u } from 'unist-builder';
|
|
|
2
2
|
import { visit } from 'unist-util-visit';
|
|
3
3
|
export const rehypeZoomImages = () => (tree) => {
|
|
4
4
|
visit(tree, 'mdxJsxFlowElement', (node, index, parent) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const noZoom = element.attributes.find((attr) => 'name' in attr && attr.name === 'noZoom');
|
|
5
|
+
if (node.name === 'img' || node.name === 'picture' || node.name === 'figure') {
|
|
6
|
+
const noZoom = node.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'noZoom');
|
|
8
7
|
if (!noZoom && parent && index != null) {
|
|
9
8
|
parent.children.splice(index, 1, u('element', {
|
|
10
9
|
tagName: 'ZoomImage',
|
|
10
|
+
properties: {},
|
|
11
11
|
}, [node]));
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -3,6 +3,7 @@ export * from './remarkFrames.js';
|
|
|
3
3
|
export * from './remarkRemoveImports.js';
|
|
4
4
|
export * from './remarkExtractTableOfContents.js';
|
|
5
5
|
export * from './remarkMdxRemoveUnusedVariables.js';
|
|
6
|
+
export * from './remarkMdxRemoveUnknownJsx/index.js';
|
|
6
7
|
export * from './remarkReplaceAllImages.js';
|
|
7
8
|
export * from './remarkMermaid.js';
|
|
8
9
|
export * from './remarkMdxRemoveJs.js';
|
|
@@ -3,6 +3,7 @@ export * from './remarkFrames.js';
|
|
|
3
3
|
export * from './remarkRemoveImports.js';
|
|
4
4
|
export * from './remarkExtractTableOfContents.js';
|
|
5
5
|
export * from './remarkMdxRemoveUnusedVariables.js';
|
|
6
|
+
export * from './remarkMdxRemoveUnknownJsx/index.js';
|
|
6
7
|
export * from './remarkReplaceAllImages.js';
|
|
7
8
|
export * from './remarkMermaid.js';
|
|
8
9
|
export * from './remarkMdxRemoveJs.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Root } from 'mdast';
|
|
1
2
|
import { Parent } from 'unist';
|
|
2
3
|
import { VFile } from 'vfile';
|
|
3
|
-
export declare const remarkMdxInjectSnippets:
|
|
4
|
+
export declare const remarkMdxInjectSnippets: (snippetTreeMap: Record<string, Root>) => (tree: Parent, file: VFile) => void;
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import { removePosition } from 'unist-util-remove-position';
|
|
2
2
|
import { visit, SKIP } from 'unist-util-visit';
|
|
3
|
-
export const remarkMdxInjectSnippets = (snippetTreeMap) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
3
|
+
export const remarkMdxInjectSnippets = (snippetTreeMap) => (tree, file) => {
|
|
4
|
+
visit(tree, (node, index, parent) => {
|
|
5
|
+
if (parent && index != null && node.type === 'mdxJsxFlowElement') {
|
|
6
|
+
const mdxJsxFlowElement = node;
|
|
7
|
+
if (mdxJsxFlowElement.name === 'Snippet') {
|
|
8
|
+
const fileAttr = mdxJsxFlowElement.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'file');
|
|
9
|
+
const name = fileAttr === null || fileAttr === void 0 ? void 0 : fileAttr.value;
|
|
10
|
+
if (typeof name === 'string') {
|
|
11
|
+
const snippet = snippetTreeMap[name];
|
|
12
|
+
if (snippet) {
|
|
13
|
+
const fragment = structuredClone(snippet);
|
|
14
|
+
removePosition(fragment);
|
|
15
|
+
parent.children.splice(index, 1, ...fragment.children);
|
|
16
|
+
return [SKIP, index];
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
file.message('Cannot expand missing snippet `' + name + '`', node, 'remark-mdx-inject-snippets');
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
|
-
}
|
|
25
|
-
};
|
|
23
|
+
}
|
|
24
|
+
});
|
|
26
25
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare const remarkMdxRemoveJs: () =>
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
export declare const remarkMdxRemoveJs: () => (tree: Root) => void;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
export declare const remarkMdxRemoveUnknownJsx: (allowedComponents?: string[]) => (tree: Root) => Root | import("mdast-util-mdxjs-esm").MdxjsEsm | import("mdast-util-mdx-expression").MdxFlowExpression | import("mdast-util-mdx-expression").MdxTextExpression | import("mdast").Delete | import("mdast").Yaml | import("mdast-util-mdx").MdxJsxFlowElement | import("mdast").Blockquote | import("mdast").Break | import("mdast").Code | import("mdast").Definition | import("mdast").Emphasis | import("mdast").FootnoteDefinition | import("mdast").FootnoteReference | import("mdast").Heading | import("mdast").Html | import("mdast").Image | import("mdast").ImageReference | import("mdast").InlineCode | import("mdast").Link | import("mdast").LinkReference | import("mdast").List | import("mdast").ListItem | import("mdast").Paragraph | import("mdast").Strong | import("mdast").Table | import("mdast").TableCell | import("mdast").TableRow | import("mdast").Text | import("mdast").ThematicBreak | import("mdast-util-math").InlineMath | import("mdast-util-math").Math | import("mdast-util-mdx").MdxJsxTextElement;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { map } from 'unist-util-map';
|
|
2
2
|
import { findExportedNodes, isMdxJsxFlowElementHast } from '../../../lib/index.js';
|
|
3
3
|
import { createCommentNode } from './createCommentNode.js';
|
|
4
|
-
const
|
|
4
|
+
export const remarkMdxRemoveUnknownJsx = (allowedComponents) => (tree) => {
|
|
5
5
|
const exportedComponentNames = findExportedNodes(tree, 'ArrowFunctionExpression');
|
|
6
6
|
return map(tree, (node) => {
|
|
7
7
|
if (isMdxJsxFlowElementHast(node)) {
|
|
@@ -14,4 +14,3 @@ const rehypeMdxRemoveUnknownJsx = (allowedComponents) => (tree) => {
|
|
|
14
14
|
return node;
|
|
15
15
|
});
|
|
16
16
|
};
|
|
17
|
-
export default rehypeMdxRemoveUnknownJsx;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const remarkMdxRemoveUnusedVariables: () => (tree:
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
export declare const remarkMdxRemoveUnusedVariables: () => (tree: Root) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const remarkMermaid:
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
export declare const remarkMermaid: () => (tree: Root) => void;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { visit } from 'unist-util-visit';
|
|
2
2
|
const REACT_COMPONENT_NAME = 'Mermaid';
|
|
3
|
-
export const remarkMermaid = () => (
|
|
3
|
+
export const remarkMermaid = () => (tree) => {
|
|
4
4
|
const codeblocks = [];
|
|
5
|
-
visit(
|
|
6
|
-
if (typeof index === 'number') {
|
|
5
|
+
visit(tree, 'code', (node, index, parent) => {
|
|
6
|
+
if (node.lang === 'mermaid' && parent && typeof index === 'number') {
|
|
7
7
|
codeblocks.push([node, index, parent]);
|
|
8
8
|
}
|
|
9
9
|
});
|
|
@@ -48,5 +48,4 @@ export const remarkMermaid = () => (ast, _file, done) => {
|
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
done();
|
|
52
51
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const remarkRemoveImports: () =>
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
export declare const remarkRemoveImports: () => (tree: Root) => void;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import { remove } from 'unist-util-remove';
|
|
2
|
+
import { isMdxJsEsm } from '../../utils.js';
|
|
2
3
|
export const remarkRemoveImports = () => (tree) => {
|
|
3
4
|
remove(tree, (node) => {
|
|
4
|
-
|
|
5
|
-
const mdxjsEsm = node;
|
|
6
|
-
return mdxjsEsm.value.startsWith('import');
|
|
7
|
-
}
|
|
8
|
-
return false;
|
|
5
|
+
return isMdxJsEsm(node) && node.value.startsWith('import');
|
|
9
6
|
});
|
|
10
|
-
return tree;
|
|
11
7
|
};
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
type ImageNode = Node<Data> & {
|
|
3
|
-
name: string;
|
|
4
|
-
attributes: {
|
|
5
|
-
name: string;
|
|
6
|
-
value: string;
|
|
7
|
-
}[];
|
|
8
|
-
url: string;
|
|
9
|
-
};
|
|
1
|
+
import type { Root } from 'mdast';
|
|
10
2
|
export declare const getImageUri: (imagePath: string, subdomain: string, filePath: string, basePath?: string) => string;
|
|
11
|
-
export declare const remarkReplaceAllImages: (subdomain: string, filePath: string, basePath?: string) => (tree:
|
|
12
|
-
export {};
|
|
3
|
+
export declare const remarkReplaceAllImages: (subdomain: string, filePath: string, basePath?: string) => (tree: Root) => Root;
|
|
@@ -14,30 +14,26 @@ export const getImageUri = (imagePath, subdomain, filePath, basePath) => {
|
|
|
14
14
|
};
|
|
15
15
|
export const remarkReplaceAllImages = (subdomain, filePath, basePath) => {
|
|
16
16
|
return (tree) => {
|
|
17
|
-
visit(tree, (node) => {
|
|
18
|
-
var _a;
|
|
19
|
-
if (node == null) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
17
|
+
visit(tree, 'mdxJsxFlowElement', (node) => {
|
|
22
18
|
if (node.name === 'img' || node.name === 'source' || node.name === 'video') {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
const srcAttr = node.attributes.find(isSrcAttr);
|
|
20
|
+
if (!srcAttr)
|
|
21
|
+
return;
|
|
22
|
+
const nodeUrl = srcAttr.value;
|
|
23
|
+
if (typeof nodeUrl !== 'string')
|
|
26
24
|
return;
|
|
27
|
-
}
|
|
28
25
|
if (
|
|
29
26
|
// <img/> component
|
|
30
|
-
|
|
31
|
-
!
|
|
32
|
-
|
|
33
|
-
node.attributes[srcAttrIndex]) {
|
|
34
|
-
node.attributes[srcAttrIndex].value = getImageUri(nodeUrl, subdomain, filePath, basePath);
|
|
27
|
+
!isAbsoluteUrl(nodeUrl) &&
|
|
28
|
+
!isDataString(nodeUrl)) {
|
|
29
|
+
srcAttr.value = getImageUri(nodeUrl, subdomain, filePath, basePath);
|
|
35
30
|
}
|
|
36
31
|
}
|
|
37
|
-
|
|
32
|
+
});
|
|
33
|
+
visit(tree, 'image', (node) => {
|
|
34
|
+
if (
|
|
38
35
|
// ![]() format
|
|
39
|
-
node.
|
|
40
|
-
node.url &&
|
|
36
|
+
node.url &&
|
|
41
37
|
!isAbsoluteUrl(node.url) &&
|
|
42
38
|
!isDataString(node.url)) {
|
|
43
39
|
node.url = getImageUri(node.url, subdomain, filePath, basePath);
|
|
@@ -46,4 +42,7 @@ export const remarkReplaceAllImages = (subdomain, filePath, basePath) => {
|
|
|
46
42
|
return tree;
|
|
47
43
|
};
|
|
48
44
|
};
|
|
45
|
+
function isSrcAttr(attr) {
|
|
46
|
+
return attr.type === 'mdxJsxAttribute' && attr.name === 'src';
|
|
47
|
+
}
|
|
49
48
|
const isDataString = (str) => str.startsWith('data:');
|
package/dist/mdx/remark.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const coreRemarkMdxPlugins:
|
|
3
|
-
export declare const coreRemark: import("unified").
|
|
1
|
+
import type { PluggableList } from 'unified';
|
|
2
|
+
export declare const coreRemarkMdxPlugins: PluggableList;
|
|
3
|
+
export declare const coreRemark: import("unified").Processor<import("mdast").Root, undefined, undefined, import("mdast").Root, string>;
|
|
4
4
|
export declare const getAST: (str: string) => import("mdast").Root;
|
|
@@ -79,9 +79,7 @@ export const findAndRemoveImports = (content) => __awaiter(void 0, void 0, void
|
|
|
79
79
|
}
|
|
80
80
|
if (newBody.length != 0) {
|
|
81
81
|
node.data.estree.body = newBody;
|
|
82
|
-
|
|
83
|
-
delete node.value;
|
|
84
|
-
}
|
|
82
|
+
node.value = '';
|
|
85
83
|
removePosition(node);
|
|
86
84
|
const newValue = toJs(node.data.estree, { handlers: jsx }).value;
|
|
87
85
|
node.value = newValue;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
1
|
+
import type { Program } from 'estree-jsx';
|
|
2
|
+
import { MdxjsEsm } from 'mdast-util-mdx';
|
|
3
|
+
import { Node } from 'unist';
|
|
3
4
|
/**
|
|
4
5
|
* An export looks like this in AST form:
|
|
5
6
|
* {
|
|
@@ -18,4 +19,8 @@ import type { NodeWithEstree } from '../../types/mdx/index.js';
|
|
|
18
19
|
* @param content mdx ast node
|
|
19
20
|
* @returns whether the node includes an export or not
|
|
20
21
|
*/
|
|
21
|
-
export declare const nodeIncludesExport: (node: Node) => node is
|
|
22
|
+
export declare const nodeIncludesExport: (node: Node) => node is MdxjsEsm & {
|
|
23
|
+
data: {
|
|
24
|
+
estree: Program;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isExport } from '../utils.js';
|
|
1
|
+
import { isExport, isMdxJsEsm } from '../utils.js';
|
|
2
2
|
/**
|
|
3
3
|
* An export looks like this in AST form:
|
|
4
4
|
* {
|
|
@@ -18,18 +18,11 @@ import { isExport } from '../utils.js';
|
|
|
18
18
|
* @returns whether the node includes an export or not
|
|
19
19
|
*/
|
|
20
20
|
export const nodeIncludesExport = (node) => {
|
|
21
|
-
var _a, _b
|
|
22
|
-
if (node.
|
|
21
|
+
var _a, _b;
|
|
22
|
+
if (!isMdxJsEsm(node) || !((_b = (_a = node.data) === null || _a === void 0 ? void 0 : _a.estree) === null || _b === void 0 ? void 0 : _b.body) || node.data.estree.sourceType !== 'module') {
|
|
23
23
|
return false;
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
((_d = (_c = node.data) === null || _c === void 0 ? void 0 : _c.estree) === null || _d === void 0 ? void 0 : _d.sourceType) !== 'module') {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
if (!((_f = (_e = node.data) === null || _e === void 0 ? void 0 : _e.estree) === null || _f === void 0 ? void 0 : _f.body)) {
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
for (const bodyChild of ((_g = node.data) === null || _g === void 0 ? void 0 : _g.estree).body) {
|
|
25
|
+
for (const bodyChild of node.data.estree.body) {
|
|
33
26
|
if (isExport(bodyChild.type)) {
|
|
34
27
|
return true;
|
|
35
28
|
}
|
package/dist/mdx/utils.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import type { ImportDeclaration, ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration } from 'estree-jsx';
|
|
2
|
-
import
|
|
1
|
+
import type { ImportDeclaration, ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration, Program } from 'estree-jsx';
|
|
2
|
+
import { MdxFlowExpression, MdxjsEsm, MdxTextExpression } from 'mdast-util-mdx';
|
|
3
3
|
import type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
|
|
4
4
|
import type { Node } from 'unist';
|
|
5
|
-
import type { MdxNodeBodyChildType
|
|
6
|
-
export declare const
|
|
7
|
-
export declare
|
|
8
|
-
|
|
5
|
+
import type { MdxNodeBodyChildType } from '../types/mdx/index.js';
|
|
6
|
+
export declare const isMdxJsEsm: (node: Node) => node is MdxjsEsm;
|
|
7
|
+
export declare function estreeIsProgram<T extends MdxFlowExpression | MdxTextExpression | MdxjsEsm>(node: T): node is T & {
|
|
8
|
+
data: {
|
|
9
|
+
estree: Program;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
9
12
|
export declare const isImportDeclaration: (bodyChild: MdxNodeBodyChildType) => bodyChild is ImportDeclaration;
|
|
10
13
|
export declare const isExport: (type: string) => boolean;
|
|
11
14
|
export declare const isExportNode: (bodyChild: MdxNodeBodyChildType) => bodyChild is ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration;
|
package/dist/mdx/utils.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
export const isComment = (node) => {
|
|
2
|
-
var _a, _b, _c, _d;
|
|
3
|
-
return node.type === 'mdxFlowExpression' &&
|
|
4
|
-
((_b = (_a = node.data) === null || _a === void 0 ? void 0 : _a.estree) === null || _b === void 0 ? void 0 : _b.body.length) === 0 &&
|
|
5
|
-
((_d = (_c = node.data.estree.comments) === null || _c === void 0 ? void 0 : _c.length) !== null && _d !== void 0 ? _d : 0) > 0;
|
|
6
|
-
};
|
|
7
1
|
export const isMdxJsEsm = (node) => node.type === 'mdxjsEsm';
|
|
8
|
-
export
|
|
2
|
+
export function estreeIsProgram(node) {
|
|
3
|
+
var _a;
|
|
4
|
+
return ((_a = node.data) === null || _a === void 0 ? void 0 : _a.estree) != null;
|
|
5
|
+
}
|
|
9
6
|
export const isImportDeclaration = (bodyChild) => bodyChild.type === 'ImportDeclaration';
|
|
10
7
|
export const isExport = (type) => [
|
|
11
8
|
'ExportAllDeclaration', // export * from source
|