Skip to content

Commit

Permalink
Resolve absolute URLs when copying selection as Markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
yorkxin committed Apr 24, 2024
1 parent 9a70b28 commit eabc478
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ function selectionToMarkdown(turndownOptions) {
for (let i = 0, len = sel.rangeCount; i < len; i += 1) {
container.appendChild(sel.getRangeAt(i).cloneContents());
}

// Fix <a href> so that they are absolute URLs
container.querySelectorAll('a').forEach((value) => {
value.setAttribute('href', value.href);
});

// Fix <img src> so that they are absolute URLs
container.querySelectorAll('img').forEach((value) => {
value.setAttribute('src', value.src);
});
const html = container.innerHTML;
return turndownService.turndown(html);
}
Expand Down

0 comments on commit eabc478

Please sign in to comment.