You've already forked joplin
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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user