Skip to content

Commit

Permalink
Replace dependency to improve browser bundle size
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Apr 23, 2023
1 parent e28098a commit f7a35ea
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
9 changes: 3 additions & 6 deletions packages/rehype-katex/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

/**
Expand Down Expand Up @@ -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
})
}
}
4 changes: 1 addition & 3 deletions packages/rehype-katex/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down

0 comments on commit f7a35ea

Please sign in to comment.