wop commited on
Commit
a2c868f
Β·
verified Β·
1 Parent(s): 92dbb60

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +27 -5
templates/index.html CHANGED
@@ -1445,11 +1445,30 @@
1445
  SYNTAX HIGHLIGHTER (lightweight)
1446
  ═══════════════════════════════════════════════ */
1447
  function syntaxHighlight(code, lang) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1448
  const e = esc(code);
1449
  if (!lang || lang === 'text' || lang === 'plain') return e;
1450
  return e
1451
  // comments
1452
- .replace(/(\/\/[^\n]*|#[^\n]*|\/\*[\s\S]*?\*\/)/g, '<span class="tok-cmt">$1</span>')
1453
  // strings
1454
  .replace(/(["'`])((?:\\.|(?!\1)[^\\])*)\1/g, '<span class="tok-str">$1$2$1</span>')
1455
  // numbers
@@ -1459,7 +1478,7 @@
1459
  // function calls
1460
  .replace(/\b([a-zA-Z_]\w*)\s*(?=\()/g, '<span class="tok-fn">$1</span>')
1461
  // operators
1462
- .replace(/([=!<>&|+\-*/%^~]+)/g, '<span class="tok-op">$1</span>');
1463
  }
1464
 
1465
  /* ═══════════════════════════════════════════════
@@ -2606,9 +2625,12 @@
2606
  }
2607
 
2608
  function autoGrow(el) {
2609
- el.style.height = '0';
2610
- const next = Math.min(el.scrollHeight, 180) + 'px';
2611
- requestAnimationFrame(() => { el.style.height = next; });
 
 
 
2612
  }
2613
 
2614
  /* ═══════════════════════════════════════════════
 
1445
  SYNTAX HIGHLIGHTER (lightweight)
1446
  ═══════════════════════════════════════════════ */
1447
  function syntaxHighlight(code, lang) {
1448
+ // If the server already provided HTML-highlighted output (e.g. Pygments
1449
+ // rendered <span class="tok-..."> tokens), it may arrive as raw
1450
+ // markup or as escaped entities (&lt;span ...). In those cases we should
1451
+ // render the existing highlight rather than escaping it again.
1452
+ function decodeEntities(s) {
1453
+ return String(s)
1454
+ .replace(/&lt;/g, '<')
1455
+ .replace(/&gt;/g, '>')
1456
+ .replace(/&amp;/g, '&')
1457
+ .replace(/&quot;/g, '"')
1458
+ .replace(/&#39;/g, "'");
1459
+ }
1460
+
1461
+ // Quick heuristic: if code contains token spans (either raw or escaped),
1462
+ // decode/return as-is so markup renders correctly.
1463
+ if (/<span class=\"tok-/.test(code) || /&lt;span class=\"tok-/.test(code)) {
1464
+ return /&lt;span/.test(code) ? decodeEntities(code) : String(code);
1465
+ }
1466
+
1467
  const e = esc(code);
1468
  if (!lang || lang === 'text' || lang === 'plain') return e;
1469
  return e
1470
  // comments
1471
+ .replace(/(\/\/[^\n]*|#[^\n]*|\/\*[\s\S]*?\*\//g, '<span class="tok-cmt">$1</span>')
1472
  // strings
1473
  .replace(/(["'`])((?:\\.|(?!\1)[^\\])*)\1/g, '<span class="tok-str">$1$2$1</span>')
1474
  // numbers
 
1478
  // function calls
1479
  .replace(/\b([a-zA-Z_]\w*)\s*(?=\()/g, '<span class="tok-fn">$1</span>')
1480
  // operators
1481
+ .replace(/([=!<>\&|+\-*/%^~]+)/g, '<span class="tok-op">$1</span>');
1482
  }
1483
 
1484
  /* ═══════════════════════════════════════════════
 
2625
  }
2626
 
2627
  function autoGrow(el) {
2628
+ // Use 'auto' so browsers recalculate scrollHeight reliably, then
2629
+ // clamp to a sensible min/max so the compose area can shrink back.
2630
+ el.style.height = 'auto';
2631
+ let h = Math.min(el.scrollHeight, 180);
2632
+ if (h < 40) h = 40;
2633
+ requestAnimationFrame(() => { el.style.height = h + 'px'; });
2634
  }
2635
 
2636
  /* ═══════════════════════════════════════════════