feat: changed default conversion to dedicated package to convert html to delta

pull/1984/head
CatHood0 9 months ago
parent bb2f579a8e
commit 28114b4486
  1. 30
      lib/src/models/documents/delta_x.dart
  2. 1
      pubspec.yaml
  3. 1
      test/utils/delta_x_test.dart

@ -1,9 +1,8 @@
import 'package:html2md/html2md.dart' as html2md;
import 'package:flutter_quill_delta_from_html/flutter_quill_delta_from_html.dart';
import 'package:markdown/markdown.dart' as md;
import 'package:meta/meta.dart';
import '../../../markdown_quill.dart';
import '../../../quill_delta.dart';
import '../../utils/delta_x_utils.dart';
@immutable
@experimental
@ -16,34 +15,15 @@ class DeltaX {
/// used for **production applications**.
@experimental
static Delta fromMarkdown(String markdownText) {
final mdDocument = md.Document(
encodeHtml: false,
inlineSyntaxes: [UnderlineSyntax(), VideoSyntax()],
);
final mdDocument = md.Document(encodeHtml: false);
final mdToDelta = MarkdownToDelta(markdownDocument: mdDocument);
return mdToDelta.convert(markdownText);
}
/// 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 [Delta] using [fromMarkdown]
///
/// This api is **experimental** and designed to be used **internally** and shouldn't
/// used for **production applications**.
///
@experimental
static Delta fromHtml(String htmlText) {
final markdownText = html2md.convert(
htmlText,
rules: [underlineRule, videoRule],
styleOptions: {'emDelimiter': '*'},
).replaceAll(
'unsafe:',
'',
);
return fromMarkdown(markdownText);
static Delta fromHtml(String htmlText, {List<CustomHtmlPart>? customBlocks}) {
final htmlToDelta = HtmlToDelta(customBlocks: customBlocks);
return htmlToDelta.convert(htmlText);
}
}

@ -54,6 +54,7 @@ dependencies:
flutter_colorpicker: ^1.1.0
# For converting HTML to Quill delta
flutter_quill_delta_from_html: ^1.1.8
markdown: ^7.2.1
html2md: ^1.3.1
charcode: ^1.3.1

@ -33,6 +33,7 @@ void main() {
]);
final expectedDeltaVideo = Delta.fromOperations([
Operation.insert('\n'),
Operation.insert({'video': 'https://www.youtube.com/embed/dQw4w9WgXcQ'}),
Operation.insert('\n'),
]);

Loading…
Cancel
Save