fix: images attributes aren't taked by ConverterOptions

pull/1990/head
CatHood0 10 months ago
parent 7c3e914d6a
commit d9b77a6f2d
  1. 4
      quill_html_converter/lib/quill_html_converter.dart
  2. 5
      quill_html_converter/test/quill_html_converter_test.dart

@ -85,7 +85,9 @@ final _defaultConverterOptions = ConverterOptions(
} }
if (op.isImage()) { if (op.isImage()) {
// Fit images within restricted parent width // 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; return null;
}, },

@ -28,15 +28,16 @@ void main() {
expect(Delta.fromJson(quillDelta).toHtml().trim(), html.trim()); 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 = const html =
'<p><img style="max-width: 100%;object-fit: contain" src="https://img.freepik.com/foto-gratis/belleza-otonal-abstracta-patron-venas-hoja-multicolor-generado-ia_188544-9871.jpg"/></p>'; '<p><img style="max-width: 100%;object-fit: contain;width: 40vh; height:350px; margin: 20px;" src="https://img.freepik.com/foto-gratis/belleza-otonal-abstracta-patron-venas-hoja-multicolor-generado-ia_188544-9871.jpg"/></p>';
final quillDelta = [ final quillDelta = [
{ {
'insert': { 'insert': {
'image': 'image':
'https://img.freepik.com/foto-gratis/belleza-otonal-abstracta-patron-venas-hoja-multicolor-generado-ia_188544-9871.jpg' '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'} {'insert': '\n'}
]; ];

Loading…
Cancel
Save