Fix appear save draft dialog when reload editing composer

Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
dab246
2025-04-01 00:50:53 +07:00
committed by Dat H. Pham
parent 9410de9399
commit 0b9bb3530c
13 changed files with 93 additions and 21 deletions
@@ -23,4 +23,6 @@ abstract class HtmlDataSource {
});
Future<String> removeCollapsedExpandedSignatureEffect({required String emailContent});
Future<String> removeStyleLazyLoadDisplayInlineImages({required String emailContent});
}
@@ -62,4 +62,13 @@ class HtmlDataSourceImpl extends HtmlDataSource {
);
}).catchError(_exceptionThrower.throwException);
}
@override
Future<String> removeStyleLazyLoadDisplayInlineImages({required String emailContent}) {
return Future.sync(() async {
return await _htmlAnalyzer.removeStyleLazyLoadDisplayInlineImages(
emailContent: emailContent,
);
}).catchError(_exceptionThrower.throwException);
}
}
@@ -237,4 +237,30 @@ class HtmlAnalyzer {
return null;
}
}
Future<String> removeStyleLazyLoadDisplayInlineImages({required String emailContent}) async {
try {
final document = parse(emailContent);
final imgElements = document.querySelectorAll('img[style], img[loading]');
await Future.wait(imgElements.map((img) async {
String? style = img.attributes['style'];
if (style != null) {
style = style.replaceAll(RegExp(r'display\s*:\s*inline;?'), '').trim();
if (style.isEmpty) {
img.attributes.remove('style');
} else {
img.attributes['style'] = style;
}
}
if (img.attributes['loading'] == 'lazy') {
img.attributes.remove('loading');
}
}));
return document.body?.innerHtml ?? emailContent;
} catch (e) {
logError('HtmlAnalyzer::removeStyleLazyLoadDisplayInlineImages:Exception = $e');
return emailContent;
}
}
}