refactor: enforce named capture groups; clean up regexes (#6524)

* refactor: enforce named capture groups; clean up regexes

* fixes

* fix
This commit is contained in:
Joshua Chen 2022-02-01 17:43:15 +08:00 committed by GitHub
parent c56e6194b4
commit 1cefb643dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 80 additions and 77 deletions

View file

@ -67,11 +67,11 @@ export function replaceMarkdownLinks<T extends ContentPaths>({
// ink
// [doc1]: doc1.md -> we replace this doc1.md with correct link
const mdRegex =
/(?:(?:\]\()|(?:\]:\s?))(?!https?:\/\/|@site\/)([^'")\]\s>]+\.mdx?)/g;
/(?:(?:\]\()|(?:\]:\s?))(?!https?:\/\/|@site\/)(?<filename>[^'")\]\s>]+\.mdx?)/g;
let mdMatch = mdRegex.exec(modifiedLine);
while (mdMatch !== null) {
// Replace it to correct html link.
const mdLink = mdMatch[1];
const mdLink = mdMatch.groups!.filename;
const sourcesToTry = [
path.resolve(path.dirname(filePath), decodeURIComponent(mdLink)),