Display lists.

This commit is contained in:
Danila Fedorin 2021-07-06 16:48:31 -07:00
parent 1da35be148
commit 49df21e465
2 changed files with 11 additions and 1 deletions

View file

@ -36,7 +36,7 @@ function parseLink(result, node, children) {
function parseList(result, node) {
let start = null;
if (result.getNodeElementName(node) == "OL") {
if (result.getNodeElementName(node) === "OL") {
// Will return 1 for, say, '1A', which may not be intended?
start = parseInt(result.getAttributeValue(node, "start")) || 1;
}

View file

@ -32,6 +32,15 @@ export class TextMessageView extends BaseMessageView {
}
}
function renderList(listBlock) {
const items = listBlock.items.map(item => tag.li({}, renderParts(item)));
const start = listBlock.startOffset;
if (start) {
return tag.ol({ start }, items);
} else {
return tag.ul({}, items);
}
}
/**
* Map from part to function that outputs DOM for the part
*/
@ -43,6 +52,7 @@ const formatFunction = {
text: textPart => text(textPart.text),
link: linkPart => tag.a({ href: linkPart.url, target: "_blank", rel: "noopener" }, renderParts(linkPart.inlines)),
format: formatPart => tag[formatPart.format]({}, renderParts(formatPart.children)),
list: renderList,
newline: () => tag.br()
};