Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix link searching to detect all links in a given line #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/markdownProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,21 +107,21 @@ const convertAdmonition = (line: string, isInAdmonition: boolean, isInQuote: boo
};

function checkForLinks(line: string): string {
const pattern = /\[([^\]]+)\]\(([^)]+)\)/;
const match = line.match(pattern);
const pattern = /\[([^\]]+)\]\(([^)]+)\)/g;
const matches = [...line.matchAll(pattern)];

if (match) {
return matches.reduce((processedLine, match) => {

const url = match[2];

// keep external links as is
if (url.includes("http")) {
return line;
return processedLine;
// only continue with internal links
} else {
const urlParts = url.split("/");

if (urlParts.length <= 1) return line;
if (urlParts.length <= 1) return processedLine;

let mainFolder = urlParts[0];

Expand All @@ -135,10 +135,9 @@ function checkForLinks(line: string): string {
const processedUrlParts = processUrlParts(urlParts, isBlog);

const newUrl = "/" + processedUrlParts.join("/");
return line.replace(url, newUrl);
return processedLine.replace(url, newUrl);
}
}
return line
}, line);
}

function processUrlParts(urlParts: string[], isBlog: boolean): string[] {
Expand Down