Skip to content
This repository has been archived by the owner on Nov 25, 2024. It is now read-only.

Commit

Permalink
fix: url tokenizer to not treat package version string as email (#280)
Browse files Browse the repository at this point in the history
* 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
3 people authored May 10, 2024
1 parent 3966cbe commit 5b13f8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/odd-waves-glow.md
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
16 changes: 15 additions & 1 deletion packages/site-kit/src/lib/markdown/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -217,7 +230,8 @@ export async function transform(markdown, renderer = {}) {
renderer: {
...default_renderer,
...renderer
}
},
tokenizer
});

return (await marked.parse(markdown)) ?? '';
Expand Down

0 comments on commit 5b13f8f

Please sign in to comment.