diff --git a/src/platform/web/ui/session/room/timeline/TextMessageView.js b/src/platform/web/ui/session/room/timeline/TextMessageView.js index 88d97b3f..9bad828e 100644 --- a/src/platform/web/ui/session/room/timeline/TextMessageView.js +++ b/src/platform/web/ui/session/room/timeline/TextMessageView.js @@ -36,18 +36,29 @@ export class TextMessageView extends BaseMessageView { * Map from part to function that outputs DOM for the part */ const formatFunction = { + header: headerBlock => tag["h" + Math.min(6,headerBlock.level)]({}, renderParts(headerBlock.inlines)), + codeblock: codeBlock => tag.pre({}, tag.code({}, text(codeBlock.text))), + emph: emphPart => tag.em({}, [renderPart(emphPart.wraps)]), + code: codePart => tag.code({}, text(codePart.text)), text: textPart => text(textPart.text), link: linkPart => tag.a({ href: linkPart.url, target: "_blank", rel: "noopener" }, [linkPart.text]), newline: () => tag.br() }; +function renderPart(part) { + const f = formatFunction[part.type]; + return f(part); +} + +function renderParts(parts) { + return Array.from(parts, renderPart); +} + class BodyView extends StaticView { render(t, messageBody) { const container = t.span(); for (const part of messageBody.parts) { - const f = formatFunction[part.type]; - const element = f(part); - container.appendChild(element); + container.appendChild(renderPart(part)); } return container; }