generated at
scrapbox-external-project-link-processor
index.js
export class ScrapboxExternalProjectLinkProcessor { appURL; constructor({ appURL }) { this.appURL = appURL; } async process({text}) { const lines = text.split("\n"); const replacedLines = lines.map((line) => { let replacedLine = line; const externalProjectLinkMatches = [...replacedLine.matchAll(/\[(\/.*?)\]/g)]; externalProjectLinkMatches.forEach((externalProjectLinkMatch) => { const externalLink = `[${externalProjectLinkMatch[1]} ${this.appURL}${encodeURI(externalProjectLinkMatch[1])}]`; replacedLine = replacedLine.replaceAll(externalProjectLinkMatch[0], externalLink); }); return replacedLine; }); return {text: replacedLines.join("\n")}; } }