Repository navigation
fix(desktop): wrap long code-block lines when exporting to PDF (#5307) - #5460
Merged
Merged
Conversation
The `@media print` rule that wraps code blocks selected `pre code.fenced-code-block` — a class only the legacy muyajs renderer emitted. @muyajs/core renders fences through marked, which emits `<pre><code class="language-*">` (or no class at all), so the rule stopped matching and the code text kept `white-space: pre` from github-markdown-css (`pre > code`) and the prism theme (`code[class*="language-"]`). Long lines then ran off the page: the exported PDF showed `pre`'s `overflow: auto` scrollbar with the tail of the line unreachable. Select any `pre code` inside the printed article instead, which covers both the highlighted fences and the language-less ones. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Closed
1 task done
Contributor
|
Build artifacts for PR #5460: Run: https://github.com/marktext/marktext/actions/runs/35448360165
|
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.
Fixes #5307.
Problem
A fenced code block with a long line is cut off in the exported PDF: the page shows the code block's scrollbar, but the rest of the line is simply not on the paper (and cannot be scrolled to or copied).
Reproduced on
developby exportingthrough the real app (Playwright +
File › Export › PDF), which produced exactly the PDF in the issue — the line ends atncurses-devewith a scrollbar underneath.Cause
printService.csswraps printed code blocks withfenced-code-blockis a class only the legacymuyajsrenderer emitted. Exports now go through@muyajs/core, which renders fences with marked and emits<pre><code class="language-*">— or a bare<code>when the fence has no language. The rule therefore matches nothing, and the element that actually carries the text keepswhite-space: prefrom github-markdown-css (.markdown-body pre > code) and from the prism theme (code[class*="language-"]). The engine's own.markdown-body pre { white-space: pre-wrap }cannot help, becausewhite-spaceapplies per element and the inner<code>overrides it;.markdown-body pre { overflow: auto }then renders the scrollbar seen in the PDF.Fix
Select any
pre codeinside the printed article, which covers both highlighted fences and language-less ones. Wrapping stays unconditional for PDF/print — a printed page cannot be scrolled — matching the pre-migration behaviour.Verification
print-code-wrap.spec.tsrenders a fence through the real@muyajs/coreexport path, feeds it to the realMarkdownPrintcontainer, and asserts the@media printwrap selectors match the emitted<code>(both with and without a language). It fails ondevelopand passes with this change.ncurses-deve; after the change the full line wraps onto a second row ending inmake gcc.pnpm run lint(0 errors),pnpm run typecheck,pnpm run test:unit(822 passing).🤖 Generated with Claude Code