@mintlify/common 1.0.852 → 1.0.854

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.
@@ -10,6 +10,7 @@ type MDXOptionsData = {
10
10
  config?: Pick<DocsConfig, 'api' | '$schema'> | Pick<MintConfig, 'api' | '$schema'>;
11
11
  subdomain?: string;
12
12
  tailwindSelectors?: string[];
13
+ path?: string;
13
14
  };
14
15
  export declare const getMDXOptions: ({ data, remarkPlugins, rehypePlugins, mdxExtracts, }: {
15
16
  data: MDXOptionsData;
@@ -1,4 +1,4 @@
1
- import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeKeyboardSymbols, rehypeListItemText, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeTable, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames, remarkComponentIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, remarkMdxExtractPanel, remarkVideo, remarkExtractMultiView, remarkPrompt, remarkUnwrapJsxHeadings, } from './plugins/index.js';
1
+ import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeKeyboardSymbols, rehypeListItemText, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeTable, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames, remarkComponentIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, remarkMdxExtractPanel, remarkResolveRelativeLinks, remarkVideo, remarkExtractMultiView, remarkPrompt, remarkUnwrapJsxHeadings, } 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
@@ -14,6 +14,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
14
14
  return {
15
15
  remarkPlugins: [
16
16
  [remarkMdxInjectSnippets, data.snippetTreeMap],
17
+ [remarkResolveRelativeLinks, { path: data.path }],
17
18
  remarkPrompt,
18
19
  [remarkComponentIds, data.pageMetadata],
19
20
  remarkUnwrapJsxHeadings,
@@ -17,4 +17,6 @@ export * from './remarkValidateTabs.js';
17
17
  export * from './remarkVideo.js';
18
18
  export * from './remarkExtractMultiView.js';
19
19
  export * from './remarkPrompt.js';
20
+ export * from './remarkResolveRelativeLinks.js';
20
21
  export * from './remarkUnwrapJsxHeadings.js';
22
+ export * from './remarkVisibilityForMarkdown.js';
@@ -17,4 +17,6 @@ export * from './remarkValidateTabs.js';
17
17
  export * from './remarkVideo.js';
18
18
  export * from './remarkExtractMultiView.js';
19
19
  export * from './remarkPrompt.js';
20
+ export * from './remarkResolveRelativeLinks.js';
20
21
  export * from './remarkUnwrapJsxHeadings.js';
22
+ export * from './remarkVisibilityForMarkdown.js';
@@ -0,0 +1,6 @@
1
+ import type { Root } from 'mdast';
2
+ type Options = {
3
+ path?: string;
4
+ };
5
+ export declare const remarkResolveRelativeLinks: (options?: Options) => (tree: Root) => void;
6
+ export {};
@@ -0,0 +1,48 @@
1
+ import { posix } from 'path';
2
+ import { visit } from 'unist-util-visit';
3
+ const isRelative = (url) => url.startsWith('./') || url.startsWith('../');
4
+ const resolveRelative = (baseDir, url) => {
5
+ // Preserve any fragment or query string verbatim.
6
+ const splitIndex = url.search(/[#?]/);
7
+ const pathPart = splitIndex === -1 ? url : url.slice(0, splitIndex);
8
+ const tail = splitIndex === -1 ? '' : url.slice(splitIndex);
9
+ const resolved = posix.normalize(posix.join(baseDir, pathPart));
10
+ const absolute = resolved.startsWith('/') && !resolved.startsWith('//') ? resolved : `/${resolved}`;
11
+ return absolute + tail;
12
+ };
13
+ const ATTR_BY_TAG = {
14
+ a: 'href',
15
+ Card: 'href',
16
+ img: 'src',
17
+ source: 'src',
18
+ };
19
+ export const remarkResolveRelativeLinks = (options = {}) => {
20
+ return (tree) => {
21
+ const { path } = options;
22
+ if (!path)
23
+ return;
24
+ const stripped = path.replace(/^\/+/, '').replace(/\.mdx?$/i, '');
25
+ const dir = posix.dirname(stripped);
26
+ const baseDir = dir === '.' || dir === '' ? '/' : `/${dir}`;
27
+ visit(tree, (node) => {
28
+ if (node.type === 'link' || node.type === 'image') {
29
+ const linkOrImg = node;
30
+ if (linkOrImg.url && isRelative(linkOrImg.url)) {
31
+ linkOrImg.url = resolveRelative(baseDir, linkOrImg.url);
32
+ }
33
+ return;
34
+ }
35
+ if (node.type !== 'mdxJsxFlowElement' && node.type !== 'mdxJsxTextElement') {
36
+ return;
37
+ }
38
+ const jsxNode = node;
39
+ const attrName = jsxNode.name ? ATTR_BY_TAG[jsxNode.name] : undefined;
40
+ if (!attrName)
41
+ return;
42
+ const attr = jsxNode.attributes.find((a) => a.type === 'mdxJsxAttribute' && a.name === attrName);
43
+ if (attr && 'value' in attr && typeof attr.value === 'string' && isRelative(attr.value)) {
44
+ attr.value = resolveRelative(baseDir, attr.value);
45
+ }
46
+ });
47
+ };
48
+ };
@@ -0,0 +1,2 @@
1
+ import type { Root } from 'mdast';
2
+ export declare const remarkVisibilityForMarkdown: () => (tree: Root) => void;
@@ -0,0 +1,46 @@
1
+ function isMdxJsxElement(node) {
2
+ return node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement';
3
+ }
4
+ function getVisibilityFor(node) {
5
+ for (const attr of node.attributes) {
6
+ if (attr.type !== 'mdxJsxAttribute' || attr.name !== 'for')
7
+ continue;
8
+ if (typeof attr.value === 'string') {
9
+ if (attr.value === 'humans' || attr.value === 'agents')
10
+ return attr.value;
11
+ continue;
12
+ }
13
+ if (attr.value &&
14
+ typeof attr.value === 'object' &&
15
+ 'value' in attr.value &&
16
+ typeof attr.value.value === 'string') {
17
+ const raw = attr.value.value.trim();
18
+ const quoted = raw.match(/^(["'])(humans|agents)\1$/);
19
+ if (quoted)
20
+ return quoted[2];
21
+ }
22
+ }
23
+ return undefined;
24
+ }
25
+ function transformChildren(children) {
26
+ return children.flatMap((child) => transformNode(child));
27
+ }
28
+ function transformNode(node) {
29
+ if (isMdxJsxElement(node) && node.name === 'Visibility') {
30
+ const audience = getVisibilityFor(node);
31
+ if (audience === 'humans') {
32
+ return [];
33
+ }
34
+ if (audience === 'agents') {
35
+ return transformChildren(node.children);
36
+ }
37
+ }
38
+ if ('children' in node && Array.isArray(node.children)) {
39
+ const next = transformChildren(node.children);
40
+ node.children = next;
41
+ }
42
+ return [node];
43
+ }
44
+ export const remarkVisibilityForMarkdown = () => (tree) => {
45
+ tree.children = transformChildren(tree.children);
46
+ };
@@ -4,3 +4,4 @@ export declare const coreRemarkMdxPlugins: PluggableList;
4
4
  export declare const coreRemark: import("unified").Processor<Root, undefined, undefined, Root, string>;
5
5
  export declare const getAST: (str: string, filePath?: string) => Root;
6
6
  export declare const stringifyTree: (tree: Root) => string;
7
+ export declare function stripVisibilityForMarkdown(mdx: string): string;
@@ -4,6 +4,7 @@ import remarkGfm from 'remark-gfm';
4
4
  import remarkMath from 'remark-math';
5
5
  import remarkMdx from 'remark-mdx';
6
6
  import remarkStringify from 'remark-stringify';
7
+ import { remarkVisibilityForMarkdown } from './plugins/remark/remarkVisibilityForMarkdown.js';
7
8
  import { preprocessCustomHeadingIds } from './preprocessCustomHeadingIds.js';
8
9
  import { getJsxEsmTree } from './snippets/getJsxEsmTree.js';
9
10
  import { isJsxOrTsx } from './snippets/isJsxOrTsx.js';
@@ -21,3 +22,8 @@ export const getAST = (str, filePath) => {
21
22
  return coreRemark().parse(preprocessCustomHeadingIds(str));
22
23
  };
23
24
  export const stringifyTree = (tree) => coreRemark().use(remarkStringify).stringify(tree);
25
+ export function stripVisibilityForMarkdown(mdx) {
26
+ const tree = getAST(mdx);
27
+ remarkVisibilityForMarkdown()(tree);
28
+ return stringifyTree(tree);
29
+ }
@@ -29,6 +29,7 @@ export function getMdx(_a) {
29
29
  config,
30
30
  codeStyling,
31
31
  tailwindSelectors,
32
+ path,
32
33
  };
33
34
  let mdxExtracts = {};
34
35
  let plugins = [remarkValidateSteps, remarkValidateTabs, ...remarkPlugins];