Skip to content

Commit eba7b59

Browse files
authored
Make sure HREF values are expanded (#27)
The problems sometime use relative links to other problems. In this case the markdown contained an invalid relative link. Link to the absolute URL instead.
1 parent 9f598f7 commit eba7b59

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/content_scripts/to-markdown.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ function generateMarkdown(doc) {
4343
return turndownService.turndown(doc).concat("\n");
4444
}
4545

46+
function expandHrefs(article) {
47+
const articleLinks = article.querySelectorAll("a");
48+
for (const link of articleLinks) {
49+
if (link.href) {
50+
// Reading the `href` seems to expand it, setting it back will make it
51+
// permanent.
52+
link.href = link.href
53+
}
54+
}
55+
}
56+
4657
function capturePage() {
4758
const newDoc = document.createDocumentFragment();
4859
const titleElement = document.createElement("h1");
@@ -62,6 +73,7 @@ function capturePage() {
6273
const articleElementsLength = articleElements.length;
6374
for (let index = 0; index < articleElementsLength; ++index) {
6475
const article = articleElements[index].cloneNode(true);
76+
6577
const headingElement = article.querySelector("h2");
6678
let heading = stripHyphens(headingElement.innerText);
6779

@@ -74,6 +86,7 @@ function capturePage() {
7486
newHeadingElement.innerText = heading;
7587
headingElement.replaceWith(newHeadingElement);
7688

89+
expandHrefs(article);
7790
newDoc.appendChild(article);
7891
}
7992

0 commit comments

Comments
 (0)