Rehype plugin that compiles a hast tree to string using hast-util-to-text
Install plugin with
npm i rehype-to-text
Then use rehypeToText
as the last plugin in your unified
chain.
import { unified } from "unified";
import rehypeParse from "rehype-parse";
import rehypeToText from "rehype-to-text";
const plainText = (
await unified()
.use(rehypeParse, { fragment: true })
.use(rehypeToText, { whitespace: "pre" })
.process(myHtml)
).toString();