Merge pull request #51 from DEVTomatoCake/jank/markdown-links

add markdown links parsing
This commit is contained in:
MathMan05 2024-08-25 15:38:01 -05:00 committed by GitHub
commit 0a8983818d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -428,6 +428,46 @@ class MarkDown{
}
}
if (txt[i] == "[" && !keep) {
let partsFound=0;
let j=i+1;
const build=["["];
for (; txt[j] !== void 0; j++) {
build.push(txt[j]);
if (partsFound === 0 && txt[j] === "]") {
if (txt[j + 1] === "(" &&
txt[j + 2] === "h" && txt[j + 3] === "t" && txt[j + 4] === "t" && txt[j + 5] === "p" && (txt[j + 6] === "s" || txt[j + 6] === ":")
) {
partsFound++;
} else {
break;
};
} else if (partsFound === 1 && txt[j] === ")") {
partsFound++;
break;
}
}
if (partsFound === 2) {
appendcurrent();
i=j;
const parts=build.join("").match(/^\[(.+)\]\((https?:.+?)( ('|").+('|"))?\)$/);
if (parts) {
const linkElem=document.createElement("a");
linkElem.href=parts[2];
linkElem.textContent=parts[1];
linkElem.target="_blank";
linkElem.rel="noopener noreferrer";
linkElem.title=(parts[3] ? parts[3].substring(2, parts[3].length - 1)+"\n\n" : "") + parts[2];
span.appendChild(linkElem);
continue;
}
}
}
current.textContent+=txt[i];
}
appendcurrent();