no deduplicar links que no están al lado

This commit is contained in:
Cat /dev/Nulo 2023-04-18 19:19:11 -03:00
parent a26ecf3099
commit a45d1a00eb

View file

@ -31,12 +31,14 @@
function getLinks(node) { function getLinks(node) {
/** @type {Link[]} */ /** @type {Link[]} */
let links = []; let links = [];
let lastWasLinkMark = false;
node.descendants((node) => { node.descendants((node) => {
for (const mark of node.marks) { for (const mark of node.marks) {
const content = node.textContent; const content = node.textContent;
// no repetir marks interrumpidas por otras marks // no repetir marks interrumpidas por otras marks
const lastLink = links[links.length - 1] || null; const lastLink = links[links.length - 1] || null;
if ( if (
lastWasLinkMark &&
lastLink && lastLink &&
("href" in lastLink ("href" in lastLink
? lastLink.href === mark.attrs.href ? lastLink.href === mark.attrs.href
@ -51,14 +53,19 @@
content, content,
href: mark.attrs.href, href: mark.attrs.href,
}); });
lastWasLinkMark = true;
} else if (mark.type === schema.marks.internal_link) { } else if (mark.type === schema.marks.internal_link) {
links.push({ links.push({
type: "internal", type: "internal",
content, content,
id: mark.attrs.id, id: mark.attrs.id,
}); });
lastWasLinkMark = true;
} else {
lastWasLinkMark = false;
} }
} }
if (node.marks.length == 0) lastWasLinkMark = false;
}); });
return links; return links;
} }