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

font support missing in Rich Text Parser #137

Closed
SoftWyer opened this issue Aug 3, 2019 · 2 comments
Closed

font support missing in Rich Text Parser #137

SoftWyer opened this issue Aug 3, 2019 · 2 comments

Comments

@SoftWyer
Copy link

SoftWyer commented Aug 3, 2019

The Rich Text parser is missing support for the <font /> tag and thus renders no content. The HTML parser has this support.

I've modified the parser to accept font and to also render the color if it's a HEX string. I'll see if I can arrange for a pull request, e.g.

          case "strong":
            childStyle = childStyle.merge(TextStyle(fontWeight: FontWeight.bold));
            break;
          case "font":
            Color c;
            String color = node.attributes['color'] ?? '';
            if (color.startsWith('#')) {
              // A hex color
              c = HexToColor(color);
            }
            childStyle = childStyle.merge(TextStyle(
              color: c,
            ));
            break;
          case "i":

HexToColor is a simple class to render the hex string, e.g.

class HexToColor extends Color{
  static _hexToColor(String code) {
    return int.parse(code.substring(1, 7), radix: 16) + 0xFF000000;
  }
  HexToColor(final String code) : super(_hexToColor(code));
}

In theory, font takes an 'rgb(a,b,c)' string too so that should be easy to implement. It also handles color names such as 'red' but I can't see an easy way of converting these to a Color object

It's possible that we could do something with the size argument of font too but I currently don't need that option.

@SoftWyer
Copy link
Author

PR raised -> #138

@erickok
Copy link
Collaborator

erickok commented Feb 8, 2021

We have inline style support now, which is really what your html should be using.

If support for the legacy (html 4 and lower) tag is still something you desire, please re-open this ticket. We would add it I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants