mirror of
https://github.com/revoltchat/revite.git
synced 2024-11-22 07:00:58 -05:00
feat: convert html AST nodes to text
This commit is contained in:
parent
2214efe1bc
commit
4f3f6e26cf
3 changed files with 12 additions and 12 deletions
|
@ -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,
|
||||
})
|
||||
|
|
|
@ -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, "<");
|
||||
});
|
||||
};
|
||||
};
|
10
src/components/markdown/plugins/htmlToText.ts
Normal file
10
src/components/markdown/plugins/htmlToText.ts
Normal 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";
|
||||
});
|
||||
};
|
||||
};
|
Loading…
Reference in a new issue