Skip to content

Commit

Permalink
release v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
robert-virkus committed Jun 13, 2021
1 parent 0b122ee commit 42982b6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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).

Expand Down
4 changes: 4 additions & 0 deletions example/enough_mail_html_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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!');
Expand Down
2 changes: 0 additions & 2 deletions lib/enough_mail_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
7 changes: 5 additions & 2 deletions lib/src/converter.dart
Original file line number Diff line number Diff line change
@@ -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 <pre> 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++) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit 42982b6

Please sign in to comment.