From: Kai Moritz Date: Sun, 12 Jul 2026 08:47:00 +0000 (+0000) Subject: Fix: -Tags wurden in APT-Code-Blöcken als Text angezeigt X-Git-Url: https://juplo.de/gitweb/?a=commitdiff_plain;h=1b0c63a31b566d07bdd5074952a4cfb740dfd5b8;p=website Fix: -Tags wurden in APT-Code-Blöcken als Text angezeigt Pass 2 in highlightBody matchte
...
und übergab dabei den ...-Wrapper ungefiltert als Code-Inhalt an Shiki. APT-generierte Blöcke haben die Struktur
...
(ohne Klasse), weshalb und im gerenderten Output sichtbar wurden. Fix: Neuer Pass 2 behandelt
...
ohne Klasse explizit. Pass 3 bleibt für bare
-Blöcke. Gemeinsame Detektionslogik in
detectAndHighlight() extrahiert.

Co-Authored-By: Claude Sonnet 4.6 
---

diff --git a/src/components/ProjectPage.astro b/src/components/ProjectPage.astro
index e723a128..ba14e397 100644
--- a/src/components/ProjectPage.astro
+++ b/src/components/ProjectPage.astro
@@ -44,8 +44,20 @@ async function toShiki(code: string, lang: string): Promise {
   }
 }
 
+async function detectAndHighlight(rawCode: string): Promise {
+  const code = decodeEntities(rawCode).trimEnd();
+  const detected = hljs.highlightAuto(code);
+  let lang = 'text';
+  if (detected.language && detected.relevance >= MIN_RELEVANCE && detected.language in bundledLanguages) {
+    lang = detected.language;
+  } else if (code.trimStart().startsWith('<')) {
+    lang = 'xml';
+  }
+  return toShiki(code, lang);
+}
+
 async function highlightBody(html: string): Promise {
-  // Pass 1: labeled Markdown blocks — 
...
+ // Pass 1: labeled blocks —
...
html = await replaceAsync( html, /
([\s\S]*?)<\/code><\/pre>/g,
@@ -59,21 +71,18 @@ async function highlightBody(html: string): Promise {
     }
   );
 
-  // Pass 2: unlabeled APT blocks — 
...
(no attributes) + // Pass 2: unlabeled blocks with code wrapper —
...
+ html = await replaceAsync( + html, + /
([\s\S]*?)<\/code><\/pre>/g,
+    async (_, rawCode) => detectAndHighlight(rawCode)
+  );
+
+  // Pass 3: plain APT blocks — 
...
(no attributes, no code wrapper) html = await replaceAsync( html, /
([\s\S]*?)<\/pre>/g,
-    async (_, rawCode) => {
-      const code = decodeEntities(rawCode).trimEnd();
-      const detected = hljs.highlightAuto(code);
-      let lang = 'text';
-      if (detected.language && detected.relevance >= MIN_RELEVANCE && detected.language in bundledLanguages) {
-        lang = detected.language;
-      } else if (code.trimStart().startsWith('<')) {
-        lang = 'xml';
-      }
-      return toShiki(code, lang);
-    }
+    async (_, rawCode) => detectAndHighlight(rawCode)
   );
 
   return html;