initial attempt at converting html back to markdown

This commit is contained in:
Bruno Windels 2019-05-21 17:34:18 +02:00
parent ff61376c07
commit 5373007301

View file

@ -40,11 +40,25 @@ function parseHtmlMessage(html, room) {
switch (prefix) { switch (prefix) {
case "@": return new UserPillPart(resourceId, n.textContent, room.getMember(resourceId)); case "@": return new UserPillPart(resourceId, n.textContent, room.getMember(resourceId));
case "#": return new RoomPillPart(resourceId); case "#": return new RoomPillPart(resourceId);
default: return new PlainPart(n.textContent); default: {
if (href === n.textContent) {
return new PlainPart(n.textContent);
} else {
return new PlainPart(`[${n.textContent}](${href})`);
}
}
} }
} }
case "BR": case "BR":
return new NewlinePart("\n"); return new NewlinePart("\n");
case "EM":
return new PlainPart(`*${n.textContent}*`);
case "STRONG":
return new PlainPart(`**${n.textContent}**`);
case "PRE":
return new PlainPart(`\`\`\`${n.textContent}\`\`\``);
case "CODE":
return new PlainPart(`\`${n.textContent}\``);
default: default:
return new PlainPart(n.textContent); return new PlainPart(n.textContent);
} }