Skip to content

Commit

Permalink
understand other URL schemes too (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann150 committed Aug 19, 2021
1 parent 88ecadb commit a731592
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/internal/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@ altUrlFormat
{
return text();
}
// URL scheme as defined in https://url.spec.whatwg.org/#url-scheme-string
/ [a-zA-Z] [-a-zA-Z0-9+.]* ":" (!(">" / _) CHAR)+
{
return text();
}

// inline: link

Expand All @@ -412,6 +417,11 @@ linkLabelPart

linkUrl
= url { return text(); }
// URL scheme as defined in https://url.spec.whatwg.org/#url-scheme-string
/ [a-zA-Z] [-a-zA-Z0-9+.]* ":" (!(")" / _) CHAR)+
{
return text();
}

// inline: fn

Expand Down
26 changes: 26 additions & 0 deletions test/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,22 @@ hoge`;
];
assert.deepStrictEqual(mfm.parse(input), output);
});

it('do not match other schemes in url withouth angle brackets', () => {
const input = 'oops:url';
const output = [
TEXT('oops:url'),
];
assert.deepStrictEqual(mfm.parse(input), output);
});

it('match other schemes in url with angle brackets', () => {
const input = '<gemini://example.com>';
const output = [
N_URL('gemini://example.com', true),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
});

describe('link', () => {
Expand Down Expand Up @@ -962,6 +978,16 @@ hoge`;
];
assert.deepStrictEqual(mfm.parse(input), output);
});

it('match other schemes without angle brackets', () => {
const input = '[send email](mailto:[email protected]?subject=test)';
const output = [
LINK(false, 'mailto:[email protected]?subject=test', [
TEXT('send email')
]),
];
assert.deepStrictEqual(mfm.parse(input), output);
});
});

describe('fn v1', () => {
Expand Down

0 comments on commit a731592

Please sign in to comment.