Skip to content

Fix PDF/print margins: respect Page Setup, remove double margins#329

Merged
schuyler merged 1 commit into
mainfrom
claude/port-pr-1363-JDgTy
Feb 26, 2026
Merged

Fix PDF/print margins: respect Page Setup, remove double margins#329
schuyler merged 1 commit into
mainfrom
claude/port-pr-1363-JDgTy

Conversation

@schuyler

@schuyler schuyler commented Feb 26, 2026

Copy link
Copy Markdown
Owner

Summary

Port of MacDownApp/macdown PR #1363, adapted for MacDown 3000:

  • Removes hardcoded margins from printInfo in MPDocument.m — the method was overwriting all four margins (top/bottom 50pt, left/right 0pt) every time, making the File > Page Setup... dialog non-functional for margin control
  • Zeros out @media print body padding/margin in all 8 bundled CSS stylesheets (the original 6, plus GitHub Tomorrow.css and the centralized print.css which are MacDown 3000 additions)
  • Users can now control PDF export and print margins via File > Page Setup... (Cmd+Shift+P), with NSPrintInfo as the single source of truth

Changes beyond the original PR

The original PR touched 7 files (1 .m + 6 CSS). This port touches 9 files because MacDown 3000 has:

  • GitHub Tomorrow.css — a new theme stylesheet with the same padding: 2cm issue
  • Extensions/print.css — a centralized print stylesheet (from PR #1349 port) that also had padding: 2cm, which would compound with NSPrintInfo margins

GitHub-2020.css has no @media print block, so no changes needed there.

Test plan

  • Build the project
  • Open a markdown file, use File > Page Setup... to set custom margins
  • File > Export > PDF... — verify PDF reflects the configured margins
  • File > Print... — verify print preview shows the configured margins
  • Verify no double-margin compounding (margins should match Page Setup values)

Related to MacDownApp/macdown#1363

@github-actions

github-actions Bot commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Report

Current Coverage: 56.42%

Coverage Details (Summary)
Name                                                                                                                                   Coverage            
-------------------------------------------------------------------------------------------------------------------------------------- ------------------- 
MASPreferences.bundle                                                                                                                  0.00% (0/0)         
MacDown 3000.app                                                                                                                       59.71% (8167/13678) 
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Extension/NSColor+HTML.m                                                   94.05% (332/353)    
        +[NSColor(HTML) colorWithHexString:]                                                                                           94.12% (16/17)      
        +[NSColor(HTML) colorWithHTMLName:]                                                                                            89.13% (164/184)    
        __35+[NSColor(HTML) colorWithHTMLName:]_block_invoke                                                                           100.00% (152/152)   
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Document/MPAsset.m                                                         93.69% (104/111)    
        -[MPAsset typeName]                                                                                                            100.00% (3/3)       
        -[MPAsset defaultTypeName]                                                                                                     100.00% (3/3)       
        +[MPAsset assetWithURL:andType:]                                                                                               100.00% (3/3)       
        -[MPAsset initWithURL:andType:]                                                                                                87.50% (7/8)        
        -[MPAsset init]                                                                                                                100.00% (3/3)       
        -[MPAsset templateForOption:]                                                                                                  0.00% (0/6)         
        -[MPAsset htmlForOption:]                                                                                                      100.00% (28/28)     
        -[MPStyleSheet defaultTypeName]                                                                                                100.00% (3/3)       
        +[MPStyleSheet CSSWithURL:]                                                                                                    100.00% (3/3)       
        -[MPStyleSheet templateForOption:]                                                                                             100.00% (20/20)     
        -[MPScript defaultTypeName]                                                                                                    100.00% (3/3)       
        +[MPScript javaScriptWithURL:]                                                                                                 100.00% (3/3)       
        -[MPScript templateForOption:]                                                                                                 100.00% (20/20)     
        -[MPEmbeddedScript htmlForOption:]                                                                                             100.00% (5/5)       
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Utility/FileURLInlining.m                                                  26.60% (25/94)      
        +[FileURLInlining inlineFromIterable:]                                                                                         0.00% (0/11)        
        -[FileURLInlining initWithURL:]                                                                                                0.00% (0/6)         
        -[FileURLInlining init]                                                                                                        100.00% (3/3)       
        -[FileURLInlining inlineContent]                                                                                               0.00% (0/9)         
        -[FileURLInlining imageContent]                                                                                                0.00% (0/12)        
        +[FileURLInlining mimeTypeForFilePath:]                                                                                        100.00% (22/22)     
        -[FileURLInlining clippingContent]                                                                                             0.00% (0/4)         
        +[FileURLInlining isTextClippingAtPath:]                                                                                       0.00% (0/12)        
        +[FileURLInlining textContentFromClipping:]                                                                                    0.00% (0/15)        
    /Users/runner/work/macdown3000/macdown3000/Dependency/peg-markdown-highlight/HGMarkdownHighlightingStyle.m                         87.69% (57/65)      
        +[HGMarkdownHighlightingStyle colorFromARGBColor:]                                                                             100.00% (6/6)       
        -[HGMarkdownHighlightingStyle initWithType:attributesToAdd:toRemove:fontTraitsToAdd:]                                          88.89% (8/9)        
        -[HGMarkdownHighlightingStyle initWithStyleAttributes:baseFont:]                                                               86.00% (43/50)      
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Utility/MPResourceWatcherSet.m                                             87.10% (54/62)      
        -[MPResourceWatcherSet init]                                                                                                   100.00% (6/6)       
        -[MPResourceWatcherSet dealloc]                                                                                                0.00% (0/3)         
        -[MPResourceWatcherSet watchedPaths]                                                                                           100.00% (3/3)       
        -[MPResourceWatcherSet updateWatchedPaths:]                                                                                    100.00% (16/16)     
        -[MPResourceWatcherSet addWatcherForPath:]                                                                                     100.00% (18/18)     
        __42-[MPResourceWatcherSet addWatcherForPath:]_block_invoke                                                                    100.00% (6/6)       
        __42-[MPResourceWatcherSet addWatcherForPath:]_block_invoke.5                                                                  0.00% (0/5)         
        -[MPResourceWatcherSet stopAll]                                                                                                100.00% (5/5)       
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Extension/hoedown_html_patch.c                                             86.47% (115/133)    
        hoedown_patch_reset_checkbox_index                                                                                             100.00% (3/3)       
        hoedown_patch_get_checkbox_index                                                                                               0.00% (0/3)         
        hoedown_patch_render_blockcode                                                                                                 89.09% (49/55)      

... (2784 more lines truncated)

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

The printInfo method hardcoded all four margins (top/bottom 50pt, left/right
0pt), overriding whatever the user configured via File > Page Setup. This
made the Page Setup dialog effectively non-functional for margin control.

Additionally, all CSS stylesheets added body padding/margin of 2cm in their
@media print blocks, which compounded with the NSPrintInfo margins to create
unpredictable whitespace.

This commit:
- Removes hardcoded margin values from printInfo, allowing NSPrintInfo
  (controlled by Page Setup) to be the single source of truth
- Zeros out @media print body padding/margin in all 8 bundled stylesheets
  (including GitHub Tomorrow.css and the centralized print.css, which are
  MacDown 3000 additions beyond the original 6)

Users can now control PDF/print margins via File > Page Setup (Cmd+Shift+P).

Based on MacDownApp/macdown PR #1363.
Related to MacDownApp/macdown#1363
@schuyler schuyler force-pushed the claude/port-pr-1363-JDgTy branch from 0373225 to 3e234bc Compare February 26, 2026 20:05
@schuyler schuyler merged commit 78af4f1 into main Feb 26, 2026
7 of 9 checks passed
@schuyler schuyler deleted the claude/port-pr-1363-JDgTy branch February 26, 2026 22:34
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