Add parseInlineSegments function to fix links with formatting#3335
Open
juliaroldi wants to merge 2 commits intomasterfrom
Open
Add parseInlineSegments function to fix links with formatting#3335juliaroldi wants to merge 2 commits intomasterfrom
juliaroldi wants to merge 2 commits intomasterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the markdown-to-content-model inline parsing pipeline by replacing the previous split/link/formatting appliers with a single recursive inline parser, aiming to preserve formatting state across link boundaries (e.g. **[link](url)**) and simplify segment generation.
Changes:
- Replaced the old inline pipeline (
splitParagraphSegments+applyLink+applyTextFormatting) with a consolidated recursive parser (parseInlineSegments). - Updated
applySegmentFormattingto build segments viaparseInlineSegments, then apply heading adjustment to the first text segment. - Reworked test coverage by removing tests for deleted utilities/appliers and adding new
parseInlineSegmentstests plus new link-formatting cases inapplySegmentFormattingtests.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/roosterjs-content-model-markdown/test/markdownToModel/utils/splitParagraphSegmentsTest.ts | Removed tests for deleted splitParagraphSegments utility. |
| packages/roosterjs-content-model-markdown/test/markdownToModel/utils/parseInlineSegmentsTest.ts | Added unit tests for the new consolidated inline parser (formatting, links, images). |
| packages/roosterjs-content-model-markdown/test/markdownToModel/appliers/applyTextFormattingTest.ts | Removed tests for deleted applyTextFormatting applier. |
| packages/roosterjs-content-model-markdown/test/markdownToModel/appliers/applySegmentFormattingTest.ts | Added scenarios validating formatting behavior inside/around markdown links. |
| packages/roosterjs-content-model-markdown/test/markdownToModel/appliers/applyLinkTest.ts | Removed tests for deleted applyLink applier. |
| packages/roosterjs-content-model-markdown/lib/markdownToModel/utils/splitParagraphSegments.ts | Deleted old link/image splitting utility in favor of the new unified parser. |
| packages/roosterjs-content-model-markdown/lib/markdownToModel/utils/parseInlineSegments.ts | Added new recursive parser that produces Content Model segments directly (text/link/image + formatting state). |
| packages/roosterjs-content-model-markdown/lib/markdownToModel/appliers/applyTextFormatting.ts | Deleted old formatting-only applier, now superseded by parseInlineSegments. |
| packages/roosterjs-content-model-markdown/lib/markdownToModel/appliers/applySegmentFormatting.ts | Updated to use parseInlineSegments and apply heading adjustment to the first text segment. |
| packages/roosterjs-content-model-markdown/lib/markdownToModel/appliers/applyLink.ts | Deleted old link-only applier, now superseded by parseInlineSegments. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+71
to
+75
| const innerLink: ContentModelLink = { | ||
| dataset: {}, | ||
| format: { href: linkMatch[2], underline: true }, | ||
| }; | ||
| parseInlineSegments(linkMatch[1], segments, state, innerLink); |
Comment on lines
+82
to
+86
| if (marker && shouldToggleFormatting(text, i, marker, state)) { | ||
| flushBuffer(); | ||
| toggleFormatting(state, marker.type); | ||
| i += marker.length; | ||
| continue; |
Comment on lines
+55
to
+59
| while (i < text.length) { | ||
| const remaining = text.substring(i); | ||
|
|
||
| // Image:  | ||
| const imgMatch = imagePattern.exec(remaining); |
Comment on lines
+138
to
+142
| it('should parse formatting inside a link', () => { | ||
| runTest('[**bold**](https://example.com)', [ | ||
| { | ||
| segmentType: 'Text', | ||
| text: 'bold', |
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.
Consolidates the markdown inline-segment parsing logic into a single recursive parser, replacing the previous split between splitParagraphSegments, applyTextFormatting, and applyLink. This fixes a class of bugs where formatting state was not preserved across link/image boundaries (e.g. link), and simplifies the overall pipeline.