@mintlify/common 1.0.196 → 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.
Files changed (57) hide show
  1. package/dist/mdx/getMDXOptions.d.ts +4 -4
  2. package/dist/mdx/getMDXOptions.js +2 -3
  3. package/dist/mdx/lib/findExportedNode.d.ts +2 -2
  4. package/dist/mdx/lib/findExportedNode.js +3 -1
  5. package/dist/mdx/lib/remark-utils.d.ts +1 -1
  6. package/dist/mdx/plugins/rehype/index.d.ts +0 -1
  7. package/dist/mdx/plugins/rehype/index.js +0 -1
  8. package/dist/mdx/plugins/rehype/rehypeMdxExtractEndpoint/index.d.ts +2 -2
  9. package/dist/mdx/plugins/rehype/rehypeMdxExtractExamples.d.ts +2 -2
  10. package/dist/mdx/plugins/rehype/rehypeMdxExtractExamples.js +5 -5
  11. package/dist/mdx/plugins/rehype/rehypeParamFieldIds.d.ts +2 -2
  12. package/dist/mdx/plugins/rehype/rehypeParamFieldIds.js +1 -2
  13. package/dist/mdx/plugins/rehype/rehypeZoomImages.d.ts +2 -2
  14. package/dist/mdx/plugins/rehype/rehypeZoomImages.js +3 -3
  15. package/dist/mdx/plugins/remark/index.d.ts +1 -0
  16. package/dist/mdx/plugins/remark/index.js +1 -0
  17. package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.d.ts +2 -1
  18. package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.js +19 -20
  19. package/dist/mdx/plugins/remark/remarkMdxRemoveJs.d.ts +2 -2
  20. package/dist/mdx/plugins/remark/remarkMdxRemoveJs.js +0 -1
  21. package/dist/mdx/plugins/remark/remarkMdxRemoveUnknownJsx/createCommentNode.d.ts +2 -0
  22. package/dist/mdx/plugins/remark/remarkMdxRemoveUnknownJsx/index.d.ts +2 -0
  23. package/dist/mdx/plugins/{rehype/rehypeMdxRemoveUnknownJsx → remark/remarkMdxRemoveUnknownJsx}/index.js +1 -2
  24. package/dist/mdx/plugins/remark/remarkMdxRemoveUnusedVariables.d.ts +2 -2
  25. package/dist/mdx/plugins/remark/remarkMermaid.d.ts +2 -2
  26. package/dist/mdx/plugins/remark/remarkMermaid.js +3 -4
  27. package/dist/mdx/plugins/remark/remarkRemoveImports.d.ts +2 -2
  28. package/dist/mdx/plugins/remark/remarkRemoveImports.js +2 -6
  29. package/dist/mdx/plugins/remark/remarkReplaceAllImages.d.ts +2 -11
  30. package/dist/mdx/plugins/remark/remarkReplaceAllImages.js +16 -17
  31. package/dist/mdx/remark.d.ts +3 -3
  32. package/dist/mdx/snippets/findAndRemoveImports.js +1 -3
  33. package/dist/mdx/snippets/getExportMap.d.ts +1 -1
  34. package/dist/mdx/snippets/index.d.ts +0 -1
  35. package/dist/mdx/snippets/index.js +0 -1
  36. package/dist/mdx/snippets/nodeIncludesExport.d.ts +8 -3
  37. package/dist/mdx/snippets/nodeIncludesExport.js +4 -11
  38. package/dist/mdx/utils.d.ts +9 -6
  39. package/dist/mdx/utils.js +4 -7
  40. package/dist/tsconfig.build.tsbuildinfo +1 -1
  41. package/dist/types/mdx/index.d.ts +1 -12
  42. package/package.json +28 -35
  43. package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/createCommentNode.d.ts +0 -15
  44. package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/index.d.ts +0 -3
  45. package/dist/mdx/snippets/mdxMdToHtml/code.d.ts +0 -10
  46. package/dist/mdx/snippets/mdxMdToHtml/code.js +0 -38
  47. package/dist/mdx/snippets/mdxMdToHtml/image.d.ts +0 -10
  48. package/dist/mdx/snippets/mdxMdToHtml/image.js +0 -31
  49. package/dist/mdx/snippets/mdxMdToHtml/index.d.ts +0 -11
  50. package/dist/mdx/snippets/mdxMdToHtml/index.js +0 -83
  51. package/dist/mdx/snippets/mdxMdToHtml/list.d.ts +0 -11
  52. package/dist/mdx/snippets/mdxMdToHtml/list.js +0 -18
  53. package/dist/mdx/snippets/mdxMdToHtml/table.d.ts +0 -16
  54. package/dist/mdx/snippets/mdxMdToHtml/table.js +0 -37
  55. package/dist/mdx/snippets/mdxMdToHtml/utils.d.ts +0 -10
  56. package/dist/mdx/snippets/mdxMdToHtml/utils.js +0 -22
  57. /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 'remark-mdx';
