diff --git a/README.md b/README.md index e16b685619..2fa927abbc 100644 --- a/README.md +++ b/README.md @@ -103,13 +103,13 @@ Add the following to your `pubspec.yaml` file: |------------|-----------|-------|-------------|---------|---------|-------|------|--------|--------|--------| |`a` | `abbr` | `acronym`| `address` | `article`| `aside` | `audio`| `b` | `bdi` | `bdo` | `big` | |`blockquote`| `body` | `br` | `caption` | `cite` | `code` | `data`| `dd` | `del` | `details` | `dfn` | -| `div` | `dl` | `dt` | `em` | `figcaption`| `figure`| `footer`| `h1` | `h2` | `h3` | `h4` | -| `h5` |`h6` | `header` | `hr` | `i` | `iframe`| `img` | `ins` | `kbd`| `li` | `main` | -| `mark` | `nav` | `noscript`|`ol` | `p` | `pre` | `q` | `rp` | `rt` | `ruby` | `s` | -| `samp` | `section` | `small` | `span`| `strike` | `strong`| `sub` | `sup` | `summary` | `svg`| `table`| -| `tbody` | `td` | `template` | `tfoot` | `th` | `thead` |`time` | `tr` | `tt` | `u` | `ul` | -| `var` | `video` | `math`: | `mrow` | `msup` | `msub` | `mover` | `munder` | `msubsup` | `moverunder` | `mfrac` | -| `mlongdiv` | `msqrt` | `mroot` | `mi` | `mn` | `mo` | | | | | | +| `div` | `dl` | `dt` | `em` | `figcaption`| `figure`| `footer`| `font` | `h1` | `h2` | `h3` | +| `h4` | `h5` |`h6` | `header` | `hr` | `i` | `iframe`| `img` | `ins` | `kbd`| `li` | +| `main` | `mark` | `nav` | `noscript`|`ol` | `p` | `pre` | `q` | `rp` | `rt` | `ruby` | +| `s` | `samp` | `section` | `small` | `span`| `strike` | `strong`| `sub` | `sup` | `summary` | `svg`| +| `table` | `tbody` | `td` | `template` | `tfoot` | `th` | `thead` |`time` | `tr` | `tt` | `u` | +| `ul` | `var` | `video` | `math`: | `mrow` | `msup` | `msub` | `mover` | `munder` | `msubsup` | `moverunder` | +| `mfrac` | `mlongdiv` | `msqrt` | `mroot` | `mi` | `mn` | `mo` | | | | | ## Currently Supported CSS Attributes: diff --git a/lib/src/styled_element.dart b/lib/src/styled_element.dart index 6d80f9db80..164f243434 100644 --- a/lib/src/styled_element.dart +++ b/lib/src/styled_element.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter_html/src/css_parser.dart'; import 'package:flutter_html/style.dart'; import 'package:html/dom.dart' as dom; //TODO(Sub6Resources): don't use the internal code of the html package as it may change unexpectedly. @@ -179,6 +180,17 @@ StyledElement parseStyledElement( display: Display.BLOCK, ); break; + case "font": + styledElement.style = Style( + color: element.attributes['color'] != null ? + element.attributes['color']!.startsWith("#") ? + ExpressionMapping.stringToColor(element.attributes['color']!) : + ExpressionMapping.namedColorToColor(element.attributes['color']!) : + null, + fontFamily: element.attributes['face']?.split(",").first, + fontSize: numberToFontSize(element.attributes['size'] ?? ''), + ); + break; case "h1": styledElement.style = Style( fontSize: FontSize.xxLarge, @@ -368,3 +380,31 @@ StyledElement parseStyledElement( } typedef ListCharacter = String Function(int i); + +FontSize numberToFontSize(String num) { + switch (num) { + case "1": + return FontSize.xxSmall; + case "2": + return FontSize.xSmall; + case "3": + return FontSize.small; + case "4": + return FontSize.medium; + case "5": + return FontSize.large; + case "6": + return FontSize.xLarge; + case "7": + return FontSize.xxLarge; + } + if (num.startsWith("+")) { + final relativeNum = double.tryParse(num.substring(1)) ?? 0; + return numberToFontSize((3 + relativeNum).toString()); + } + if (num.startsWith("-")) { + final relativeNum = double.tryParse(num.substring(1)) ?? 0; + return numberToFontSize((3 - relativeNum).toString()); + } + return FontSize.medium; +} \ No newline at end of file