Spaces:
Running
Running
arterm-sedov commited on
Commit ·
08ca8ef
1
Parent(s): 8057706
Supported mermaid diagrams in HTML export
Browse files
agent_ng/tabs/chat_tab.py
CHANGED
|
@@ -1239,7 +1239,7 @@ class ChatTab(QuickActionsMixin):
|
|
| 1239 |
# Load CSS from external file
|
| 1240 |
css_content = self._load_export_css()
|
| 1241 |
|
| 1242 |
-
# Create HTML with
|
| 1243 |
html_content = f"""<!DOCTYPE html>
|
| 1244 |
<html lang="en">
|
| 1245 |
<head>
|
|
@@ -1249,6 +1249,33 @@ class ChatTab(QuickActionsMixin):
|
|
| 1249 |
<style>
|
| 1250 |
{css_content}
|
| 1251 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1252 |
</head>
|
| 1253 |
<body>
|
| 1254 |
<div class="content">
|
|
|
|
| 1239 |
# Load CSS from external file
|
| 1240 |
css_content = self._load_export_css()
|
| 1241 |
|
| 1242 |
+
# Create HTML with CSS styling and Mermaid support
|
| 1243 |
html_content = f"""<!DOCTYPE html>
|
| 1244 |
<html lang="en">
|
| 1245 |
<head>
|
|
|
|
| 1249 |
<style>
|
| 1250 |
{css_content}
|
| 1251 |
</style>
|
| 1252 |
+
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
|
| 1253 |
+
<script>
|
| 1254 |
+
document.addEventListener('DOMContentLoaded', function () {{
|
| 1255 |
+
if (window.mermaid) {{
|
| 1256 |
+
try {{
|
| 1257 |
+
mermaid.initialize({{ startOnLoad: false, securityLevel: 'loose' }});
|
| 1258 |
+
// Transform fenced code blocks with language-mermaid into mermaid containers
|
| 1259 |
+
const mermaidCodes = document.querySelectorAll('pre > code.language-mermaid');
|
| 1260 |
+
mermaidCodes.forEach(function(codeEl) {{
|
| 1261 |
+
const graphDefinition = codeEl.textContent || '';
|
| 1262 |
+
const preEl = codeEl.parentElement;
|
| 1263 |
+
const container = document.createElement('div');
|
| 1264 |
+
container.className = 'mermaid';
|
| 1265 |
+
container.textContent = graphDefinition;
|
| 1266 |
+
if (preEl) {{
|
| 1267 |
+
preEl.replaceWith(container);
|
| 1268 |
+
}}
|
| 1269 |
+
}});
|
| 1270 |
+
// Render all mermaid diagrams
|
| 1271 |
+
mermaid.run();
|
| 1272 |
+
}} catch (e) {{
|
| 1273 |
+
// Non-fatal: if Mermaid fails, leave code blocks as-is
|
| 1274 |
+
console && console.warn && console.warn('Mermaid render failed:', e);
|
| 1275 |
+
}}
|
| 1276 |
+
}}
|
| 1277 |
+
}});
|
| 1278 |
+
</script>
|
| 1279 |
</head>
|
| 1280 |
<body>
|
| 1281 |
<div class="content">
|
resources/css/html_export_theme.css
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
/* CMW Platform Agent - HTML Export Theme */
|
| 2 |
/* ====================================== */
|
| 3 |
-
/*
|
| 4 |
|
| 5 |
:root {
|
| 6 |
/* CMW Brand Colors */
|
|
|
|
| 1 |
/* CMW Platform Agent - HTML Export Theme */
|
| 2 |
/* ====================================== */
|
| 3 |
+
/* Styling for exported conversation HTML files */
|
| 4 |
|
| 5 |
:root {
|
| 6 |
/* CMW Brand Colors */
|