4
- import type { Pluggable } from 'unified';
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?: Pluggable[];
16
- rehypePlugins?: Pluggable[];
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 rehypeMdxRemoveUnknownJsx from './plugins/rehype/rehypeMdxRemoveUnknownJsx/index.js';
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 { Node } from 'unist';
2
- export declare const findExportedNodes: (tree: Node, ...type: string[]) => string[];
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, nodeIncludesExport, (node) => {
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").Content | undefined;
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 { Node } from 'unist';
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) => <T extends Node>(tree: T) => T | undefined;
4
+ export declare const rehypeMdxExtractEndpoint: (metadata: unknown, config: MintConfig | undefined, mdxExtracts: MdxExtracts) => (tree: Root) => Root | undefined;
@@ -1,3 +1,3 @@
1
- import type { Node } from 'unist';
1
+ import type { Root } from 'hast';
2
2
  import type { MdxExtracts } from '../../../types/index.js';
3
- export declare const rehypeMdxExtractExamples: (mdxExtracts: MdxExtracts) => <T extends Node>(tree: T) => T;
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 !== null)
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 !== null)
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, _b;
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((_a = preComponent.properties) === null || _a === void 0 ? void 0 : _a.className) &&
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 ((_b = child.attributes[0]) === null || _b === void 0 ? void 0 : _b.value) === 'string') {
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 { Node } from 'unist';
2
- export declare const rehypeParamFieldIds: () => <T extends Node>(tree: T) => T;
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', (node) => {
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 { Node } from 'unist';
2
- export declare const rehypeZoomImages: () => <T extends Node>(tree: T) => void;
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
- const element = node;
6
- if (element.name === 'img' || element.name === 'picture' || element.name === 'figure') {
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: <T extends Parent>(snippetTreeMap: Record<string, T>) => (tree: Parent, file: VFile) => void;
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
- return (tree, file) => {
5
- visit(tree, (node, index, parent) => {
6
- if (parent && index !== null && node.type === 'mdxJsxFlowElement') {
7
- const mdxJsxFlowElement = node;
8
- if (mdxJsxFlowElement.name === 'Snippet') {
9
- const fileAttr = mdxJsxFlowElement.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'file');
10
- const name = fileAttr === null || fileAttr === void 0 ? void 0 : fileAttr.value;
11
- if (typeof name === 'string') {
12
- const snippet = snippetTreeMap[name];
13
- if (snippet) {
14
- const fragment = removePosition(structuredClone(snippet));
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');
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 { Node } from 'unist';
2
- export declare const remarkMdxRemoveJs: () => <T extends Node>(tree: T) => T;
1
+ import type { Root } from 'mdast';
2
+ export declare const remarkMdxRemoveJs: () => (tree: Root) => void;
@@ -1,5 +1,4 @@
1
1
  import { remove } from 'unist-util-remove';
2
2
  export const remarkMdxRemoveJs = () => (tree) => {
3
3
  remove(tree, ['mdxTextExpression', 'mdxFlowExpression']);
4
- return tree;
5
4
  };
@@ -0,0 +1,2 @@
1
+ import { MdxFlowExpression } from 'mdast-util-mdx';
2
+ export declare const createCommentNode: (componentName: string) => MdxFlowExpression;
@@ -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 rehypeMdxRemoveUnknownJsx = (allowedComponents) => (tree) => {
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 { Node } from 'unist';
2
- export declare const remarkMdxRemoveUnusedVariables: () => (tree: Node) => void;
1
+ import type { Root } from 'mdast';
2
+ export declare const remarkMdxRemoveUnusedVariables: () => (tree: Root) => void;
@@ -1,2 +1,2 @@
1
- import type { Pluggable } from 'unified';
2
- export declare const remarkMermaid: Pluggable;
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 = () => (ast, _file, done) => {
3
+ export const remarkMermaid = () => (tree) => {
4
4
  const codeblocks = [];
5
- visit(ast, { type: 'code', lang: 'mermaid' }, (node, index, parent) => {
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 { Node } from 'unist';
2
- export declare const remarkRemoveImports: () => <T extends Node>(tree: T) => T;
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
- if (node.type === 'mdxjsEsm') {
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 { Data, Node } from 'unist';
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: ImageNode) => ImageNode;
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 srcAttrIndex = node.attributes.findIndex((attr) => attr.name === 'src');
24
- const nodeUrl = (_a = node.attributes[srcAttrIndex]) === null || _a === void 0 ? void 0 : _a.value;
25
- if (!nodeUrl) {
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
- srcAttrIndex !== -1 &&
31
- !isAbsoluteUrl(nodeUrl) &&
32
- !isDataString(nodeUrl) &&
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
- else if (
32
+ });
33
+ visit(tree, 'image', (node) => {
34
+ if (
38
35
  // ![]() format
39
- node.type === 'image' &&
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:');
@@ -1,4 +1,4 @@
1
- import type { Pluggable } from 'unified';
2
- export declare const coreRemarkMdxPlugins: Pluggable[];
3
- export declare const coreRemark: import("unified").FrozenProcessor<import("mdast").Root, import("mdast").Root, import("mdast").Root, string>;
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
- if (node.value) {
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,4 +1,4 @@
1
- import { Root } from 'remark-mdx';
1
+ import type { Root } from 'mdast';
2
2
  /**
3
3
  *
4
4
  * @returns map of export names and their content
@@ -1,4 +1,3 @@
1
- export * from './mdxMdToHtml/index.js';
2
1
  export * from './findAndRemoveImports.js';
3
2
  export * from './hasImports.js';
4
3
  export * from './nodeIncludesExport.js';
@@ -1,4 +1,3 @@
1
- export * from './mdxMdToHtml/index.js';
2
1
  export * from './findAndRemoveImports.js';
3
2
  export * from './hasImports.js';
4
3
  export * from './nodeIncludesExport.js';
@@ -1,5 +1,6 @@
1
- import type { Node } from 'unist';
2
- import type { NodeWithEstree } from '../../types/mdx/index.js';
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 NodeWithEstree;
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, _c, _d, _e, _f, _g;
22
- if (node.type !== 'mdxjsEsm') {
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
- if (((_b = (_a = node.data) === null || _a === void 0 ? void 0 : _a.estree) === null || _b === void 0 ? void 0 : _b.type) !== 'Program' &&
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
  }
@@ -1,11 +1,14 @@
1
- import type { ImportDeclaration, ExportAllDeclaration, ExportDefaultDeclaration, ExportNamedDeclaration } from 'estree-jsx';
2
- import type { Content } from 'mdast';
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, NodeWithEstree } from '../types/mdx/index.js';
6
- export declare const isComment: (node: Content) => boolean;
7
- export declare const isMdxJsEsm: (node: Node) => node is Content;
8
- export declare const estreeIsProgram: (node: Content) => node is NodeWithEstree;
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 const estreeIsProgram = (node) => { var _a; return ((_a = node.data) === null || _a === void 0 ? void 0 : _a.estree) != null; };
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