diff --git a/quill_html_converter/lib/quill_html_converter.dart b/quill_html_converter/lib/quill_html_converter.dart index 7ed4fe0b..17c8a889 100644 --- a/quill_html_converter/lib/quill_html_converter.dart +++ b/quill_html_converter/lib/quill_html_converter.dart @@ -1,10 +1,9 @@ library quill_html_converter; import 'package:dart_quill_delta/dart_quill_delta.dart'; -import 'package:vsc_quill_delta_to_html/vsc_quill_delta_to_html.dart' - as conventer show ConverterOptions, QuillDeltaToHtmlConverter; +import 'package:vsc_quill_delta_to_html/vsc_quill_delta_to_html.dart'; -typedef ConverterOptions = conventer.ConverterOptions; +export 'package:vsc_quill_delta_to_html/vsc_quill_delta_to_html.dart'; /// A extension for [Delta] which comes from `flutter_quill` to extends /// the functionality of it to support converting the [Delta] to/from HTML @@ -19,10 +18,33 @@ extension DeltaHtmlExt on Delta { /// that designed specifically for converting the quill delta to html String toHtml({ConverterOptions? options}) { final json = toJson(); - final html = conventer.QuillDeltaToHtmlConverter( + final html = QuillDeltaToHtmlConverter( List.castFrom(json), - options, + options ?? defaultConverterOptions, ).convert(); return html; } } + +ConverterOptions get defaultConverterOptions { + return ConverterOptions( + converterOptions: OpConverterOptions( + customTagAttributes: (op) => parseStyle(op.attributes['style']), + ), + ); +} + +Map? parseStyle(String? style, [Map? attrs]) { + if (style == null || style.isEmpty) return attrs; + + attrs ??= {}; + + for (var e in style.split(';')) { + if ((e = e.trim()).isEmpty) break; + var kv = e.split(':'); + if (kv.length < 2) break; + var key = kv[0].trim(); + attrs[key] = kv[1].trim(); + } + return attrs; +}