From f7a35ea4dade42ed6c731d440ac24444a2180b94 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Sun, 23 Apr 2023 15:04:44 +0200 Subject: [PATCH] Replace dependency to improve browser bundle size --- packages/rehype-katex/index.js | 9 +++------ packages/rehype-katex/package.json | 4 +--- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/packages/rehype-katex/index.js b/packages/rehype-katex/index.js index 58847e0..75188f0 100644 --- a/packages/rehype-katex/index.js +++ b/packages/rehype-katex/index.js @@ -5,15 +5,11 @@ import katex from 'katex' import {visit} from 'unist-util-visit' -import {removePosition} from 'unist-util-remove-position' import {toText} from 'hast-util-to-text' -import {unified} from 'unified' -import rehypeParse from 'rehype-parse' +import {fromHtmlIsomorphic} from 'hast-util-from-html-isomorphic' const assign = Object.assign -const parseHtml = unified().use(rehypeParse, {fragment: true}) - const source = 'rehype-katex' /** @@ -85,8 +81,9 @@ export default function rehypeKatex(options) { ) } + const root = fromHtmlIsomorphic(result, {fragment: true}) // @ts-expect-error: assume no `doctypes` in KaTeX result. - element.children = removePosition(parseHtml.parse(result), true).children + element.children = root.children }) } } diff --git a/packages/rehype-katex/package.json b/packages/rehype-katex/package.json index 106fb07..1c06217 100644 --- a/packages/rehype-katex/package.json +++ b/packages/rehype-katex/package.json @@ -40,11 +40,9 @@ "dependencies": { "@types/hast": "^2.0.0", "@types/katex": "^0.14.0", + "hast-util-from-html-isomorphic": "^1.0.0", "hast-util-to-text": "^3.1.0", "katex": "^0.16.0", - "rehype-parse": "^8.0.0", - "unified": "^10.0.0", - "unist-util-remove-position": "^4.0.0", "unist-util-visit": "^4.0.0" }, "scripts": {