fix: SeText heading markdown rendering differently from web version#9907
fix: SeText heading markdown rendering differently from web version#9907divyanshu-patil wants to merge 1 commit into
Conversation
|
Hello @divyanshu-patil, Thanks for your pull request! A Core Committer will review your pull request soon. For code contributions, you can learn more about the review process here. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR updates the commonmark patch file ( ChangesCommonmark Patch Update
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
hello @enahum can you take a look at this PR, it overrides the default behaviour of the CommonMark but brings UI consistency across web and app version Thank you for you time ! |
|
@divyanshu-patil Thanks for the PR, but I think this fits better in https://github.com/mattermost/commonmark.js instead of a patch. @hmhealey thoughts? |
|
@enahum Fair point, but the CommonMark setext spec actually says:
So this behavior is spec-compliant, raising it in The real issue is that web doesn't match this behavior. Web uses hello
hello
---renders as: hello
|
Summary
This PR fixes a Markdown rendering inconsistency where setext headings (headings created by underlining a line with
---or===) were being rendered differently in the mobile app compared to the web app.Issue
Given input like:
The mobile parser (based on
commonmark) follows the strict CommonMark spec, which states that a setext underline converts the entire preceding paragraph into a heading — not just the line directly above the underline. Sincetext 1,text 2, andtext 3have no blank lines between them, the parser treats them as a single paragraph node, and that whole block becomes the heading.text 4is left as a separate paragraph.This does not match the web app's behavior, where only
text 3(the line immediately preceding the---) becomes the heading, andtext 1/text 2remain a normal paragraph.Root cause
In
blocks.js, the setext heading block-start handler assigns the entire accumulated paragraph string (container._string_content, which includes all prior lines) directly to the new heading node:Because
container._string_contentcontains every line collected in the paragraph so far ("text 1\ntext 2\ntext 3\n"), all of it gets wrapped in the heading, rather than isolating just the final line.Fix
container._string_contentinto individual lines and drop the trailing empty entry produced by the final line break.paragraphnode (with recalculatedsourcepos) and insert it into the tree immediately before the heading, preserving them as normal paragraph text instead of discarding them.Follow-up fix during testing
An initial version of the patch attempted to reassign the heading's
sourceposdirectly:This threw a runtime error because
sourceposonNodeis a getter-only property (backed internally by_sourcepos). The fix was updated to assign to the internal field instead:This resolves the crash while keeping the source position metadata accurate for the newly split heading and paragraph nodes.
Ticket Link
Checklist
E2E/Run(orE2E/Run-iOS/E2E/Run-Androidfor platform-specific runs).Device Information
This PR was tested on:
Screenshots
Web
Before
After
Release Note