Skip to content

Commit

Permalink
make processLinks switch to imperative style to be cleaner and consis…
Browse files Browse the repository at this point in the history
…tent
  • Loading branch information
ryzokuken committed Dec 16, 2024
1 parent ebeee90 commit a20d5d9
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions web/autolinker.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,21 @@ class Autolinker {
static processLinks(pdfPageView, textContent) {
const [text, diffs] = normalize(textContent.join(""));
const matches = text.matchAll(Autolinker.#urlRegex);
return Array.from(matches, match => {
const links = [];
for (const match of matches) {
const url = createValidAbsoluteUrl(match[0]);
if (url) {
const [index, length] = getOriginalIndex(
diffs,
match.index,
match[0].length
);
return this.#addLinkAnnotations(url.href, index, length, pdfPageView);
links.push(
...this.#addLinkAnnotations(url.href, index, length, pdfPageView)
);
}
return url;
})
.filter(annotation => annotation !== null)
.flat();
}
return links;
}
}

Expand Down

0 comments on commit a20d5d9

Please sign in to comment.