TF-4139 Fix attachment reminder mistakenly shown when replying to an email
This commit is contained in:
@@ -685,14 +685,31 @@ class HtmlUtils {
|
|||||||
});
|
});
|
||||||
</script>''';
|
</script>''';
|
||||||
|
|
||||||
static String extractPlainText(String html) {
|
static String extractPlainText(
|
||||||
|
String html, {
|
||||||
|
bool removeQuotes = true,
|
||||||
|
bool removeStyle = true,
|
||||||
|
bool removeScript = true,
|
||||||
|
}) {
|
||||||
var cleaned = html;
|
var cleaned = html;
|
||||||
// Delete the blockquote and the content inside
|
|
||||||
final blockquoteRegex = RegExp(
|
if (cleaned.isEmpty) return '';
|
||||||
r'<blockquote[\s\S]*?</blockquote>',
|
|
||||||
caseSensitive: false,
|
// Parse DOM
|
||||||
);
|
final doc = parser.parse(cleaned);
|
||||||
cleaned = html.replaceAll(blockquoteRegex, '');
|
|
||||||
|
// Remove unwanted nodes by CSS selector
|
||||||
|
if (removeQuotes) {
|
||||||
|
doc.querySelectorAll('blockquote').forEach((e) => e.remove());
|
||||||
|
}
|
||||||
|
if (removeStyle) {
|
||||||
|
doc.querySelectorAll('style').forEach((e) => e.remove());
|
||||||
|
}
|
||||||
|
if (removeScript) {
|
||||||
|
doc.querySelectorAll('script').forEach((e) => e.remove());
|
||||||
|
}
|
||||||
|
|
||||||
|
cleaned = doc.outerHtml;
|
||||||
|
|
||||||
// Decode HTML entities up to 5 times (& → &, → space, <div> → <div>, ...)
|
// Decode HTML entities up to 5 times (& → &, → space, <div> → <div>, ...)
|
||||||
int iterations = 0;
|
int iterations = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user