Fix appear save draft dialog when reload editing composer
Signed-off-by: dab246 <tdvu@linagora.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user