1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-26 22:41:17 +02:00

Desktop: Fixed copying and pasting an image from Chrome in RTE

This commit is contained in:
Laurent Cozic
2023-11-17 16:47:05 +00:00
parent 60c2964acd
commit 2c9bf9f03a
7 changed files with 168 additions and 9 deletions

View File

@@ -404,4 +404,33 @@ export const extractHtmlBody = (html: string) => {
return bodyFound ? output.join('') : html;
};
export const htmlDocIsImageOnly = (html: string) => {
let imageCount = 0;
let nonImageFound = false;
let textFound = false;
const parser = new htmlparser2.Parser({
onopentag: (name: string) => {
if (name === 'img') {
imageCount++;
} else if (['meta'].includes(name)) {
// We allow these tags since they don't print anything
} else {
nonImageFound = true;
}
},
ontext: (text: string) => {
if (text.trim()) textFound = true;
},
});
parser.write(html);
parser.end();
return imageCount === 1 && !nonImageFound && !textFound;
};
export default new HtmlUtils();