Skip to content
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

enhance: other URL schemes #73

Merged
merged 1 commit into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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