fix(web): preserve code block text when lowlight auto-detect finds no match - #58
Merged
Merged
Conversation
… match lowlight.highlightAuto() returns an empty children array (not the raw text wrapped in a text node) when it can't confidently detect a language, so any code block left on "Auto" whose content has no strong language signal (e.g. a plain pip install line) exported to HTML with an empty <code> element. Fall back to the escaped source text whenever the highlighter produces no renderable nodes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The fallback preserves source text while retaining existing syntax highlighting behavior.
Pull request overview
Preserves code text during HTML export when lowlight auto-detection produces no renderable nodes.
Changes:
- Handles empty sources without invoking highlighting.
- Falls back to escaped source text when highlighting returns empty output.
File summaries
| File | Description |
|---|---|
packages/web/src/lib/export/documentExport.ts |
Adds safe fallback behavior for code block highlighting. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
<code>empty whenever a code block's language was "Auto" and the text had no strong language signal (e.g. a plainpip install ...line) —lowlight.highlightAuto()returns an emptychildrenarray in that case instead of the raw text.highlightCodeForExportnow falls back to the escaped source text whenever the highlighter (either the explicit-language or auto-detect path) produces no renderable nodes.Test plan
pip install numpy pandas transformers peft datasets)bash) still render with syntax highlighting🤖 Generated with Claude Code