From 42982b6331047e972191130b0edcc1c9151a1632 Mon Sep 17 00:00:00 2001 From: Robert Virkus Date: Sun, 13 Jun 2021 18:06:48 +0200 Subject: [PATCH] release v1.3.0 --- CHANGELOG.md | 3 +++ README.md | 8 ++++++-- example/enough_mail_html_example.dart | 4 ++++ lib/enough_mail_html.dart | 2 -- lib/src/converter.dart | 7 +++++-- pubspec.yaml | 2 +- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6b49db..0682a80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 1.3.0 +- Do not include the `enough_mail` package automatically to keep documentation simpler + ## 1.2.0 - Add `HtmlToPlainTextConverter` with HTML to plain text conversion diff --git a/README.md b/README.md index 8be9e72..5c7b468 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Generate html code from any email mime message for displaying it. ## Usage -The `enough_mail_html` package defines the `decodeTextHtmlForDisplay()` extension method on `MimeMessage` of the [enough_mail](https://pub.dev/packages/enough_mail) package. +The `enough_mail_html` package defines the `transformToHtml()` extension method on `MimeMessage` of the [enough_mail](https://pub.dev/packages/enough_mail) package. This method will always generate HTML, specifically also for plain text or empty messages. You can define your custom processors @@ -19,6 +19,10 @@ String generateHtml(MimeMessage mimeMessage) { return mimeMessage.transformToHtml( blockExternalImages: false, emptyMessageText: 'Nothing here, move on!'); } + +String generatePlainText(String htmlText) { + return HtmlToPlainTextConverter.convert(htmlText); +} ``` More examples: @@ -63,7 +67,7 @@ Add this dependency your pubspec.yaml file: ``` dependencies: - enough_mail_html: ^1.0.0 + enough_mail_html: ^1.3.0 ``` The latest version or `enough_mail_html` is [![enough_mail_html version](https://img.shields.io/pub/v/enough_mail_html.svg)](https://pub.dartlang.org/packages/enough_mail_html). diff --git a/example/enough_mail_html_example.dart b/example/enough_mail_html_example.dart index d5129db..928a1ea 100644 --- a/example/enough_mail_html_example.dart +++ b/example/enough_mail_html_example.dart @@ -6,6 +6,10 @@ String simpleTransformExample(MimeMessage mimeMessage) { return mimeMessage.transformToHtml(); } +String generatePlainText(String htmlText) { + return HtmlToPlainTextConverter.convert(htmlText); +} + String configureImageBlockingOrEmptyMessage(MimeMessage mimeMessage) { return mimeMessage.transformToHtml( blockExternalImages: true, emptyMessageText: 'Nothing here, move on!'); diff --git a/lib/enough_mail_html.dart b/lib/enough_mail_html.dart index e692e3e..fb42d05 100644 --- a/lib/enough_mail_html.dart +++ b/lib/enough_mail_html.dart @@ -5,5 +5,3 @@ library enough_mail_html; export 'src/enough_mail_html_base.dart'; export 'src/converter.dart'; - -export 'package:enough_mail/enough_mail.dart'; diff --git a/lib/src/converter.dart b/lib/src/converter.dart index ecb5783..a832b2a 100644 --- a/lib/src/converter.dart +++ b/lib/src/converter.dart @@ -1,16 +1,19 @@ /// Converts HTML text into a plain text message. class HtmlToPlainTextConverter { static final _htmlEntityRegex = RegExp(r'&(#?)([a-zA-Z0-9]+?);'); - static final htmlTagRegex = + static final _htmlTagRegex = RegExp(r'<[^>]*>', multiLine: true, caseSensitive: true); + // disallow instantiation: + HtmlToPlainTextConverter._(); + /// Converts the given [htmlText] into plain text. /// /// - It keeps code untouched in the
 elements
   /// - Blockquotes are transformed into lines starting with `>`
   /// - HTML entities are transformed to their plain text representation
   static String convert(final String htmlText) {
-    final matches = htmlTagRegex.allMatches(htmlText).toList();
+    final matches = _htmlTagRegex.allMatches(htmlText).toList();
     final plainTextBuffer = StringBuffer();
     var lastMatchIndex = 0;
     for (var i = 0; i < matches.length; i++) {
diff --git a/pubspec.yaml b/pubspec.yaml
index aa82208..37b3de0 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,6 +1,6 @@
 name: enough_mail_html
 description: Generate HTML from an email mime message and creates plain text from HTML. Eases handling of `MimeMessage` in the `enough_mail` package.
-version: 1.2.0
+version: 1.3.0
 homepage: https://github.com/Enough-Software/enough_mail_html
 
 environment: