diff --git a/modules/web_api/static/css/styles.css b/modules/web_api/static/css/styles.css
index 78f3e4d..d4e3056 100644
--- a/modules/web_api/static/css/styles.css
+++ b/modules/web_api/static/css/styles.css
@@ -18,3 +18,43 @@ body {
min-height: 100vh;
min-height: -webkit-fill-available;
}
+
+/* Стилизация Markdown-контента ответов ассистента в стиле Gemini */
+.chat-markdown-content h1,
+.chat-markdown-content h2,
+.chat-markdown-content h3,
+.chat-markdown-content h4 {
+ font-weight: 700;
+ color: #0f172a;
+ margin-top: 0.85rem;
+ margin-bottom: 0.35rem;
+ font-size: 0.95rem;
+}
+.chat-markdown-content p {
+ margin-bottom: 0.45rem;
+}
+.chat-markdown-content p:last-child {
+ margin-bottom: 0;
+}
+.chat-markdown-content ul {
+ list-style-type: disc;
+ margin-left: 1.25rem;
+ margin-bottom: 0.5rem;
+}
+.chat-markdown-content ol {
+ list-style-type: decimal;
+ margin-left: 1.25rem;
+ margin-bottom: 0.5rem;
+}
+.chat-markdown-content li {
+ margin-bottom: 0.2rem;
+}
+.chat-markdown-content code:not([id^="code-block-"]) {
+ padding: 0.15rem 0.35rem;
+ border-radius: 0.375rem;
+ background-color: #f1f5f9;
+ color: #4338ca;
+ font-size: 0.825rem;
+ border: 1px solid #e2e8f0;
+ font-family: monospace;
+}
diff --git a/modules/web_api/static/index.html b/modules/web_api/static/index.html
index 2299a9b..8a6ca0f 100644
--- a/modules/web_api/static/index.html
+++ b/modules/web_api/static/index.html
@@ -248,6 +248,7 @@
+
diff --git a/modules/web_api/static/js/chat/messages.js b/modules/web_api/static/js/chat/messages.js
index 279197b..3389e9a 100644
--- a/modules/web_api/static/js/chat/messages.js
+++ b/modules/web_api/static/js/chat/messages.js
@@ -1,10 +1,116 @@
/**
* ===============================================================================
* FILE: modules/web_api/static/js/chat/messages.js
- * ROLE: Рендеринг пузырей сообщений пользователя, ассистента и индикатора загрузки.
+ * ROLE: Рендеринг сообщений на базе marked.js с поддержкой marked v4-v14+.
* ===============================================================================
*/
+function safeEscapeCode(str) {
+ if (!str) return '';
+ return String(str)
+ .replace(/&/g, '&')
+ .replace(//g, '>')
+ .replace(/"/g, '"')
+ .replace(/'/g, ''');
+}
+
+function renderMarkdownGemini(rawText) {
+ if (!rawText || typeof rawText !== 'string') return '';
+
+ if (typeof marked === 'undefined') {
+ return safeEscapeCode(rawText).replace(/\n/g, '
');
+ }
+
+ const renderer = new marked.Renderer();
+
+ // Переопределяем ТОЛЬКО блоки кода (совместимо со всеми версиями marked)
+ renderer.code = function(arg1, arg2) {
+ // Поддержка и старых версий (code, lang), и новых (token)
+ let code = '';
+ let lang = 'code';
+
+ if (typeof arg1 === 'object' && arg1 !== null) {
+ code = arg1.text || '';
+ lang = arg1.lang || 'code';
+ } else {
+ code = arg1 || '';
+ lang = arg2 || 'code';
+ }
+
+ const language = (lang || 'code').trim();
+ const blockId = 'code-block-' + Math.random().toString(36).substr(2, 9);
+
+ return `
+
${safeEscapeCode(code)}