From 4f3f6e26cf4dd62c883850020fd34f81b8d1eacf Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Wed, 13 Jul 2022 12:32:39 +0100 Subject: [PATCH] feat: convert html AST nodes to text --- src/components/markdown/RemarkRenderer.tsx | 4 ++-- src/components/markdown/plugins/htmlEntities.ts | 10 ---------- src/components/markdown/plugins/htmlToText.ts | 10 ++++++++++ 3 files changed, 12 insertions(+), 12 deletions(-) delete mode 100644 src/components/markdown/plugins/htmlEntities.ts create mode 100644 src/components/markdown/plugins/htmlToText.ts diff --git a/src/components/markdown/RemarkRenderer.tsx b/src/components/markdown/RemarkRenderer.tsx index fff898ec..e3b2f3d6 100644 --- a/src/components/markdown/RemarkRenderer.tsx +++ b/src/components/markdown/RemarkRenderer.tsx @@ -20,7 +20,7 @@ import { RenderCodeblock } from "./plugins/Codeblock"; import { RenderAnchor } from "./plugins/anchors"; import { remarkChannels, RenderChannel } from "./plugins/channels"; import { isOnlyEmoji, remarkEmoji, RenderEmoji } from "./plugins/emoji"; -import { remarkHtmlEntities } from "./plugins/htmlEntities"; +import { remarkHtmlToText } from "./plugins/htmlToText"; import { remarkMention, RenderMention } from "./plugins/mentions"; import { remarkSpoiler, RenderSpoiler } from "./plugins/spoiler"; import { remarkTimestamps } from "./plugins/timestamps"; @@ -139,7 +139,7 @@ const render = unified() .use(remarkTimestamps) .use(remarkEmoji) .use(remarkMention) - .use(remarkHtmlEntities) + .use(remarkHtmlToText) .use(remarkRehype, { handlers, }) diff --git a/src/components/markdown/plugins/htmlEntities.ts b/src/components/markdown/plugins/htmlEntities.ts deleted file mode 100644 index eae15f49..00000000 --- a/src/components/markdown/plugins/htmlEntities.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Plugin } from "unified"; -import { visit } from "unist-util-visit"; - -export const remarkHtmlEntities: Plugin = () => { - return (tree) => { - visit(tree, "text", (node: { value: string }) => { - node.value = node.value.replace(/ { + return (tree) => { + visit(tree, "html", (node: { type: string; value: string }) => { + node.type = "text"; + }); + }; +};