Skip to content

Commit 8c7fe7b

Browse files
authored
uniorg-parse: match [[..]] link type with ^ (#153)
1 parent 71f7546 commit 8c7fe7b

4 files changed

Lines changed: 48 additions & 1 deletion

File tree

.changeset/quiet-rooms-clap.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"uniorg-parse": patch
3+
---
4+
5+
Fix link type detection in `[[ ]]` links when protocol name occurs in the middle of the URL.
6+
7+
Previously, `[[my-link:https://blah]]` was incorrectly detected as `https` link type. Now it's correctly recognized as `fuzzy` link type.

packages/uniorg-parse/src/__snapshots__/parser.spec.ts.snap

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,6 +2549,24 @@ children:
25492549
children: []
25502550
`;
25512551
2552+
exports[`org/parser > links > custom type wrapping a url 1`] = `
2553+
type: "org-data"
2554+
contentsBegin: 0
2555+
contentsEnd: 28
2556+
children:
2557+
- type: "paragraph"
2558+
affiliated: {}
2559+
contentsBegin: 0
2560+
contentsEnd: 28
2561+
children:
2562+
- type: "link"
2563+
format: "bracket"
2564+
linkType: "fuzzy"
2565+
rawLink: "card:https://example.com"
2566+
path: "card:https://example.com"
2567+
children: []
2568+
`;
2569+
25522570
exports[`org/parser > links > file link with percents 1`] = `
25532571
type: "org-data"
25542572
contentsBegin: 0
@@ -2603,6 +2621,24 @@ children:
26032621
children: []
26042622
`;
26052623
2624+
exports[`org/parser > links > leading whitespace is not a link type 1`] = `
2625+
type: "org-data"
2626+
contentsBegin: 0
2627+
contentsEnd: 24
2628+
children:
2629+
- type: "paragraph"
2630+
affiliated: {}
2631+
contentsBegin: 0
2632+
contentsEnd: 24
2633+
children:
2634+
- type: "link"
2635+
format: "bracket"
2636+
linkType: "fuzzy"
2637+
rawLink: " https://example.com"
2638+
path: " https://example.com"
2639+
children: []
2640+
`;
2641+
26062642
exports[`org/parser > links > link 1`] = `
26072643
type: "org-data"
26082644
contentsBegin: 0

packages/uniorg-parse/src/parser.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,10 @@ I have no :END:`
480480

481481
itParses('https link', `[[https://example.com/hello]]`);
482482

483+
itParses('custom type wrapping a url', `[[card:https://example.com]]`);
484+
485+
itParses('leading whitespace is not a link type', `[[ https://example.com]]`);
486+
483487
itParses(
484488
'multiline description',
485489
`[[www.something.com][line1

packages/uniorg-parse/src/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2351,7 +2351,7 @@ class Parser {
23512351
return { linkType: 'file', path: link };
23522352
}
23532353
// Explicit type (http, irc, bbdb...).
2354-
const m = link.match(new RegExp(this.re.linkTypesRe()));
2354+
const m = link.match(new RegExp(`^${this.re.linkTypesRe()}`));
23552355
if (m) {
23562356
return { linkType: m[1], path: link.slice(m[0].length) };
23572357
}

0 commit comments

Comments
 (0)