fix: escape ambiguous Mfm marks from html

This commit is contained in:
Lhcfl 2024-05-01 11:47:14 +08:00
parent 1a46d1394c
commit a4a96f0026

View file

@ -19,6 +19,13 @@ export function fromHtml(html: string, hashtagNames?: string[]): string {
return appendChildren(childNodes, background).join("").trim();
}
/**
* We only exclude text containing asterisks, since the other marks can almost be considered intentionally used.
*/
function escapeAmbiguousMfmMarks(text: string) {
return text.includes("*") ? `<plain>${text}</plain>` : text;
}
/**
* Get only the text, ignoring all formatting inside
* @param node
@ -62,7 +69,7 @@ export function fromHtml(html: string, hashtagNames?: string[]): string {
background = "",
): (string | string[])[] {
if (treeAdapter.isTextNode(node)) {
return [node.value];
return [escapeAmbiguousMfmMarks(node.value)];
}
// Skip comment or document type node