@mintlify/common 1.0.369 → 1.0.370

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.
@@ -1,4 +1,4 @@
1
- import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames, remarkHeadingIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, } from './plugins/index.js';
1
+ import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames, remarkHeadingIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, remarkMdxExtractPanel, } 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
@@ -16,6 +16,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
16
16
  [remarkMdxInjectSnippets, data.snippetTreeMap],
17
17
  [remarkExtractTableOfContents, mdxExtracts], // modifies tree so cannot be excluded
18
18
  [remarkExtractChangelogFilters, mdxExtracts],
19
+ [remarkMdxExtractPanel, mdxExtracts],
19
20
  remarkMdxRemoveUnusedVariables,
20
21
  remarkFrames,
21
22
  remarkRemoveImports,
@@ -12,3 +12,4 @@ export * from './remarkExpandContent.js';
12
12
  export * from './remarkSplitCodeGroup.js';
13
13
  export * from './remarkSplitTabs.js';
14
14
  export * from './remarkHeadingIds.js';
15
+ export * from './remarkMdxExtractPanel.js';
@@ -12,3 +12,4 @@ export * from './remarkExpandContent.js';
12
12
  export * from './remarkSplitCodeGroup.js';
13
13
  export * from './remarkSplitTabs.js';
14
14
  export * from './remarkHeadingIds.js';
15
+ export * from './remarkMdxExtractPanel.js';
@@ -0,0 +1,3 @@
1
+ import type { Root } from 'mdast';
2
+ import { MdxExtracts } from '../../../types/index.js';
3
+ export declare const remarkMdxExtractPanel: (mdxExtracts?: MdxExtracts) => (tree: Root) => Root;
@@ -0,0 +1,43 @@
1
+ import remarkStringify from 'remark-stringify';
2
+ import { unified } from 'unified';
3
+ import { visit } from 'unist-util-visit';
4
+ import { coreRemarkMdxPlugins } from '../../remark.js';
5
+ export const remarkMdxExtractPanel = (mdxExtracts) => {
6
+ return (tree) => {
7
+ let esmContent = '';
8
+ let panelContent;
9
+ const stringifyNode = (node) => {
10
+ try {
11
+ return unified().use(coreRemarkMdxPlugins).use(remarkStringify).stringify(node);
12
+ }
13
+ catch (error) {
14
+ console.error('Error converting MDX content to markdown:', error);
15
+ return '';
16
+ }
17
+ };
18
+ visit(tree, 'mdxjsEsm', (node) => {
19
+ esmContent += stringifyNode({
20
+ type: 'root',
21
+ children: [node],
22
+ });
23
+ });
24
+ visit(tree, 'mdxJsxFlowElement', (node, i, parent) => {
25
+ if (node.name === 'Panel') {
26
+ panelContent = stringifyNode({
27
+ type: 'root',
28
+ children: node.children,
29
+ });
30
+ if (parent && i != null) {
31
+ parent.children.splice(i, 1);
32
+ }
33
+ }
34
+ });
35
+ if (esmContent || panelContent) {
36
+ const content = [esmContent, panelContent].filter((content) => !!content).join('\n');
37
+ if (!!panelContent && mdxExtracts) {
38
+ mdxExtracts.panel = { content };
39
+ }
40
+ }
41
+ return tree;
42
+ };
43
+ };