From bc69724224f8e7ddb5079b71a911d17fe36abd3f Mon Sep 17 00:00:00 2001 From: barbapapazes Date: Thu, 2 Nov 2023 16:34:20 +0100 Subject: [PATCH 1/5] fix: same text and url --- utils/markdown.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils/markdown.ts b/utils/markdown.ts index 38476c7..6bd4c43 100644 --- a/utils/markdown.ts +++ b/utils/markdown.ts @@ -16,6 +16,10 @@ export function resolveMarkdownRelativeLinks( if (path.startsWith("http") || path.startsWith("https")) { return match; } + // match a link (e.g. [./example](./example), will replace the link, not the text) + if (url) { + return match.replace(`(${path})`, `(${cdnBaseURL}/${path.replace(/^\.\//, "")})`); + } return match.replace(path, `${cdnBaseURL}/${path.replace(/^\.\//, "")}`); }, ); From 457880f33bcf4b78125aa222bc241c0ea9ae5932 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 2 Nov 2023 15:37:08 +0000 Subject: [PATCH 2/5] chore: apply automated fixes --- utils/markdown.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/markdown.ts b/utils/markdown.ts index 6bd4c43..4133856 100644 --- a/utils/markdown.ts +++ b/utils/markdown.ts @@ -18,7 +18,10 @@ export function resolveMarkdownRelativeLinks( } // match a link (e.g. [./example](./example), will replace the link, not the text) if (url) { - return match.replace(`(${path})`, `(${cdnBaseURL}/${path.replace(/^\.\//, "")})`); + return match.replace( + `(${path})`, + `(${cdnBaseURL}/${path.replace(/^\.\//, "")})`, + ); } return match.replace(path, `${cdnBaseURL}/${path.replace(/^\.\//, "")}`); }, From 39460fc398be4fd604bf2b1ca4648bb55f96d787 Mon Sep 17 00:00:00 2001 From: barbapapazes Date: Wed, 10 Jan 2024 10:15:49 +0100 Subject: [PATCH 3/5] fix: update regexp --- utils/markdown.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/utils/markdown.ts b/utils/markdown.ts index 4133856..de6476e 100644 --- a/utils/markdown.ts +++ b/utils/markdown.ts @@ -16,14 +16,15 @@ export function resolveMarkdownRelativeLinks( if (path.startsWith("http") || path.startsWith("https")) { return match; } - // match a link (e.g. [./example](./example), will replace the link, not the text) - if (url) { - return match.replace( - `(${path})`, - `(${cdnBaseURL}/${path.replace(/^\.\//, "")})`, - ); - } - return match.replace(path, `${cdnBaseURL}/${path.replace(/^\.\//, "")}`); + /** + * RegExp is used to avoid replacing texts in markdown links and targets only `href` and `src` attributes + * @example [link](./image.png) => [link](https://cdn.com/image.png) + * @example [./src/file.ts](./src/file.ts) => [./src/file.ts](https://cdn.com/src/file.ts) + */ + const searchRegExp = new RegExp(`(?[^[])(?${path})`, "g") // [^[] matches any character except [ + return match.replace(searchRegExp, (_, before, url) => { + return `${before}${cdnBaseURL}/${url.replace(/^\.\//, "")}` + }); }, ); } From ca9be8b31ec956e55ed5e63d242015e4d1005295 Mon Sep 17 00:00:00 2001 From: barbapapazes Date: Wed, 10 Jan 2024 10:17:10 +0100 Subject: [PATCH 4/5] docs: update examples --- utils/markdown.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/markdown.ts b/utils/markdown.ts index de6476e..52791c6 100644 --- a/utils/markdown.ts +++ b/utils/markdown.ts @@ -20,6 +20,7 @@ export function resolveMarkdownRelativeLinks( * RegExp is used to avoid replacing texts in markdown links and targets only `href` and `src` attributes * @example [link](./image.png) => [link](https://cdn.com/image.png) * @example [./src/file.ts](./src/file.ts) => [./src/file.ts](https://cdn.com/src/file.ts) + * @example ./src/file.ts => https://cdn.com/src/file.ts */ const searchRegExp = new RegExp(`(?[^[])(?${path})`, "g") // [^[] matches any character except [ return match.replace(searchRegExp, (_, before, url) => { From 1bd4d4be5c84054d8dee0787f8c4818825ad705e Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 10 Jan 2024 09:17:54 +0000 Subject: [PATCH 5/5] chore: apply automated fixes --- utils/markdown.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/markdown.ts b/utils/markdown.ts index 52791c6..2302b2a 100644 --- a/utils/markdown.ts +++ b/utils/markdown.ts @@ -21,10 +21,10 @@ export function resolveMarkdownRelativeLinks( * @example [link](./image.png) => [link](https://cdn.com/image.png) * @example [./src/file.ts](./src/file.ts) => [./src/file.ts](https://cdn.com/src/file.ts) * @example ./src/file.ts => https://cdn.com/src/file.ts - */ - const searchRegExp = new RegExp(`(?[^[])(?${path})`, "g") // [^[] matches any character except [ + */ + const searchRegExp = new RegExp(`(?[^[])(?${path})`, "g"); // [^[] matches any character except [ return match.replace(searchRegExp, (_, before, url) => { - return `${before}${cdnBaseURL}/${url.replace(/^\.\//, "")}` + return `${before}${cdnBaseURL}/${url.replace(/^\.\//, "")}`; }); }, );