Files
sharedinbox/lib/core/utils/html_utils.dart
T

16 lines
597 B
Dart
Raw Normal View History

/// Strips HTML tags and decodes common entities to produce plain text.
///
/// Not a full HTML parser — handles the common subset found in email bodies.
String htmlToPlain(String html) => html
.replaceAll(RegExp(r'<br\s*/?>'), '\n')
.replaceAll(RegExp(r'<p\s*/?>', caseSensitive: false), '\n')
.replaceAll(RegExp(r'</p>', caseSensitive: false), '')
.replaceAll(RegExp(r'<[^>]+>'), '')
.replaceAll('&amp;', '&')
.replaceAll('&lt;', '<')
.replaceAll('&gt;', '>')
.replaceAll('&quot;', '"')
.replaceAll('&#39;', "'")
.replaceAll('&nbsp;', ' ')
.trim();