feat: chat — les posts affichent le markdown rendu comme un document, code coloré #193
CI / lint (push) Successful in 2m50s
CI / security (push) Successful in 1m37s
CI / test (push) Successful in 4m34s
CI / build (push) Successful in 1m31s
CI / e2e (push) Successful in 17m36s

This commit is contained in:
2026-10-09 15:48:04 -04:00
parent 4fb7c43e06
commit f4c8504c8d
17 changed files with 308 additions and 19 deletions
+28 -3
View File
@@ -12,7 +12,7 @@
import { api, AuthManager } from "./auth.js";
import { t } from "./i18n.js";
import { showToast, TabManager } from "./ui.js";
import { escapeHtml, safeCreateIcons } from "./utils.js";
import { escapeHtml, safeCreateIcons, safeHighlight } from "./utils.js";
import { icon } from "./viewer.js";
const PANEL_ID = "file-chat-panel";
@@ -147,7 +147,32 @@ async function _markRead(vault, path) {
}
// URL dans le texte → lien cliquable (partage d'URL #190), texte sinon.
function _fillBody(body, text) {
/**
* Remplit le corps d'un message (#193).
*
* Quand le serveur a fourni le rendu markdown (`html`, même pipeline que les
* documents : mistune + sanitizer BUG-021), on l'injecte dans un `.md-content`
* — titres, listes, tableaux, blocs de code — et on colore les blocs avec
* highlight.js (`safeHighlight`), exactement comme dans le viewer.
*
* Sans `html` (message optimiste d'un autre client, cache ancien), on retombe
* sur le texte brut avec liens cliquables, comme avant.
*/
function _fillBody(body, m) {
const text = typeof m === "string" ? m : (m && m.text) || "";
const html = m && typeof m === "object" ? m.html || "" : "";
if (html) {
body.classList.add("file-chat-md");
const div = document.createElement("div");
div.className = "md-content";
div.innerHTML = html; // rendu + assaini côté serveur
body.appendChild(div);
div.querySelectorAll("pre code").forEach((block) => {
if (block.querySelector(".secret-mask")) return;
safeHighlight(block);
});
return;
}
const parts = String(text || "").split(/(https?:\/\/[^\s<>"']+)/g);
parts.forEach((part) => {
if (!part) return;
@@ -341,7 +366,7 @@ export function _messageEl(m, currentUser, delUrl, readMap) {
}
const body = document.createElement("div");
body.className = "file-chat-body";
_fillBody(body, m.text);
_fillBody(body, m);
wrap.appendChild(meta);
if (m.text) wrap.appendChild(body);
const att = _attachEl(m.attachment);