@mintlify/common
Version:
Commonly shared code within Mintlify
30 lines (29 loc) • 1.17 kB
JavaScript
import { remark } from 'remark';
import remarkFrontmatter from 'remark-frontmatter';
import remarkGfm from 'remark-gfm';
import remarkMath from 'remark-math';
import remarkMdx from 'remark-mdx';
import remarkStringify from 'remark-stringify';
import { remarkVisibilityForMarkdown } from './plugins/remark/remarkVisibilityForMarkdown.js';
import { preprocessCustomHeadingIds } from './preprocessCustomHeadingIds.js';
import { getJsxEsmTree } from './snippets/getJsxEsmTree.js';
import { isJsxOrTsx } from './snippets/isJsxOrTsx.js';
export const coreRemarkMdxPlugins = [
remarkMdx,
remarkGfm,
[remarkFrontmatter, ['yaml', 'toml']],
remarkMath,
];
export const coreRemark = remark().use(coreRemarkMdxPlugins).freeze();
export const getAST = (str, filePath) => {
if (isJsxOrTsx(filePath)) {
return getJsxEsmTree(str, filePath);
}
return coreRemark().parse(preprocessCustomHeadingIds(str));
};
export const stringifyTree = (tree) => coreRemark().use(remarkStringify).stringify(tree);
export function stripVisibilityForMarkdown(mdx) {
const tree = getAST(mdx);
remarkVisibilityForMarkdown()(tree);
return stringifyTree(tree);
}