Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<li> issues with block children #123

Closed
cpboyd opened this issue Jul 12, 2019 · 2 comments · Fixed by #122
Closed

<li> issues with block children #123

cpboyd opened this issue Jul 12, 2019 · 2 comments · Fixed by #122
Labels
bug Something isn't working
Milestone

Comments

@cpboyd
Copy link

cpboyd commented Jul 12, 2019

So, I've got content that is of the form:

<li><p>Text</p></li>

The leadingChar never gets rendered because there's no direct TextSpan child.
This appears to be because of the root node reset: https://github.com/Sub6Resources/flutter_html/blob/master/lib/rich_text_parser.dart#L716

@cpboyd cpboyd changed the title <li> (and likely other blocks) with <p> children <li> issues with block children Jul 12, 2019
@cpboyd
Copy link
Author

cpboyd commented Jul 12, 2019

One workaround that I used for my specific issue with <li> elements:

  BlockText withLeadingChar(String newLeadingChar) {
    return BlockText(
      child: child,
      padding: padding,
      margin: margin,
      leadingChar: newLeadingChar,
      decoration: decoration,
    );
  }

...

    // filter out empty widgets
    List<Widget> children = [];
    String skippedLeadingChar = '';
    widgetList.forEach((dynamic w) {
      if (w is BlockText) {
        if (!isEmpty(skippedLeadingChar) && isEmpty(w.leadingChar)) {
          w = w.withLeadingChar(skippedLeadingChar);
        }
        if (w.child.text == null) return;
        TextSpan childTextSpan = w.child.text;
        if (isEmpty(childTextSpan.text) &&
            (childTextSpan.children == null ||
                childTextSpan.children.isEmpty)) {
          if (!isEmpty(w.leadingChar)) {
            skippedLeadingChar = w.leadingChar;
          }
          return;
        }
      } else if (w is LinkBlock) {
        if (w.children.isEmpty) return;
      } else if (w is LinkTextSpan) {
        if (w.text.isEmpty && w.children.isEmpty) return;
      }
      children.add(w);
      skippedLeadingChar = '';
    });

@Sub6Resources
Copy link
Owner

Ah, thanks for the bug report. I'll work on getting this issue fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants