Fix fenced code block rendering issues (#36, #37)#272
Merged
Conversation
Extend the markdown preprocessor to insert blank lines before fenced code blocks (``` and ~~~) when they immediately follow text. This ensures Hoedown correctly recognizes them as code blocks. The regex uses a lookahead to only match OPENING fences (followed by content like a language specifier or code), not closing fences. The fix also resolves square bracket rendering issues inside code blocks, since properly recognized code blocks don't have their contents parsed for link syntax. Updates: - MPRenderer.m: Add fenceRegex to MPPreprocessMarkdown - regression-issue36.html: Update golden file to reflect correct output - MPMarkdownRenderingTests.m: Update test comment to mark as FIXED Related to #36 Related to #37
Contributor
Code Coverage ReportCurrent Coverage: 52.39% Coverage Details (Summary) |
2fb53a4 to
d232249
Compare
Extend the markdown preprocessor to insert zero-width space between ] and : inside fenced code blocks. This prevents Hoedown's is_ref() from matching TypeScript index signatures and similar patterns as reference link definitions. The fix finds fenced code block content and replaces `]: ` with `]\u200B: `. The ZWSP is invisible in rendered output and only affects copy-paste from the preview pane (not the editor). Related to #37
d232249 to
59c0563
Compare
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
Extends the markdown preprocessor to fix two related code block rendering issues:
[key: string]: any) vanishBoth fixes are minimal preprocessor additions (~25 lines total) that work around Hoedown parser limitations.
Related Issues
Related to #36
Related to #37
Technical Details
Issue #36 Fix: Insert blank lines before fenced code blocks
The lookahead
(?=\\S|\\n.)ensures only OPENING fences are matched (not closing fences).Issue #37 Fix: Break reference link pattern inside code blocks
This prevents Hoedown's
is_ref()from matching TypeScript index signatures as reference links. The ZWSP is invisible in rendered output and only affects copy-paste from the preview pane (not the editor).Known Limitations
Manual Testing Plan
<pre><code>block[key: string]: anypatternsFiles Changed
MacDown/Code/Document/MPRenderer.m- Add fenceRegex and blockRegex to preprocessorMacDownTests/Fixtures/regression-issue36.html- Update golden file for Fix code block formatting when no blank line before block #36MacDownTests/Fixtures/regression-issue37.html- Update golden file for Fix code block rendering with square brackets #37MacDownTests/MPMarkdownRenderingTests.m- Update test commentsplans/test_coverage_improvement_plan.md- Mark Fix code block formatting when no blank line before block #36, Fix code block rendering with square brackets #37 as fixedplans/xcuitest.md- Mark Fix code block formatting when no blank line before block #36, Fix code block rendering with square brackets #37 as fixed