diff --git a/package.json b/package.json index b43705a..81bf638 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "rehype-slug": "^6.0.0", "rehype-stringify": "^10.0.1", "rehype-unwrap-images": "^1.0.0", + "remark-cjk-friendly": "^2.3.1", "remark-parse": "^11.0.0", "remark-rehype": "^11.1.1", "remark-toc": "^9.0.0", diff --git a/src/lib/markdown.ts b/src/lib/markdown.ts index b07fa78..1d0cddd 100644 --- a/src/lib/markdown.ts +++ b/src/lib/markdown.ts @@ -3,12 +3,13 @@ import type { BuiltinLanguage } from "shiki"; import { cacheOnce } from "./utils/cache"; import rehypeShiki from "@shikijs/rehype"; import rehypeStringify from "rehype-stringify"; +import remarkCjkFriendly from "remark-cjk-friendly/parseOnly"; import remarkParse from "remark-parse"; import remarkRehype from "remark-rehype"; import { unified } from "unified"; async function getProcessor(langs: BuiltinLanguage[] = []) { - return unified().use(remarkParse).use(remarkRehype).use(rehypeShiki, { theme: "vitesse-dark", langs }).use(rehypeStringify); + return unified().use(remarkParse).use(remarkCjkFriendly).use(remarkRehype).use(rehypeShiki, { theme: "vitesse-dark", langs }).use(rehypeStringify); } export async function renderMarkdown(text: string, langs: BuiltinLanguage[] = []) { diff --git a/svelte.config.js b/svelte.config.js index df5238e..1a9e343 100644 --- a/svelte.config.js +++ b/svelte.config.js @@ -4,10 +4,11 @@ import { mdsvex } from "mdsvex"; import rehypeAutolinkHeadings from "rehype-autolink-headings"; import rehypeSlug from "rehype-slug"; import rehypeUnwrapImages from "rehype-unwrap-images"; +import remarkCjkFriendly from "remark-cjk-friendly/parseOnly"; import remarkToc from "remark-toc"; /** @type {import("mdsvex").MdsvexOptions} */ -const mdsvexConfig = { extensions: [".svx"], smartypants: { dashes: "oldschool" }, remarkPlugins: [remarkToc], rehypePlugins: [rehypeUnwrapImages, rehypeSlug, [rehypeAutolinkHeadings, { behavior: "wrap" }]] }; +const mdsvexConfig = { extensions: [".svx"], smartypants: { dashes: "oldschool" }, remarkPlugins: [remarkCjkFriendly, remarkToc], rehypePlugins: [rehypeUnwrapImages, rehypeSlug, [rehypeAutolinkHeadings, { behavior: "wrap" }]] }; /** @type {import('@sveltejs/kit').Config} */ const config = {