mirror of
https://github.com/stoatchat/for-legacy-web.git
synced 2026-03-09 18:15:28 +00:00
feat: convert html AST nodes to text
This commit is contained in:
@@ -20,7 +20,7 @@ import { RenderCodeblock } from "./plugins/Codeblock";
|
|||||||
import { RenderAnchor } from "./plugins/anchors";
|
import { RenderAnchor } from "./plugins/anchors";
|
||||||
import { remarkChannels, RenderChannel } from "./plugins/channels";
|
import { remarkChannels, RenderChannel } from "./plugins/channels";
|
||||||
import { isOnlyEmoji, remarkEmoji, RenderEmoji } from "./plugins/emoji";
|
import { isOnlyEmoji, remarkEmoji, RenderEmoji } from "./plugins/emoji";
|
||||||
import { remarkHtmlEntities } from "./plugins/htmlEntities";
|
import { remarkHtmlToText } from "./plugins/htmlToText";
|
||||||
import { remarkMention, RenderMention } from "./plugins/mentions";
|
import { remarkMention, RenderMention } from "./plugins/mentions";
|
||||||
import { remarkSpoiler, RenderSpoiler } from "./plugins/spoiler";
|
import { remarkSpoiler, RenderSpoiler } from "./plugins/spoiler";
|
||||||
import { remarkTimestamps } from "./plugins/timestamps";
|
import { remarkTimestamps } from "./plugins/timestamps";
|
||||||
@@ -139,7 +139,7 @@ const render = unified()
|
|||||||
.use(remarkTimestamps)
|
.use(remarkTimestamps)
|
||||||
.use(remarkEmoji)
|
.use(remarkEmoji)
|
||||||
.use(remarkMention)
|
.use(remarkMention)
|
||||||
.use(remarkHtmlEntities)
|
.use(remarkHtmlToText)
|
||||||
.use(remarkRehype, {
|
.use(remarkRehype, {
|
||||||
handlers,
|
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";
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user