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:
parent
06ad539941
commit
484f290eb0
@ -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() {
|
function documentForReadability() {
|
||||||
// Readability directly change the passed document so clone it so as
|
// Readability directly change the passed document so clone it so as
|
||||||
// to preserve the original web page.
|
// to preserve the original web page.
|
||||||
@ -249,10 +267,13 @@
|
|||||||
} else if (command.name === "selectedHtml") {
|
} else if (command.name === "selectedHtml") {
|
||||||
|
|
||||||
hardcodePreStyles(document);
|
hardcodePreStyles(document);
|
||||||
const range = window.getSelection().getRangeAt(0);
|
preProcessDocument(document);
|
||||||
const container = document.createElement('div');
|
const range = window.getSelection().getRangeAt(0);
|
||||||
container.appendChild(range.cloneContents());
|
const container = document.createElement('div');
|
||||||
return clippedContentResponse(pageTitle(), container.innerHTML, getImageSizes(document), getAnchorNames(document));
|
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') {
|
} else if (command.name === 'screenshot') {
|
||||||
|
|
||||||
|
@ -438,6 +438,10 @@ class Api {
|
|||||||
baseUrl: requestNote.base_url ? requestNote.base_url : '',
|
baseUrl: requestNote.base_url ? requestNote.base_url : '',
|
||||||
anchorNames: requestNote.anchor_names ? requestNote.anchor_names : [],
|
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) {
|
if (requestNote.parent_id) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user