feat: chat — les posts affichent le markdown rendu comme un document, code coloré #193
This commit is contained in:
+28
-3
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user