diff --git a/src/replace-links/__tests__/replace-links.url.test.ts b/src/replace-links/__tests__/replace-links.url.test.ts index 8554a16..23eedb6 100644 --- a/src/replace-links/__tests__/replace-links.url.test.ts +++ b/src/replace-links/__tests__/replace-links.url.test.ts @@ -44,6 +44,42 @@ describe("ignore url", () => { }); expect(result).toBe("- https://x.com/xxxx/status/12345?t=25S02Tda"); } + { + const { candidateMap, trie } = buildCandidateTrieForTest({ + files: [{ path: "http" }], + settings: { + restrictNamespace: false, + baseDir: undefined, + }, + }); + const result = await replaceLinks({ + body: "Hello https://claude.ai/chat/xxx", + linkResolverContext: { + filePath: "journals/2022-01-01", + trie, + candidateMap, + }, + }); + expect(result).toBe("Hello https://claude.ai/chat/xxx"); + } + { + const { candidateMap, trie } = buildCandidateTrieForTest({ + files: [{ path: "http" }], + settings: { + restrictNamespace: false, + baseDir: undefined, + }, + }); + const result = await replaceLinks({ + body: "こんにちは https://claude.ai/chat/xxx", + linkResolverContext: { + filePath: "journals/2022-01-01", + trie, + candidateMap, + }, + }); + expect(result).toBe("こんにちは https://claude.ai/chat/xxx"); + } }); it("multiple urls", async () => { diff --git a/src/replace-links/replace-links.ts b/src/replace-links/replace-links.ts index 21f310c..4957e12 100644 --- a/src/replace-links/replace-links.ts +++ b/src/replace-links/replace-links.ts @@ -43,9 +43,9 @@ export const replaceLinks = ({ parseInt(candidate, 10) >= 1 && parseInt(candidate, 10) <= 12; - // Regex to protect code blocks, inline code, wikilinks, and Markdown links. + // Regex to protect code blocks, inline code, wikilinks, Markdown links, and URLs. const protectedRegex = - /(```[\s\S]*?```|`[^`]*`|\[\[[^\]]+\]\]|\[[^\]]+\]\([^)]+\))/g; + /(```[\s\S]*?```|`[^`]*`|\[\[[^\]]+\]\]|\[[^\]]+\]\([^)]+\)|https?:\/\/[^\s]+)/g; // Normalize the body text to NFC. body = body.normalize("NFC");