Skip to content

Address issue #306: Make dollar-sign math highlighting conditional#317

Merged
schuyler merged 2 commits into
mainfrom
claude/issue-306-dollar-sign-highlighting-PvKjK
Feb 18, 2026
Merged

Address issue #306: Make dollar-sign math highlighting conditional#317
schuyler merged 2 commits into
mainfrom
claude/issue-306-dollar-sign-highlighting-PvKjK

Conversation

@schuyler

@schuyler schuyler commented Feb 18, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add pmh_EXT_MATH extension flag to PEG Markdown Highlight so dollar-sign math rules ($...$ and $$...$$) are only active when both MathJax and inline-dollar preferences are enabled
  • Constrain Dollar1Math to single-line matching so an unpaired $ only affects the current line, even with math enabled
  • Make $ a normal character (not SpecialChar) when math is disabled, preventing it from disrupting the highlighting state machine
  • Add htmlMathJax and htmlMathJaxInlineDollar to the editor KVO observation set so toggling preferences updates highlighting immediately

Related Issue

Related to #306

Manual Testing Plan

Prerequisites

  • macOS 10.14+, Xcode installed
  • Access MathJax preferences in Preferences > Rendering tab

Key Scenarios

# Scenario MathJax Inline $ Expected
1 Unpaired $ with math disabled Off Off No broken highlighting — $ treated as normal text
2 Unpaired $ with math enabled On On Damage confined to current line only
3 Paired $...$ inline math On On Highlighted as code; surrounding text unaffected
4 Multi-line $$...$$ display math On On Entire block highlighted as code across lines
5 Toggle preferences Toggle Toggle Highlighting updates immediately without reopening
6 MathJax on, inline dollar off On Off $ treated as plain text (math grammar inactive)
7 $ inside code blocks/spans On On Code formatting takes precedence

Add pmh_EXT_MATH extension flag to PEG Markdown Highlight so that
dollar-sign math rules ($...$ and $$...$$) are only active when the
user has enabled both MathJax and inline-dollar preferences. When math
is disabled, $ is treated as a normal character instead of a special
one, preventing unpaired dollar signs from disrupting syntax
highlighting.

Also constrain Dollar1Math to single-line matching so that even with
math enabled, an unpaired $ only affects the current line rather than
corrupting the entire document.

Related to #306
Without observing htmlMathJax and htmlMathJaxInlineDollar, toggling
these preferences in the UI would not trigger setupEditor: to update
the highlighter's extension flags. The math highlighting change would
only take effect incidentally when another preference change occurred.

Related to #306
@github-actions

github-actions Bot commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

Code Coverage Report

Current Coverage: 54.52%

Coverage Details (Summary)
Name                                                                                                                                   Coverage            
-------------------------------------------------------------------------------------------------------------------------------------- ------------------- 
MASPreferences.bundle                                                                                                                  0.00% (0/0)         
MacDown 3000.app                                                                                                                       59.02% (7858/13314) 
    /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/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)      
        hoedown_patch_render_listitem                                                                                                  100.00% (44/44)     
        hoedown_patch_render_toc_header                                                                                                67.86% (19/28)      
    /Users/runner/work/macdown3000/macdown3000/MacDown/Code/Application/MPMainController.m                                             42.91% (106/247)    
        MPOpenBundledFile                                                                                                              96.67% (29/30)      
        __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)        

... (2611 more lines truncated)

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

@schuyler schuyler merged commit 8fe8e8d into main Feb 18, 2026
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