LiamKhoaLe commited on
Commit
75a5481
·
1 Parent(s): 048b397

Enhance code presenter

Browse files
Files changed (2) hide show
  1. static/index.html +2 -0
  2. static/script.js +9 -0
static/index.html CHANGED
@@ -7,6 +7,7 @@
7
  <meta name="viewport" content="width=device-width, initial-scale=1">
8
  <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>📚</text></svg>">
9
  <link rel="stylesheet" href="/static/styles.css">
 
10
  </head>
11
  <body>
12
  <div class="app-container">
@@ -373,6 +374,7 @@
373
 
374
  <!-- Load markdown parser first so appendMessage can use it -->
375
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
 
376
  <script src="/static/auth.js"></script>
377
  <script src="/static/sidebar.js"></script>
378
  <script src="/static/projects.js"></script>
 
7
  <meta name="viewport" content="width=device-width, initial-scale=1">
8
  <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'><text y='.9em' font-size='90'>📚</text></svg>">
9
  <link rel="stylesheet" href="/static/styles.css">
10
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/styles/github-dark.min.css">
11
  </head>
12
  <body>
13
  <div class="app-container">
 
374
 
375
  <!-- Load markdown parser first so appendMessage can use it -->
376
  <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
377
+ <script src="https://cdn.jsdelivr.net/npm/highlight.js@11.9.0/lib/common.min.js"></script>
378
  <script src="/static/auth.js"></script>
379
  <script src="/static/sidebar.js"></script>
380
  <script src="/static/projects.js"></script>
static/script.js CHANGED
@@ -740,12 +740,21 @@
740
 
741
  function renderAssistantMarkdown(container, markdown, isReport) {
742
  try {
 
743
  const htmlContent = marked.parse(markdown);
744
  container.innerHTML = htmlContent;
745
  // Render Mermaid if present
746
  renderMermaidInElement(container);
747
  // Add copy buttons to code blocks
748
  addCopyButtonsToCodeBlocks(container);
 
 
 
 
 
 
 
 
749
  // Add download PDF button for reports
750
  if (isReport) addDownloadPdfButton(container, markdown);
751
  } catch (e) {
 
740
 
741
  function renderAssistantMarkdown(container, markdown, isReport) {
742
  try {
743
+ // Configure marked to keep code blocks for highlight.js
744
  const htmlContent = marked.parse(markdown);
745
  container.innerHTML = htmlContent;
746
  // Render Mermaid if present
747
  renderMermaidInElement(container);
748
  // Add copy buttons to code blocks
749
  addCopyButtonsToCodeBlocks(container);
750
+ // Syntax highlight code blocks
751
+ try {
752
+ container.querySelectorAll('pre code').forEach((block) => {
753
+ if (window.hljs && window.hljs.highlightElement) {
754
+ window.hljs.highlightElement(block);
755
+ }
756
+ });
757
+ } catch {}
758
  // Add download PDF button for reports
759
  if (isReport) addDownloadPdfButton(container, markdown);
760
  } catch (e) {