From db202b23ae602665268df69e1728105134df3cf6 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 1 Jul 2021 00:45:46 -0700 Subject: [PATCH] Add some prototype rendering implementations. --- .../ui/session/room/timeline/TextMessageView.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) 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; }