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

Clipper: Improved clipping selection by removing unecessary elements

This commit is contained in:
Laurent Cozic 2019-06-25 22:11:12 +01:00
parent 06ad539941
commit 484f290eb0
2 changed files with 29 additions and 4 deletions

View File

@ -171,6 +171,24 @@
}
}
// Given a document, return a <style> tag that contains all the styles
// required to render the page. Not currently used but could be as an
// option to clip pages as HTML.
function getStyleTag(doc) {
const styleText = [];
for (var i=0; i<doc.styleSheets.length; i++) {
try {
var sheet = doc.styleSheets[i];
for (const cssRule of sheet.cssRules) {
styleText.push(cssRule.cssText);
}
} catch (error) {
console.warn(error);
}
}
return '<style>' + styleText.join('\n') + '</style>';
}
function documentForReadability() {
// Readability directly change the passed document so clone it so as
// to preserve the original web page.
@ -249,10 +267,13 @@
} else if (command.name === "selectedHtml") {
hardcodePreStyles(document);
const range = window.getSelection().getRangeAt(0);
const container = document.createElement('div');
container.appendChild(range.cloneContents());
return clippedContentResponse(pageTitle(), container.innerHTML, getImageSizes(document), getAnchorNames(document));
preProcessDocument(document);
const range = window.getSelection().getRangeAt(0);
const container = document.createElement('div');
container.appendChild(range.cloneContents());
const imageSizes = getImageSizes(document, true);
cleanUpElement(container, imageSizes);
return clippedContentResponse(pageTitle(), container.innerHTML, getImageSizes(document), getAnchorNames(document));
} else if (command.name === 'screenshot') {

View File

@ -438,6 +438,10 @@ class Api {
baseUrl: requestNote.base_url ? requestNote.base_url : '',
anchorNames: requestNote.anchor_names ? requestNote.anchor_names : [],
});
// Note: to save the note as HTML, use the code below:
// const minify = require('html-minifier').minify;
// output.body = minify(requestNote.body_html, { collapseWhitespace: true });
}
if (requestNote.parent_id) {