Skip to content

Fix preview pane Reload to re-render instead of loading raw markdown#204

Merged
schuyler merged 1 commit intomainfrom
issue-203-preview-reload-fix
Dec 6, 2025
Merged

Fix preview pane Reload to re-render instead of loading raw markdown#204
schuyler merged 1 commit intomainfrom
issue-203-preview-reload-fix

Conversation

@schuyler
Copy link
Copy Markdown
Owner

@schuyler schuyler commented Dec 6, 2025

Summary

  • Fixed the preview pane's right-click → Reload action to properly re-render markdown
  • Implemented WebUIDelegate method to intercept the Reload context menu item
  • Custom Reload action calls parseAndRenderNow instead of WebView's default reload

Related Issue

Related to #203

Root Cause

When loading HTML into the preview WebView via loadHTMLString:baseURL:, the base URL was set to the markdown file path. WebKit's default Reload action attempts to reload from this base URL, which returns the raw markdown file content instead of the rendered HTML.

Manual Testing Plan

  1. Open a markdown file with formatted content
  2. Verify preview shows rendered HTML
  3. Right-click the preview pane → select "Reload"
  4. Expected: Preview continues to show rendered HTML, not raw markdown

Edge cases:

  • Empty document: should not crash
  • Large document: should complete without delay
  • Multiple reloads: should remain stable
  • Reload during typing: should not cause race conditions

When users right-click the preview pane and select Reload, WebKit was
reloading from the base URL (the markdown file path), displaying raw
markdown instead of rendered HTML.

This fix intercepts the Reload context menu action via WebUIDelegate and
replaces it with a custom action that calls parseAndRenderNow to properly
re-render the preview.

Related to #203
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Dec 6, 2025

Code Coverage Report

Current Coverage: 42.56%

Coverage Details (Summary)
Name                                                                                                                                   Coverage            
-------------------------------------------------------------------------------------------------------------------------------------- ------------------- 
MASPreferences.bundle                                                                                                                  0.00% (0/0)         
MacDown 3000.app                                                                                                                       54.67% (6823/12480) 
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Utility/MPMathJaxListener.m                                                0.00% (0/26)        
        -[MPMathJaxListener callbacks]                                                                                                 0.00% (0/5)         
        -[MPMathJaxListener addCallback:forKey:]                                                                                       0.00% (0/3)         
        -[MPMathJaxListener invokeCallbackForKey:]                                                                                     0.00% (0/8)         
        +[MPMathJaxListener isSelectorExcludedFromWebScript:]                                                                          0.00% (0/5)         
        +[MPMathJaxListener isKeyExcludedFromWebScript:]                                                                               0.00% (0/5)         
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Extension/DOMNode+Text.m                                                   0.00% (0/94)        
        -[NSString(WordCount) numberOfWords]                                                                                           0.00% (0/11)        
        __36-[NSString(WordCount) numberOfWords]_block_invoke                                                                          0.00% (0/3)         
        -[NSString(WordCount) lengthWithoutNewlines]                                                                                   0.00% (0/11)        
        __44-[NSString(WordCount) lengthWithoutNewlines]_block_invoke                                                                  0.00% (0/3)         
        -[NSString(WordCount) lengthWithoutWhitespacesAndNewlines]                                                                     0.00% (0/11)        
        __58-[NSString(WordCount) lengthWithoutWhitespacesAndNewlines]_block_invoke                                                    0.00% (0/3)         
        MPGetChildrenNodetextCount                                                                                                     0.00% (0/6)         
        MPGetNodeTextCount                                                                                                             0.00% (0/38)        
        -[DOMNode(Text) textCount]                                                                                                     0.00% (0/8)         
    /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/MPPlugIn.m                                                         0.00% (0/36)        
        -[MPPlugIn setName:]                                                                                                           0.00% (0/3)         
        -[MPPlugIn initWithBundle:]                                                                                                    0.00% (0/24)        
        -[MPPlugIn plugInDidInitialize]                                                                                                0.00% (0/4)         
        -[MPPlugIn run:]                                                                                                               0.00% (0/5)         
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Extension/hoedown_html_patch.c                                             73.64% (95/129)     
        hoedown_patch_render_blockcode                                                                                                 89.09% (49/55)      
        hoedown_patch_render_listitem                                                                                                  100.00% (46/46)     
        hoedown_patch_render_toc_header                                                                                                0.00% (0/28)        
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Application/MPMainController.m                                             40.76% (97/238)     
        MPOpenBundledFile                                                                                                              95.24% (20/21)      
        __MPOpenBundledFile_block_invoke                                                                                               85.71% (6/7)        
        treat                                                                                                                          20.00% (6/30)       
        __treat_block_invoke                                                                                                           0.00% (0/3)         
        -[MPMainController applicationDidFinishLaunching:]                                                                             100.00% (6/6)       
        -[MPMainController openUrlSchemeAppleEvent:withReplyEvent:]                                                                    0.00% (0/45)        
        __59-[MPMainController openUrlSchemeAppleEvent:withReplyEvent:]_block_invoke                                                   0.00% (0/7)         
        -[MPMainController valueForKey:fromQueryItems:]                                                                                0.00% (0/5)         
        -[MPMainController preferences]                                                                                                100.00% (3/3)       
        -[MPMainController preferencesWindowController]                                                                                0.00% (0/18)        
        -[MPMainController showPreferencesWindow:]                                                                                     0.00% (0/2)         
        -[MPMainController showHelp:]                                                                                                  100.00% (3/3)       
        -[MPMainController showContributing:]                                                                                          100.00% (3/3)       
        -[MPMainController init]                                                                                                       90.91% (10/11)      
        -[MPMainController applicationShouldOpenUntitledFile:]                                                                         80.00% (4/5)        
        -[MPMainController applicationDidBecomeActive:]                                                                                100.00% (5/5)       

... (2122 more lines truncated)

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

@schuyler schuyler merged commit 70b5b4d into main Dec 6, 2025
4 checks passed
@schuyler schuyler deleted the issue-203-preview-reload-fix branch December 6, 2025 23:53
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.

1 participant