@mintlify/common 1.0.853 → 1.0.855

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,5 +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';
21
22
  export * from './remarkVisibilityForMarkdown.js';
@@ -17,5 +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';
21
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
+ };
@@ -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];