Skip to content

Commit

Permalink
Release 1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
CatHood0 committed Aug 17, 2024
1 parent 5e66b2f commit 2552507
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 12 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 1.4.0

* feat: made text trimming optional by @raimkulovr in https://github.com/CatHood0/flutter_quill_delta_from_html/pull/7
* feat: ability to replace new lines to `<br>`

## New Contributors
* @raimkulovr made their first contribution in https://github.com/CatHood0/flutter_quill_delta_from_html/pull/7

## 1.3.13

* Chore: updated dependencies
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Add the dependency to your pubspec.yaml:

```yaml
dependencies:
flutter_quill_delta_from_html: ^1.3.13
flutter_quill_delta_from_html: ^1.4.0
```
Then, import the package and use it in your Flutter application:
Expand Down Expand Up @@ -176,12 +176,12 @@ To utilize `HtmlOperations`, extend this class and implement the methods necessa

```dart
abstract class HtmlOperations {
///custom blocks are passed internally by HtmlToDelta
/// custom blocks are passed internally by HtmlToDelta
List<CustomHtmlPart>? customBlocks;
//You don't need to override this method
//as it simply calls the other methods
//to detect the type of HTML tag
// You don't need to override this method
// since it just call the other methods
// when detect the type of HTML tag
List<Operation> resolveCurrentElement(dom.Element element, [int indentLevel = 0]);
List<Operation> brToOp(dom.Element element);
Expand Down
24 changes: 19 additions & 5 deletions lib/parser/html_to_delta.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class HtmlToDelta {
/// </body>
///```
///
/// If [trimText] is false the leading spaces wont be removed
/// and return a Delta with unexpected spaces like:
/// If [trimText] is false the leading spaces wont be removed
/// and return a Delta with unexpected spaces like:
///
///```dart
/// [
Expand All @@ -55,9 +55,20 @@ class HtmlToDelta {
///```
///
/// It's highly recommended that if you have a html on multiple lines
/// then remove all new lines to make more simple to the parser works
/// as expect. HtmlToDelta works better with a single line html code
/// then remove all new lines or set replaceNormalNewLinesToBr to true
/// to replace new lines to `<br>` tags
/// to make more simple to the parser works as we expect.
///
/// HtmlToDelta works better with a single line html code
final bool trimText;
/// Replace all new lines (\n) to `<br>`
///
/// You will need to ensure of your html content **has not**
/// wrapped into a `<html>` or `<body>` tags
/// because this will replace all ones, without
/// ensure if the tag to the left of the new line
/// is a common tags (`<p>`,`<li>`,`<h1>`,etc) or a body tags
final bool replaceNormalNewLinesToBr;

/// Creates a new instance of HtmlToDelta.
///
Expand All @@ -67,6 +78,7 @@ class HtmlToDelta {
HtmlOperations? htmlToOperations,
this.customBlocks,
this.trimText = true,
this.replaceNormalNewLinesToBr = false,
}) {
htmlToOp = htmlToOperations ?? DefaultHtmlToOperations();
//this part ensure to set the customBlocks passed at the constructor
Expand All @@ -91,7 +103,9 @@ class HtmlToDelta {
/// ```
Delta convert(String htmlText) {
final Delta delta = Delta();
final dom.Document $document = dparser.parse(htmlText);
final dom.Document $document = dparser.parse(
replaceNormalNewLinesToBr ? htmlText.replaceAll('\n', '<br>') : htmlText,
);
final dom.Element? $body = $document.body;
final dom.Element? $html = $document.documentElement;

Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: flutter_quill_delta_from_html
description: "Convert easily HTML inputs content to Quill Js Delta format"
version: 1.3.13
version: 1.4.0
homepage:
repository: https://github.com/CatHood0/flutter_quill_delta_from_html
issue_tracker: https://github.com/CatHood0/flutter_quill_delta_from_html/issues
Expand All @@ -10,7 +10,7 @@ environment:
flutter: ">=1.17.0"

dependencies:
dart_quill_delta: ^10.0.0
dart_quill_delta: ^10.2.0
html: ^0.15.4

dev_dependencies:
Expand Down

0 comments on commit 2552507

Please sign in to comment.