Address issue #387: strip grey background from printed output#403
Merged
Conversation
Themes set an explicit body background-color (e.g. GitHub.css uses
#F8F8F8) and also declare `* { -webkit-print-color-adjust: exact; }`,
which forces WebKit to preserve that background in printed output and
exported PDFs. The result is a grey page behind the text in File >
Print and File > Export > PDF.
Add @media print rules to Extensions/print.css (which loads after all
theme CSS, so its rules cascade-override) that force the page
background to white and body text to black. Code block, table,
blockquote, heading, and link rules are intentionally left alone so
syntax highlighting and visual distinction survive in print; all
themes set their own color on those elements, so the body-level
override does not leak via inheritance.
Related to #387
Contributor
Code Coverage ReportCurrent Coverage: 60.46% Coverage Details (Summary) |
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
Printed output and exported PDFs had a grey page behind the text because every bundled theme CSS sets a body
background-color(e.g.GitHub.cssuses#F8F8F8) and also declares* { -webkit-print-color-adjust: exact; }, which forces WebKit to preserve that background in print output instead of stripping it in its default "economy" mode.Fix this by adding
@media printrules toMacDown/Resources/Extensions/print.cssthat force the page background to white and body text to black.print.cssis already loaded after all theme CSS (seeMPRenderer.m534-670), so the!importantrules cascade-override every theme.Code block, table, blockquote, heading, and link rules are intentionally left alone — themes set their own
colordirectly on those elements, so the body-level override doesn't leak via inheritance. Syntax highlighting and visual distinction survive in print.Related Issue
Related to #387
Manual Testing Plan
Test Document-Macdown 3000.mdis a good candidate.)File > Export > PDF...and open the result. Verify:prebackgroundcoderetains its theme-specific backgroundFile > Print...— confirm print preview matches the PDF above.File > Page Setup..., export PDF, confirm margins are still honored.Specific edge cases
html body { ... }andhtml * { ... }selectors: body background is overridden by!important;html *color stays on headings/code/links (by direct application), which is the desired behaviour.Review Notes
!importanton body background and color, so a plain!importantin@media printdefeats every one. Solarized'shtml body(0-0-2) also loses to!important. No theme sets a background onhtmlor uses image/gradient backgrounds, buthtml, bodyis covered defensively.color: #000).plans/describe print/PDF behaviour that this change contradicts, so no doc updates needed.Generated by Claude Code