mirror of
https://github.com/kdnk/obsidian-automatic-linker.git
synced 2026-07-22 05:37:46 +00:00
fix: ignore urls in replace-links
This commit is contained in:
parent
a0b58d007f
commit
a6b9a4824c
2 changed files with 38 additions and 2 deletions
|
|
@ -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 () => {
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Reference in a new issue