flutter_html icon indicating copy to clipboard operation
flutter_html copied to clipboard

[BUG] `<p>&nbsp;</p>` does not create empty space from `3.0.0-beta.2`

Open mkucharski17 opened this issue 1 year ago • 2 comments

Describe the bug: <p>&nbsp;</p> should create space, but starting from version 3.0.0-beta.2 it is ignored. It works properly in version 3.0.0-beta.1

HTML to reproduce the issue: <p>Paragraph before nbsp<\p><p>&nbsp;<p/><p>Paragraph after nbsp<\p>

Html widget configuration:

        Html(
              data:
                  "<p>Paragraph before nbsp<\p><p>&nbsp;<p/><p>Paragraph after nbsp<\p>",
              style: {
                'p': Style(margin: Margins.all(0)),
              },
            ),

Expected behavior: It should create empty space.

Screenshots:

Screen using version 3.0.0-beta.2 Screen using version 3.0.0-beta.1
bad_behavior good_behavior

Device details and Flutter/Dart/flutter_html versions:

Flutter 3.22.2 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 761747bfc5 (3 miesiące temu) • 2024-06-05 22:15:13 +0200
Engine • revision edd8546116
Tools • Dart 3.4.3 • DevTools 2.34.3

mkucharski17 avatar Sep 06 '24 13:09 mkucharski17

Currently the whitespace.dart file removes the &nbsp treating it as a whitespace, and then removes the now-empty p element:

https://github.com/Sub6Resources/flutter_html/blob/79ec194fa6690e5caba58f5eca04e6748394bb6b/lib/src/processing/whitespace.dart#L16-L17

That's not consistent with how browsers treat such paragraphs. An empty paragraph with a non-breakable space is often used by WYSIWYG editors in CMSes for empty spaces.

Albert221 avatar Sep 06 '24 13:09 Albert221

I agree. This is probably related to #1440 and the html parser taking nbsp processing into its own hands

Sub6Resources avatar Mar 12 '25 03:03 Sub6Resources