Split up bodyToHtml (#12840)

* Split up bodyToHtml

This (very incrementally) splits up the bodyToHtml function to avoid
the multiple return types and hopefully make it a touch easier to
comprehend. I'd also like to see what the test coverage says about
this, so this is is somewhat experimental. This shouldn't change
any behaviour but the comments in this function indiciate just how
subtle it is.

* Remove I prefix

* Missed emoji formatting part
This commit is contained in:
David Baker 2024-07-30 14:35:16 +01:00 committed by GitHub
parent 66a89d8a84
commit 272a66baa5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 80 additions and 71 deletions

View file

@ -22,7 +22,7 @@ import { IContent } from "matrix-js-sdk/src/matrix";
import { logger } from "matrix-js-sdk/src/logger";
import { unescape } from "lodash";
import { bodyToHtml, checkBlockNode, IOptsReturnString } from "../HtmlUtils";
import { bodyToHtml, checkBlockNode, EventRenderOpts } from "../HtmlUtils";
function textToHtml(text: string): string {
const container = document.createElement("div");
@ -31,9 +31,8 @@ function textToHtml(text: string): string {
}
function getSanitizedHtmlBody(content: IContent): string {
const opts: IOptsReturnString = {
const opts: EventRenderOpts = {
stripReplyFallback: true,
returnString: true,
};
if (content.format === "org.matrix.custom.html") {
return bodyToHtml(content, null, opts);