16 lines
597 B
Dart
16 lines
597 B
Dart
/// 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('&', '&')
|
||
|
|
.replaceAll('<', '<')
|
||
|
|
.replaceAll('>', '>')
|
||
|
|
.replaceAll('"', '"')
|
||
|
|
.replaceAll(''', "'")
|
||
|
|
.replaceAll(' ', ' ')
|
||
|
|
.trim();
|