@mintlify/common 1.0.1112 → 1.0.1113

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.
@@ -15,6 +15,7 @@ import { toEstree } from 'hast-util-to-estree';
15
15
  import remarkRehype from 'remark-rehype';
16
16
  import { unified } from 'unified';
17
17
  import { visit } from 'unist-util-visit';
18
+ import { visitParents } from 'unist-util-visit-parents';
18
19
  import { getAST } from '../../remark.js';
19
20
  import { getExportedFunctionNames } from './remarkMdxClientComponentBoundaries.js';
20
21
  const REMARK_REHYPE_OPTIONS = {
@@ -81,18 +82,26 @@ export const MAX_MDX_FRAGMENTS_PER_PAGE = 500;
81
82
  */
82
83
  export const remarkMdxExpandExpressions = (options) => (tree) => __awaiter(void 0, void 0, void 0, function* () {
83
84
  var _a, _b, _c;
85
+ const depth = (_a = options.depth) !== null && _a !== void 0 ? _a : 0;
84
86
  const expressions = [];
85
- visit(tree, (node) => {
86
- if (node.type === 'mdxFlowExpression' || node.type === 'mdxTextExpression') {
87
- expressions.push(node);
87
+ visitParents(tree, (node, ancestors) => {
88
+ if (node.type !== 'mdxFlowExpression' && node.type !== 'mdxTextExpression')
89
+ return;
90
+ // A page-level <Panel> is stringified back to MDX source by remarkMdxExtractPanel and
91
+ // compiled again on its own (getMdx). Leave its expressions as the author wrote them so
92
+ // that second compile expands them; expanding here would bake generated JSX (<em>, <h5>,
93
+ // …) into the panel source, which the second pass strips as unknown components.
94
+ if (depth === 0 &&
95
+ ancestors.some((a) => a.type === 'mdxJsxFlowElement' && 'name' in a && a.name === 'Panel')) {
96
+ return;
88
97
  }
98
+ expressions.push(node);
89
99
  });
90
100
  if (expressions.length === 0)
91
101
  return;
92
102
  const knownComponents = [
93
- ...new Set([...((_a = options.knownComponents) !== null && _a !== void 0 ? _a : []), ...getExportedFunctionNames(tree)]),
103
+ ...new Set([...((_b = options.knownComponents) !== null && _b !== void 0 ? _b : []), ...getExportedFunctionNames(tree)]),
94
104
  ];
95
- const depth = (_b = options.depth) !== null && _b !== void 0 ? _b : 0;
96
105
  const budget = (_c = options.budget) !== null && _c !== void 0 ? _c : { remaining: MAX_MDX_FRAGMENTS_PER_PAGE };
97
106
  for (const node of expressions) {
98
107
  yield expandExpression(node, options, { knownComponents, depth, budget });