Repository navigation
fix(web): pasted URLs and paths keep their underscores #25264
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
base: main
Are you sure you want to change the base?
Changes from all commits
e9df446
f632bea
5d71b6c
b3c0b67
2e2111b
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 |
|---|---|---|
|
|
@@ -26,7 +26,14 @@ function pushSpan(spans: RichTextSpan[], text: string, marks: RichTextMark[]): v | |
| } | ||
| } | ||
|
|
||
| /** Words containing a slash or ending in a file extension are URLs, paths, or filenames. */ | ||
| const LITERAL_UNDERSCORE_WORD = /\/|\.[a-z][a-z0-9]*\W*$/i; | ||
|
|
||
| export function parseInlineMarkdown(text: string): RichTextSpan[] { | ||
| const literalWords = Array.from(text.matchAll(/\S+/g)).filter((word) => | ||
| LITERAL_UNDERSCORE_WORD.test(word[0]), | ||
| ); | ||
| let literalWord = 0; | ||
| const root: RichTextSpan[] = []; | ||
| const stack: { delimiter: string; mark: RichTextMark; spans: RichTextSpan[] }[] = []; | ||
| const current = () => stack.at(-1)?.spans ?? root; | ||
|
|
@@ -62,6 +69,15 @@ export function parseInlineMarkdown(text: string): RichTextSpan[] { | |
| } | ||
| let end = index; | ||
| while (text[end] === char) end += 1; | ||
| if (char === "_") { | ||
| let word = literalWords[literalWord]; | ||
| while (word && word.index + word[0].length <= index) word = literalWords[++literalWord]; | ||
| if (word && word.index <= index) { | ||
|
Contributor
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. 🟠 High When a path token ends with 🚀 Reply "fix it for me" or copy this AI Prompt for your agent: |
||
| pushSpan(current(), text.slice(index, end), []); | ||
| index = end; | ||
| continue; | ||
| } | ||
| } | ||
| const before = text[index - 1] ?? ""; | ||
| const after = text[end] ?? ""; | ||
| const canClose = before !== "" && !/\s/.test(before) && (char !== "_" || !/\w/.test(after)); | ||
|
|
||
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.
🔎 Supported by static analysis
Script executed:
Repository: pingdotgg/t3code
Length of output: 5561
Script executed:
Repository: pingdotgg/t3code
Length of output: 21027
Script executed:
Repository: pingdotgg/t3code
Length of output: 41090
Preserve filename-and-line references.
When
parseInlineMarkdownreceives__init__.py:42, the filename pattern does not match because the suffix ends with word characters. The leading__opens an unmatched bold span. Serialization then rewrites the value with bold markers. Treat line and optional column suffixes as part of the filename token, and add parser and draft round-trip regression cases.Suggested fix
"src/__test__.tsx", "edit __init__.py, then", + "__init__.py:42",Add a
roundTrip("__init__.py:42")assertion inapps/web/src/composer-rich-text-doc.test.ts.