Skip to content

Commit

Permalink
only exclude links if overlap is over 50%, add test and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ryzokuken committed Jan 8, 2025
1 parent 02ff41a commit 5103798
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions test/pdfs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -692,3 +692,4 @@
!issue19182.pdf
!issue18911.pdf
!issue19207.pdf
!link.pdf
Binary file added test/pdfs/link.pdf
Binary file not shown.
7 changes: 6 additions & 1 deletion web/annotation_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,15 @@ class AnnotationLayerBuilder {

const uniqueLinks = linkAnnotations.filter(link => {
for (const annotation of annotations) {
function area(rect) {
return Math.abs(rect[2] - rect[0]) * Math.abs(rect[3] - rect[1]);
}
const intersect = Util.intersect(annotation.rect, link.rect); // Find the intersection between the annotation and the link.
if (
annotation.subtype === "Link" &&
annotation.url === link.url &&
Util.intersect(annotation.rect, link.rect) !== null
intersect !== null &&
area(intersect) / area(link.rect) > 0.5 // If the overlap is more than 50%.
) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion web/autolinker.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getOriginalIndex, normalize } from "./pdf_find_controller.js";

class Autolinker {
static #urlRegex =
/\b(?:https?:\/\/|mailto:|www.)(?:[[\S--\[]--\p{P}]|\/|[\p{P}--\[]+[[\S--\[]--\p{P}])+/gmv;
/\b(?:https?:\/\/|mailto:|www.)(?:[[\S--\[]--\p{P}]|\/|[\p{P}--\[]+[[\S--\[]--\p{P}])+/gmv; // Regex can be tested and verified at https://regex101.com/r/zuMeQX/3.

Check notice

Code scanning / CodeQL

Syntax error Note

Error: Invalid regular expression flag

static #addLinkAnnotations(url, index, length, pdfPageView) {
// TODO refactor out the logic for a single match from this function
Expand Down

0 comments on commit 5103798

Please sign in to comment.