-
Notifications
You must be signed in to change notification settings - Fork 0
Add copy current URL as markdown link on artifact page #68
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| /** | ||
| * Escape characters that would break a markdown inline link label. | ||
| */ | ||
| function escapeMarkdownLinkLabel(label: string): string { | ||
| return label.replace(/\\/g, "\\\\").replace(/\[/g, "\\[").replace(/\]/g, "\\]"); | ||
| } | ||
|
|
||
| /** | ||
| * Format a markdown inline link from a label and destination URL. | ||
| */ | ||
| export function formatMarkdownLink(label: string, href: string): string { | ||
| const trimmedLabel = label.trim() || href; | ||
| return `[${escapeMarkdownLinkLabel(trimmedLabel)}](${href})`; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When users copy a link for a supported arx/arx2 fragment that uses the base76 wire form, the fragment payload can contain literal Useful? React with 👍 / 👎. |
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,20 @@ | ||||||||||||||||||||||||||||||
| import { describe, expect, it } from "vitest"; | ||||||||||||||||||||||||||||||
| import { formatMarkdownLink } from "@/lib/markdown-link"; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| describe("formatMarkdownLink", () => { | ||||||||||||||||||||||||||||||
| it("formats a standard inline link", () => { | ||||||||||||||||||||||||||||||
| expect(formatMarkdownLink("Viewer bootstrap", "https://example.com/#agent-render=v1.plain.abc")).toBe( | ||||||||||||||||||||||||||||||
| "[Viewer bootstrap](https://example.com/#agent-render=v1.plain.abc)", | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| it("escapes brackets in the label", () => { | ||||||||||||||||||||||||||||||
| expect(formatMarkdownLink("Sprint [draft]", "https://example.com/")).toBe( | ||||||||||||||||||||||||||||||
| "[Sprint \\[draft\\]](https://example.com/)", | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| it("falls back to the URL when the label is blank", () => { | ||||||||||||||||||||||||||||||
| expect(formatMarkdownLink(" ", "https://example.com/")).toBe("[https://example.com/](https://example.com/)"); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
|
Comment on lines
+17
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||||||||||||||||||||||||||||||
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.
WARNING:
hrefis inserted into the markdown destination without escaping)or backslashes, so links with those characters can be rendered incorrectly or truncated by markdown parsers.Escaping the destination before formatting the link would make the helper safe for arbitrary URLs.
Reply with
@kilocode-bot fix itto have Kilo Code address this issue.