From d9b77a6f2df962e78b05934cd564392aec5f4d8a Mon Sep 17 00:00:00 2001 From: CatHood0 Date: Mon, 8 Jul 2024 20:55:22 -0400 Subject: [PATCH] fix: images attributes aren't taked by ConverterOptions --- quill_html_converter/lib/quill_html_converter.dart | 4 +++- quill_html_converter/test/quill_html_converter_test.dart | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/quill_html_converter/lib/quill_html_converter.dart b/quill_html_converter/lib/quill_html_converter.dart index d8c6082f..0075bcb5 100644 --- a/quill_html_converter/lib/quill_html_converter.dart +++ b/quill_html_converter/lib/quill_html_converter.dart @@ -85,7 +85,9 @@ final _defaultConverterOptions = ConverterOptions( } if (op.isImage()) { // Fit images within restricted parent width - return ['max-width: 100%', 'object-fit: contain']; + final String? styles = op.attributes['style']; + final listStyles = styles?.split(';') ?? []; + return ['max-width: 100%', 'object-fit: contain', ...listStyles]; } return null; }, diff --git a/quill_html_converter/test/quill_html_converter_test.dart b/quill_html_converter/test/quill_html_converter_test.dart index aefe3822..7996c696 100644 --- a/quill_html_converter/test/quill_html_converter_test.dart +++ b/quill_html_converter/test/quill_html_converter_test.dart @@ -28,15 +28,16 @@ void main() { expect(Delta.fromJson(quillDelta).toHtml().trim(), html.trim()); }); - test('should parse block image embed to html', () { + test("should parse block image embed with it's attributes to html", () { const html = - '

'; + '

'; final quillDelta = [ { 'insert': { 'image': 'https://img.freepik.com/foto-gratis/belleza-otonal-abstracta-patron-venas-hoja-multicolor-generado-ia_188544-9871.jpg' }, + 'attributes': {'style': 'width: 40vh; height:350px; margin: 20px;'} }, {'insert': '\n'} ];