Skip to content

Address issue #387: strip grey background from printed output#403

Merged
schuyler merged 1 commit into
mainfrom
claude/resolve-issue-387-Oe2Z5
Apr 22, 2026
Merged

Address issue #387: strip grey background from printed output#403
schuyler merged 1 commit into
mainfrom
claude/resolve-issue-387-Oe2Z5

Conversation

@schuyler

Copy link
Copy Markdown
Owner

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.css uses #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 print rules to MacDown/Resources/Extensions/print.css that force the page background to white and body text to black. print.css is already loaded after all theme CSS (see MPRenderer.m 534-670), so the !important rules cascade-override every theme.

Code block, table, blockquote, heading, and link rules are intentionally left alone — themes set their own color directly 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

  1. Build MacDown 3000 in Xcode.
  2. Open a markdown document containing H1-H3 headings, paragraphs, a blockquote, a fenced code block with syntax highlighting, inline code, a table, and a link. (The issue reporter's attached Test Document-Macdown 3000.md is a good candidate.)
  3. For each of the 8 bundled themes (cycle via View > Style):
    • File > Export > PDF... and open the result. Verify:
      • Page background is white (no grey/cream/dark fill)
      • Body paragraph text is dark/legible
      • Fenced code blocks retain their theme-specific pre background
      • Inline code retains its theme-specific background
      • Headings, links, and tables retain their theme colors
    • File > Print... — confirm print preview matches the PDF above.
  4. Regression check for PR Fix PDF/print margins: respect Page Setup, remove double margins #329: set custom margins via File > Page Setup..., export PDF, confirm margins are still honored.

Specific edge cases

  • Dark themes (Clearness Dark, GitHub Tomorrow, Github2 (dark), Solarized (Dark), GitHub-2020): body text was previously light → now black on white, legible.
  • Solarized themes' html body { ... } and html * { ... } selectors: body background is overridden by !important; html * color stays on headings/code/links (by direct application), which is the desired behaviour.

Review Notes

  • Architectural review (Plan agent) confirmed the cascade: all 8 themes use specificity 0-0-1 without !important on body background and color, so a plain !important in @media print defeats every one. Solarized's html body (0-0-2) also loses to !important. No theme sets a background on html or uses image/gradient backgrounds, but html, body is covered defensively.
  • Code review found no blocking issues and verified no element in any theme sets a dark opaque background while relying on inherited body text color (which would have become unreadable after forcing body color: #000).
  • No plans in plans/ describe print/PDF behaviour that this change contradicts, so no doc updates needed.

Generated by Claude Code

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
@github-actions

github-actions Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Report

Current Coverage: 60.46%

Coverage Details (Summary)
Name                                                                                                                                   Coverage            
-------------------------------------------------------------------------------------------------------------------------------------- ------------------- 
MASPreferences.bundle                                                                                                                  0.00% (0/0)         
MacDown 3000.app                                                                                                                       62.09% (8728/14057) 
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Document/MPDocument.m                                                      60.43% (1356/2244)  
        MPEditorPreferenceKeyWithValueKey                                                                                              85.71% (6/7)        
        MPEditorKeysToObserve                                                                                                          100.00% (15/15)     
        __MPEditorKeysToObserve_block_invoke                                                                                           100.00% (10/10)     
        MPEditorPreferencesToObserve                                                                                                   100.00% (14/14)     
        __MPEditorPreferencesToObserve_block_invoke                                                                                    100.00% (9/9)       
        MPRectStringForAutosaveName                                                                                                    100.00% (6/6)       
        MPAreNilableStringsEqual                                                                                                       100.00% (3/3)       
        MPGetWebViewBackgroundColor                                                                                                    0.00% (0/9)         
        -[NSURL(Convert) absoluteBaseURLString]                                                                                        0.00% (0/6)         
        -[WebView(Shortcut) enclosingScrollView]                                                                                       100.00% (3/3)       
        -[MPPreferences(Hoedown) extensionFlags]                                                                                       78.57% (22/28)      
        -[MPPreferences(Hoedown) rendererFlags]                                                                                        75.00% (9/12)       
        MPGetPreviewLoadingCompletionHandler                                                                                           100.00% (30/30)     
        __MPGetPreviewLoadingCompletionHandler_block_invoke                                                                            100.00% (27/27)     
        -[MPDocument preferences]                                                                                                      100.00% (3/3)       
        -[MPDocument markdown]                                                                                                         100.00% (3/3)       
        -[MPDocument setMarkdown:]                                                                                                     100.00% (3/3)       
        -[MPDocument html]                                                                                                             0.00% (0/3)         
        -[MPDocument toolbarVisible]                                                                                                   0.00% (0/3)         
        -[MPDocument previewVisible]                                                                                                   100.00% (3/3)       
        -[MPDocument editorVisible]                                                                                                    100.00% (3/3)       
        -[MPDocument needsHtml]                                                                                                        80.00% (4/5)        
        -[MPDocument setTotalWords:]                                                                                                   100.00% (7/7)       
        -[MPDocument setTotalCharacters:]                                                                                              100.00% (7/7)       
        -[MPDocument setTotalCharactersNoSpaces:]                                                                                      100.00% (8/8)       
        -[MPDocument setAutosaveName:]                                                                                                 100.00% (4/4)       
        -[MPDocument mathJaxRenderGeneration]                                                                                          100.00% (3/3)       
        -[MPDocument init]                                                                                                             90.00% (9/10)       
        -[MPDocument windowNibName]                                                                                                    100.00% (3/3)       
        -[MPDocument windowControllerDidLoadNib:]                                                                                      100.00% (105/105)   
        __41-[MPDocument windowControllerDidLoadNib:]_block_invoke                                                                     100.00% (3/3)       
        __41-[MPDocument windowControllerDidLoadNib:]_block_invoke.239                                                                 100.00% (15/15)     
        -[MPDocument reloadFromLoadedString]                                                                                           92.86% (13/14)      
        -[MPDocument close]                                                                                                            12.90% (4/31)       
        +[MPDocument autosavesInPlace]                                                                                                 100.00% (3/3)       
        +[MPDocument writableTypes]                                                                                                    100.00% (3/3)       
        -[MPDocument isDocumentEdited]                                                                                                 100.00% (5/5)       
        -[MPDocument writeToURL:ofType:error:]                                                                                         0.00% (0/28)        
        __38-[MPDocument writeToURL:ofType:error:]_block_invoke                                                                        0.00% (0/2)         
        __38-[MPDocument writeToURL:ofType:error:]_block_invoke.327                                                                    0.00% (0/3)         
        -[MPDocument dataOfType:error:]                                                                                                100.00% (3/3)       
        -[MPDocument readFromData:ofType:error:]                                                                                       100.00% (9/9)       
        -[MPDocument prepareSavePanel:]                                                                                                76.92% (30/39)      
        __31-[MPDocument prepareSavePanel:]_block_invoke                                                                               100.00% (12/12)     
        -[MPDocument printInfo]                                                                                                        0.00% (0/8)         

... (3168 more lines truncated)

📊 **Full coverage report available in workflow artifacts**

@schuyler schuyler merged commit 760c2aa into main Apr 22, 2026
8 of 9 checks passed
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.

2 participants