-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Update MarkdownBlock.tsx #4841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mrubens
merged 4 commits into
RooCodeInc:main
from
xyOz-dev:URLs-followed-by-periods-incorrectly-include-period-in-clickable-link
Jun 20, 2025
Merged
Update MarkdownBlock.tsx #4841
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
6798836
Update MarkdownBlock.tsx
xyOz-dev 7b87dc5
fix: correct URL handling in MarkdownBlock and add tests for trailing…
daniel-lxs bd2eb06
Fix URL punctuation rendering
xyOz-dev 78d0dbd
fix: improve URL handling in MarkdownBlock and update tests for trail…
daniel-lxs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
29 changes: 29 additions & 0 deletions
29
webview-ui/src/components/common/__tests__/MarkdownBlock.spec.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import React from "react" | ||
| import { render, screen } from "@testing-library/react" | ||
| import MarkdownBlock from "../MarkdownBlock" | ||
| import { vi } from "vitest" | ||
|
|
||
| vi.mock("@src/utils/vscode", () => ({ | ||
| vscode: { | ||
| postMessage: vi.fn(), | ||
| }, | ||
| })) | ||
|
|
||
| vi.mock("@src/context/ExtensionStateContext", () => ({ | ||
| useExtensionState: () => ({ | ||
| theme: "dark", | ||
| }), | ||
| })) | ||
|
|
||
| describe("MarkdownBlock", () => { | ||
| it("should correctly handle URLs with trailing punctuation", async () => { | ||
| const markdown = "Check out this link: https://example.com." | ||
| render(<MarkdownBlock markdown={markdown} />) | ||
|
|
||
| await (async () => { | ||
| const linkElement = screen.getByRole("link") | ||
| expect(linkElement).toHaveAttribute("href", "https://example.com") | ||
| expect(linkElement.textContent).toBe("https://example.com.") | ||
| }) | ||
| }) | ||
| }) | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it expected that the trailing period is part of the link text?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the expected behaviour is to show the punctuation in the chat block but link to it without a trailing ., So it seems to be correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didnt personally write the test, my original code just removed the trailing period, Dan updated it slightly.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, looks like the period is still visually inside of the link even though the href is correct.

IMO we should handle it like Github does 👇 (I don't feel strongly about stripping the https:// though)
Check out this link: https://example.com/.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I made it so that the actual text keeps the period instead of just removing all punctuation, since it might look weird if the model is doing something like
https://example1.com, https://example2.com, etc.and the punctuation is stripped.However what you are suggesting might be even better:

Keeping the punctuation without the link highlight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this test be failing now if it's fixed to behave like the above? Or am I confused?