Remix 中 mdx table 不支持表格 ?

1,667 阅读1分钟

remix 中支持 md/mdx 语法,但是 Remix 语法没有内置对 markdown 表格的支持。

remix 配置文件中配置 mdx 属性

mdx 配置在 Remix 文档很不明显,从 remix 的配置文件的 .d.ts 文件。

export interface AppConfig {
    mdx?: RemixMdxConfig | RemixMdxConfigFunction;
}

export interface RemixMdxConfig {
    rehypePlugins?: any[];
    remarkPlugins?: any[];
}
export type RemixMdxConfigFunction = (filename: string) => Promise<RemixMdxConfig | undefined> | RemixMdxConfig | undefined;

添加插件 remark-gfm

Remix 通过 remark 等支持 markdown 语法,但是默认没有 表格等 gfm 插件支持。

npm install remark-gfm

添加配置:

/** @type {import('@remix-run/dev').AppConfig} */
module.exports = {
  // ...
  mdx: async (filename) => {
    const [rehypeHighlight, remarkToc, gfm] = await Promise.all([
      import("rehype-highlight").then((mod) => mod.default),
      import("remark-toc").then((mod) => mod.default),
      import("remark-gfm").then((mod) => mod.default),
    ]);

    return {
      remarkPlugins: [remarkToc, gfm],
      rehypePlugins: [rehypeHighlight],
    };
  }
};

注意:经过尝试,使用 exports.mdx = async (filename) {/**/} 没有生效。下面是支持之后的效果

image.png