[mastodon-client] Fix code block rendering

This doesn't work in all clients, but it works in more than the previous solution & matches what glitch-soc is doing.
This commit is contained in:
Laura Hausmann 2023-10-11 22:23:14 +02:00
parent efa2e501a4
commit be28fae40f
Signed by: zotan
GPG key ID: D044E84C5BE01605

View file

@ -68,7 +68,15 @@ export class MfmHelpers {
blockCode(node) {
const pre = doc.createElement("pre");
const inner = doc.createElement("code");
inner.textContent = node.props.code;
const nodes = node.props.code
.split(/\r\n|\r|\n/)
.map((x) => doc.createTextNode(x));
for (const x of intersperse<FIXME | "br">("br", nodes)) {
inner.appendChild(x === "br" ? doc.createElement("br") : x);
}
pre.appendChild(inner);
return pre;
},