Skip to content

Commit

Permalink
Disable GitHub flavored Markdown when lexing
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederikBolding committed Apr 8, 2024
1 parent 85422bc commit ac2b723
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions packages/snaps-utils/src/ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ describe('validateTextLinks', () => {
).not.toThrow();
});

it('passes for non-links', () => {
expect(() =>
validateTextLinks('Hello **http://localhost:3000**', () => false),
).not.toThrow();
});

it('throws an error if an invalid link is found in text', () => {
expect(() =>
validateTextLinks('[test](http://foo.bar)', () => false),
Expand All @@ -76,17 +82,12 @@ describe('validateTextLinks', () => {
).toThrow('Invalid URL: Protocol must be one of: https:, mailto:.');

expect(() =>
validateTextLinks(
`[foo][1]
[1]: http://foo.bar`,
() => false,
),
validateTextLinks('[foo][1]\n\n[1]: http://foo.bar', () => false),
).toThrow('Invalid URL: Protocol must be one of: https:, mailto:.');

expect(() =>
validateTextLinks(
`[foo][1]
[1]: http://foo.bar "foo bar baz"`,
`[foo][1]\n\n[1]: http://foo.bar "foo bar baz"`,
() => false,
),
).toThrow('Invalid URL: Protocol must be one of: https:, mailto:.');
Expand Down
2 changes: 1 addition & 1 deletion packages/snaps-utils/src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ALLOWED_PROTOCOLS = ['https:', 'mailto:'];
* @returns A list of URLs linked to in the string.
*/
function getMarkdownLinks(text: string) {
const tokens = lexer(text);
const tokens = lexer(text, { gfm: false });
const links: (Tokens.Link | Tokens.Generic)[] = [];

// Walk the lexed tokens and collect all link tokens
Expand Down

0 comments on commit ac2b723

Please sign in to comment.