Skip to content

feat(preview): improve reader code block rendering - #30

Merged
phatpham9 merged 2 commits into
mainfrom
feat/preview-code-blocks
Nov 22, 2026
Merged

phatpham9 merged 2 commits into
mainfrom
feat/preview-code-blocks

Conversation

@phatpham9

Copy link
Copy Markdown
Member

Summary

Reader-preview code blocks now keep their language hint and render as a proper code block instead of a wrapped <pre> that leaks nested markup.

 extractBlocks
   PRE
-    text: pre.textContent            # raw; includes <code class="…"> markup
+    text: pre.textContent            # children parsed; entities decoded
+    language: language-*/lang-*
+                or highlight-source-* (GitHub)
+                or Markdown fence info

 renderPreviewBlocks
+  renderPreviewCodeBlock
+    header
+      language label (when known)
+      Copy → Copied / Copy failed
+    pre
+      code (textContent)
  • node-html-parser treats <pre> as raw text; parsing its children fixes nested <code> markup and &lt; entities leaking into preview text.
  • The Markdown fallback carries the fence info string (tsx title="app.tsx" → tsx).
  • Long lines scroll horizontally; copy reuses the existing clipboard fallback.

Evidence

  • Before: <pre><code class="language-ts">const x = 1;</code></pre> extracted as the literal text <code class="language-ts">const x = 1;</code>, with no label or copy action.
    After: extracted as const x = 1; with language: "ts". Local preview of cloudflare/security-audit-skill rendered SHELL labels, right-aligned Copy buttons, and Copied feedback.
  • Tests: npm test — 30 files, 238 tests passed. npm run typecheck — clean. New assertions cover HTML classes, GitHub highlight-source-* wrappers, Markdown fence info, and fence options.

Merge Danger

Door: two-way — reverting restores the previous renderer.

Blast Radius: preview rendering

Previews cached before deploy keep the old literal-tag text for up to 30 minutes; labels and the new layout appear as those entries refresh. The code-block payload gains an optional language field, which older clients ignore.

🤖 Generated with Claude Code

- Parse <pre> children so nested <code> markup and entities no longer leak
  into extracted code text.
- Keep language hints from language-*/lang-* classes, GitHub highlight-source
  wrappers, and Markdown fence info strings.
- Render code blocks with a language label, copy button, and horizontal
  scrolling for long lines.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@github-actions

github-actions Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

🔎 Cloudflare preview: https://36315d02-feedreader.phatpham9.workers.dev

Uploaded from 1f991da4625a501dff9c2ae08428c75f05f0bfb5. This is a Worker version preview — it shares the production D1 database, so it reads/writes real data; it does not receive cron-triggered refreshes.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@phatpham9
phatpham9 merged commit eeca919 into main Nov 22, 2026
3 checks passed
@phatpham9
phatpham9 deleted the feat/preview-code-blocks branch November 22, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant