feat: convert html AST nodes to text

This commit is contained in:
Paul Makles 2022-07-13 12:32:39 +01:00
parent 2214efe1bc
commit 4f3f6e26cf
3 changed files with 12 additions and 12 deletions

View file

@ -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,
})

View file

@ -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(/</g, "&lt;");
});
};
};

View file

@ -0,0 +1,10 @@
import { Plugin } from "unified";
import { visit } from "unist-util-visit";
export const remarkHtmlToText: Plugin = () => {
return (tree) => {
visit(tree, "html", (node: { type: string; value: string }) => {
node.type = "text";
});
};
};