diff --git a/tools/server/public_simplechat/simplechat.js b/tools/server/public_simplechat/simplechat.js
index 29924ad639..72008b936a 100644
--- a/tools/server/public_simplechat/simplechat.js
+++ b/tools/server/public_simplechat/simplechat.js
@@ -10,6 +10,7 @@ import * as du from "./datautils.mjs";
import * as ui from "./ui.mjs"
import * as mTools from "./tools.mjs"
import * as mIdb from "./idb.mjs"
+import * as mMD from "./typemd.mjs"
const TEMP_MARKER = "-TEMP"
@@ -1496,7 +1497,15 @@ class MultiChatUI {
}
for (const [name, content] of showList) {
if (content.length > 0) {
- entry = ui.el_create_append_p(`${content}`, secContents);
+ if (name == "content") {
+ entry = document.createElement('div')
+ let md = new mMD.MarkDown()
+ md.process(content)
+ entry.innerHTML = md.html
+ secContents.appendChild(entry)
+ } else {
+ entry = ui.el_create_append_p(`${content}`, secContents);
+ }
entry.classList.add(`chat-message-${name}`)
}
}
diff --git a/tools/server/public_simplechat/typemd.mjs b/tools/server/public_simplechat/typemd.mjs
new file mode 100644
index 0000000000..a1d3eab57e
--- /dev/null
+++ b/tools/server/public_simplechat/typemd.mjs
@@ -0,0 +1,58 @@
+//@ts-check
+// Helpers to handle markdown content
+// by Humans for All
+//
+
+
+export class MarkDown {
+
+ constructor() {
+ this.in = {
+ pre: false,
+ table: false,
+ }
+ this.md = ""
+ this.html = ""
+ }
+
+ /**
+ * Process a line from markdown content
+ * @param {string} line
+ */
+ process_line(line) {
+ let lineA = line.split(' ')
+ let lineRStripped = line.trimStart()
+ if (this.in.pre) {
+ if (lineA[0] == '```') {
+ this.in.pre = false
+ this.html += "\n"
+ } else {
+ this.html += line
+ }
+ return
+ }
+ if (line.startsWith ("#")) {
+ let hLevel = lineA[0].length
+ this.html += `
\n" + return + } + this.html += `${line}
` + } + + /** + * Process a bunch of lines in markdown format. + * @param {string} lines + */ + process(lines) { + let linesA = lines.split('\n') + for(const line of linesA) { + this.process_line(line) + } + } + +}