1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-06-15 23:00:36 +02:00

Clipper: Fixed issue with relative links when importing HTML

This commit is contained in:
Laurent Cozic
2019-07-15 00:44:45 +01:00
parent 5460a977b1
commit 74ee629266
2 changed files with 28 additions and 6 deletions

View File

@ -1,5 +1,13 @@
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const urlUtils = require('lib/urlUtils.js');
function headAndBodyHtml_(doc) {
const output = [];
if (doc.head) output.push(doc.head.innerHTML);
if (doc.body) output.push(doc.body.innerHTML);
return output.join('\n');
}
const htmlUtils = {
@ -34,11 +42,22 @@ const htmlUtils = {
// This function returns the head and body but without the <head> and <body>
// tag, which for our purpose are not needed and can cause issues when present.
const output = [];
if (doc.head) output.push(doc.head.innerHTML);
if (doc.body) output.push(doc.body.innerHTML);
return output.join('\n');
},
return headAndBodyHtml_(doc);
},
prependBaseUrl(html, baseUrl) {
const dom = new JSDOM(html);
const doc = dom.window.document;
const anchors = doc.getElementsByTagName('a');
for (const anchor of anchors) {
const href = anchor.getAttribute('href');
const newHref = urlUtils.prependBaseUrl(href, baseUrl);
anchor.setAttribute('href', newHref);
}
return headAndBodyHtml_(doc);
},
};