parent
78e48eb49b
commit
22cc677f1c
18 changed files with 327 additions and 26 deletions
File diff suppressed because one or more lines are too long
@ -0,0 +1,30 @@ |
|||||||
|
# Miscellaneous |
||||||
|
*.class |
||||||
|
*.log |
||||||
|
*.pyc |
||||||
|
*.swp |
||||||
|
.DS_Store |
||||||
|
.atom/ |
||||||
|
.buildlog/ |
||||||
|
.history |
||||||
|
.svn/ |
||||||
|
migrate_working_dir/ |
||||||
|
|
||||||
|
# IntelliJ related |
||||||
|
*.iml |
||||||
|
*.ipr |
||||||
|
*.iws |
||||||
|
.idea/ |
||||||
|
|
||||||
|
# The .vscode folder contains launch configuration and tasks you configure in |
||||||
|
# VS Code which you may wish to be included in version control, so this line |
||||||
|
# is commented out by default. |
||||||
|
#.vscode/ |
||||||
|
|
||||||
|
# Flutter/Dart/Pub related |
||||||
|
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. |
||||||
|
/pubspec.lock |
||||||
|
**/doc/api/ |
||||||
|
.dart_tool/ |
||||||
|
.packages |
||||||
|
build/ |
@ -0,0 +1,10 @@ |
|||||||
|
# This file tracks properties of this Flutter project. |
||||||
|
# Used by Flutter tool to assess capabilities and perform upgrades etc. |
||||||
|
# |
||||||
|
# This file should be version controlled and should not be manually edited. |
||||||
|
|
||||||
|
version: |
||||||
|
revision: "d211f42860350d914a5ad8102f9ec32764dc6d06" |
||||||
|
channel: "stable" |
||||||
|
|
||||||
|
project_type: package |
@ -0,0 +1,3 @@ |
|||||||
|
## 0.0.1-experimental.1 |
||||||
|
|
||||||
|
* initial release. |
@ -0,0 +1,21 @@ |
|||||||
|
MIT License |
||||||
|
|
||||||
|
Copyright (c) 2023 Flutter Quill Team |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||||
|
of this software and associated documentation files (the "Software"), to deal |
||||||
|
in the Software without restriction, including without limitation the rights |
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||||
|
copies of the Software, and to permit persons to whom the Software is |
||||||
|
furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all |
||||||
|
copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||||
|
SOFTWARE. |
@ -0,0 +1,41 @@ |
|||||||
|
# Flutter Quill HTML |
||||||
|
A extension for [flutter_quill](https://pub.dev/packages/flutter_quill) package to add support for dealing with conversion to/from html |
||||||
|
|
||||||
|
It uses [vsc_quill_delta_to_html](https://pub.dev/packages/vsc_quill_delta_to_html) package to convert the the delta to HTML |
||||||
|
|
||||||
|
This library is **experimental** and the support might be dropped at anytime. |
||||||
|
|
||||||
|
## Features |
||||||
|
|
||||||
|
```markdown |
||||||
|
- Easy to use |
||||||
|
- Support Flutter Quill package |
||||||
|
``` |
||||||
|
|
||||||
|
## Getting started |
||||||
|
|
||||||
|
```yaml |
||||||
|
dependencies: |
||||||
|
quill_html_converter: ^<latest-version-here> |
||||||
|
``` |
||||||
|
|
||||||
|
## Usage |
||||||
|
|
||||||
|
First, you need to [setup](../../README.md#usage) the `flutter_quill` first |
||||||
|
|
||||||
|
Then you can simply convert to/from HTML |
||||||
|
|
||||||
|
```dart |
||||||
|
import 'package:quill_html_converter/quill_html_converter.dart'; |
||||||
|
|
||||||
|
// Convert Delta to HTML |
||||||
|
final html = _controller.document.toDelta().toHtml(); |
||||||
|
|
||||||
|
// Load Delta document using HTML |
||||||
|
_controller.document = |
||||||
|
Document.fromDelta(DeltaHtmlExt.fromHtml(html)); |
||||||
|
``` |
||||||
|
|
||||||
|
## Additional information |
||||||
|
|
||||||
|
This will be updated soon. |
@ -0,0 +1,36 @@ |
|||||||
|
include: package:flutter_lints/flutter.yaml |
||||||
|
|
||||||
|
analyzer: |
||||||
|
errors: |
||||||
|
undefined_prefixed_name: ignore |
||||||
|
unsafe_html: ignore |
||||||
|
linter: |
||||||
|
rules: |
||||||
|
always_declare_return_types: true |
||||||
|
always_put_required_named_parameters_first: true |
||||||
|
annotate_overrides: true |
||||||
|
avoid_empty_else: true |
||||||
|
avoid_escaping_inner_quotes: true |
||||||
|
avoid_print: true |
||||||
|
avoid_redundant_argument_values: true |
||||||
|
avoid_types_on_closure_parameters: true |
||||||
|
avoid_void_async: true |
||||||
|
cascade_invocations: true |
||||||
|
directives_ordering: true |
||||||
|
omit_local_variable_types: true |
||||||
|
prefer_const_constructors: true |
||||||
|
prefer_const_constructors_in_immutables: true |
||||||
|
prefer_const_declarations: true |
||||||
|
prefer_final_fields: true |
||||||
|
prefer_final_in_for_each: true |
||||||
|
prefer_final_locals: true |
||||||
|
prefer_initializing_formals: true |
||||||
|
prefer_int_literals: true |
||||||
|
prefer_interpolation_to_compose_strings: true |
||||||
|
prefer_relative_imports: true |
||||||
|
prefer_single_quotes: true |
||||||
|
sort_constructors_first: true |
||||||
|
sort_unnamed_constructors_first: true |
||||||
|
unnecessary_lambdas: true |
||||||
|
unnecessary_parenthesis: true |
||||||
|
unnecessary_string_interpolations: true |
@ -0,0 +1,60 @@ |
|||||||
|
library quill_html_converter; |
||||||
|
|
||||||
|
import 'dart:convert' show jsonDecode; |
||||||
|
|
||||||
|
import 'package:delta_markdown_converter/delta_markdown_converter.dart' |
||||||
|
as delta_markdown show markdownToDelta; |
||||||
|
import 'package:flutter_quill/flutter_quill.dart' show Delta; |
||||||
|
import 'package:html2md/html2md.dart' as html2md; |
||||||
|
import 'package:vsc_quill_delta_to_html/vsc_quill_delta_to_html.dart' |
||||||
|
as conventer show ConverterOptions, QuillDeltaToHtmlConverter; |
||||||
|
|
||||||
|
typedef ConverterOptions = conventer.ConverterOptions; |
||||||
|
|
||||||
|
/// A extension for [Delta] which comes from `flutter_quill` to extends |
||||||
|
/// the functionality of it to support converting the [Delta] to/from HTML |
||||||
|
extension DeltaHtmlExt on Delta { |
||||||
|
/// Convert the [Delta] instance to HTML Raw string |
||||||
|
/// |
||||||
|
/// It will run using the following steps: |
||||||
|
/// |
||||||
|
/// 1. Convert the [Delta] to json using [toJson] |
||||||
|
/// 2. Cast the json map as `List<Map<String, dynamic>>` |
||||||
|
/// 3. Pass it to the conventer `vsc_quill_delta_to_html` which is a package |
||||||
|
/// that designed specifically for converting the quill delta to html |
||||||
|
String toHtml({ConverterOptions? options}) { |
||||||
|
final json = toJson(); |
||||||
|
final html = conventer.QuillDeltaToHtmlConverter( |
||||||
|
List.castFrom(json), |
||||||
|
options, |
||||||
|
).convert(); |
||||||
|
return html; |
||||||
|
} |
||||||
|
|
||||||
|
/// Convert the HTML Raw string to [Delta] |
||||||
|
/// |
||||||
|
/// It will run using the following steps: |
||||||
|
/// |
||||||
|
/// 1. Convert the html to markdown string using `html2md` package |
||||||
|
/// 2. Convert the markdown string to quill delta json string |
||||||
|
/// 3. Decode the delta json string to [Delta] |
||||||
|
/// |
||||||
|
/// for more [info](https://github.com/singerdmx/flutter-quill/issues/1100) |
||||||
|
static Delta fromHtml(String html) { |
||||||
|
final markdown = html2md |
||||||
|
.convert( |
||||||
|
html, |
||||||
|
) |
||||||
|
.replaceAll('unsafe:', ''); |
||||||
|
final deltaJsonString = delta_markdown.markdownToDelta(markdown); |
||||||
|
final deltaJson = jsonDecode(deltaJsonString); |
||||||
|
if (deltaJson is! List) { |
||||||
|
throw ArgumentError( |
||||||
|
'The delta json string should be of type list when jsonDecode() it', |
||||||
|
); |
||||||
|
} |
||||||
|
return Delta.fromJson( |
||||||
|
deltaJson, |
||||||
|
); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,36 @@ |
|||||||
|
name: quill_html_converter |
||||||
|
description: A extension for flutter_quill package to add support for dealing with conversion to/from html |
||||||
|
version: 0.0.1-experimental.1 |
||||||
|
homepage: https://github.com/singerdmx/flutter-quill/tree/master/packages/quill_html_converter |
||||||
|
repository: https://github.com/singerdmx/flutter-quill/tree/master/packages/quill_html_converter |
||||||
|
|
||||||
|
topics: |
||||||
|
- ui |
||||||
|
- widgets |
||||||
|
- widget |
||||||
|
- rich-text-editor |
||||||
|
- quill |
||||||
|
|
||||||
|
environment: |
||||||
|
sdk: '>=3.1.5 <4.0.0' |
||||||
|
flutter: ">=1.17.0" |
||||||
|
|
||||||
|
dependencies: |
||||||
|
flutter: |
||||||
|
sdk: flutter |
||||||
|
flutter_quill: ^8.5.1 |
||||||
|
vsc_quill_delta_to_html: ^1.0.3 |
||||||
|
html2md: ^1.3.1 |
||||||
|
# markdown: ^7.1.1 |
||||||
|
charcode: ^1.3.1 |
||||||
|
collection: ^1.17.2 |
||||||
|
delta_markdown_converter: ^0.0.2 |
||||||
|
|
||||||
|
dev_dependencies: |
||||||
|
flutter_test: |
||||||
|
sdk: flutter |
||||||
|
flutter_lints: ^3.0.1 |
||||||
|
|
||||||
|
flutter: |
||||||
|
|
||||||
|
uses-material-design: true |
@ -0,0 +1,3 @@ |
|||||||
|
dependency_overrides: |
||||||
|
flutter_quill: |
||||||
|
path: ../../ |
@ -0,0 +1,7 @@ |
|||||||
|
import 'package:flutter_test/flutter_test.dart'; |
||||||
|
|
||||||
|
void main() { |
||||||
|
test('No tests for now', () { |
||||||
|
expect(true, true); |
||||||
|
}); |
||||||
|
} |
Loading…
Reference in new issue