Skip to content

Commit f7a35ea

Browse files
committed
Replace dependency to improve browser bundle size
1 parent e28098a commit f7a35ea

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

packages/rehype-katex/index.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55

66
import katex from 'katex'
77
import {visit} from 'unist-util-visit'
8-
import {removePosition} from 'unist-util-remove-position'
98
import {toText} from 'hast-util-to-text'
10-
import {unified} from 'unified'
11-
import rehypeParse from 'rehype-parse'
9+
import {fromHtmlIsomorphic} from 'hast-util-from-html-isomorphic'
1210

1311
const assign = Object.assign
1412

15-
const parseHtml = unified().use(rehypeParse, {fragment: true})
16-
1713
const source = 'rehype-katex'
1814

1915
/**
@@ -85,8 +81,9 @@ export default function rehypeKatex(options) {
8581
)
8682
}
8783

84+
const root = fromHtmlIsomorphic(result, {fragment: true})
8885
// @ts-expect-error: assume no `doctypes` in KaTeX result.
89-
element.children = removePosition(parseHtml.parse(result), true).children
86+
element.children = root.children
9087
})
9188
}
9289
}

packages/rehype-katex/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@
4040
"dependencies": {
4141
"@types/hast": "^2.0.0",
4242
"@types/katex": "^0.14.0",
43+
"hast-util-from-html-isomorphic": "^1.0.0",
4344
"hast-util-to-text": "^3.1.0",
4445
"katex": "^0.16.0",
45-
"rehype-parse": "^8.0.0",
46-
"unified": "^10.0.0",
47-
"unist-util-remove-position": "^4.0.0",
4846
"unist-util-visit": "^4.0.0"
4947
},
5048
"scripts": {

0 commit comments

Comments
 (0)