This repository has been archived by the owner on Nov 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: url tokenizer to not treat package version string as email (#280)
* fix: url tokenizer to not treat package version string as email * Add type --------- Co-authored-by: Puru <[email protected]> Co-authored-by: Puru Vijay <[email protected]>
- Loading branch information
1 parent
3966cbe
commit 5b13f8f
Showing
2 changed files
with
20 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/site-kit': patch | ||
--- | ||
|
||
fix: url tokenizer to not treat package version string as email |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,6 +208,19 @@ const default_renderer = { | |
} | ||
}; | ||
|
||
/** @type {import('marked').TokenizerObject} */ | ||
const tokenizer = { | ||
url(src) { | ||
// if `src` is a package version string, eg: [email protected] | ||
// do not tokenize it as email | ||
if (/@\d+\.\d+\.\d+/.test(src)) { | ||
return undefined; | ||
} | ||
// else, use the default tokenizer behavior | ||
return false; | ||
} | ||
}; | ||
|
||
/** | ||
* @param {string} markdown | ||
* @param {Partial<import('marked').Renderer>} renderer | ||
|
@@ -217,7 +230,8 @@ export async function transform(markdown, renderer = {}) { | |
renderer: { | ||
...default_renderer, | ||
...renderer | ||
} | ||
}, | ||
tokenizer | ||
}); | ||
|
||
return (await marked.parse(markdown)) ?? ''; | ||
|