Skip to content

Commit a226c49

Browse files
authored
Merge pull request #694 from tneotia/feature/font-tag
Add support for the font tag
2 parents 04fe962 + 03921d8 commit a226c49

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ Add the following to your `pubspec.yaml` file:
103103
|------------|-----------|-------|-------------|---------|---------|-------|------|--------|--------|--------|
104104
|`a` | `abbr` | `acronym`| `address` | `article`| `aside` | `audio`| `b` | `bdi` | `bdo` | `big` |
105105
|`blockquote`| `body` | `br` | `caption` | `cite` | `code` | `data`| `dd` | `del` | `details` | `dfn` |
106-
| `div` | `dl` | `dt` | `em` | `figcaption`| `figure`| `footer`| `h1` | `h2` | `h3` | `h4` |
107-
| `h5` |`h6` | `header` | `hr` | `i` | `iframe`| `img` | `ins` | `kbd`| `li` | `main` |
108-
| `mark` | `nav` | `noscript`|`ol` | `p` | `pre` | `q` | `rp` | `rt` | `ruby` | `s` |
109-
| `samp` | `section` | `small` | `span`| `strike` | `strong`| `sub` | `sup` | `summary` | `svg`| `table`|
110-
| `tbody` | `td` | `template` | `tfoot` | `th` | `thead` |`time` | `tr` | `tt` | `u` | `ul` |
111-
| `var` | `video` | `math`: | `mrow` | `msup` | `msub` | `mover` | `munder` | `msubsup` | `moverunder` | `mfrac` |
112-
| `mlongdiv` | `msqrt` | `mroot` | `mi` | `mn` | `mo` | | | | | |
106+
| `div` | `dl` | `dt` | `em` | `figcaption`| `figure`| `footer`| `font` | `h1` | `h2` | `h3` |
107+
| `h4` | `h5` |`h6` | `header` | `hr` | `i` | `iframe`| `img` | `ins` | `kbd`| `li` |
108+
| `main` | `mark` | `nav` | `noscript`|`ol` | `p` | `pre` | `q` | `rp` | `rt` | `ruby` |
109+
| `s` | `samp` | `section` | `small` | `span`| `strike` | `strong`| `sub` | `sup` | `summary` | `svg`|
110+
| `table` | `tbody` | `td` | `template` | `tfoot` | `th` | `thead` |`time` | `tr` | `tt` | `u` |
111+
| `ul` | `var` | `video` | `math`: | `mrow` | `msup` | `msub` | `mover` | `munder` | `msubsup` | `moverunder` |
112+
| `mfrac` | `mlongdiv` | `msqrt` | `mroot` | `mi` | `mn` | `mo` | | | | |
113113

114114

115115
## Currently Supported CSS Attributes:

lib/src/styled_element.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:flutter_html/src/css_parser.dart';
23
import 'package:flutter_html/style.dart';
34
import 'package:html/dom.dart' as dom;
45
//TODO(Sub6Resources): don't use the internal code of the html package as it may change unexpectedly.
@@ -179,6 +180,17 @@ StyledElement parseStyledElement(
179180
display: Display.BLOCK,
180181
);
181182
break;
183+
case "font":
184+
styledElement.style = Style(
185+
color: element.attributes['color'] != null ?
186+
element.attributes['color']!.startsWith("#") ?
187+
ExpressionMapping.stringToColor(element.attributes['color']!) :
188+
ExpressionMapping.namedColorToColor(element.attributes['color']!) :
189+
null,
190+
fontFamily: element.attributes['face']?.split(",").first,
191+
fontSize: numberToFontSize(element.attributes['size'] ?? ''),
192+
);
193+
break;
182194
case "h1":
183195
styledElement.style = Style(
184196
fontSize: FontSize.xxLarge,
@@ -368,3 +380,31 @@ StyledElement parseStyledElement(
368380
}
369381

370382
typedef ListCharacter = String Function(int i);
383+
384+
FontSize numberToFontSize(String num) {
385+
switch (num) {
386+
case "1":
387+
return FontSize.xxSmall;
388+
case "2":
389+
return FontSize.xSmall;
390+
case "3":
391+
return FontSize.small;
392+
case "4":
393+
return FontSize.medium;
394+
case "5":
395+
return FontSize.large;
396+
case "6":
397+
return FontSize.xLarge;
398+
case "7":
399+
return FontSize.xxLarge;
400+
}
401+
if (num.startsWith("+")) {
402+
final relativeNum = double.tryParse(num.substring(1)) ?? 0;
403+
return numberToFontSize((3 + relativeNum).toString());
404+
}
405+
if (num.startsWith("-")) {
406+
final relativeNum = double.tryParse(num.substring(1)) ?? 0;
407+
return numberToFontSize((3 - relativeNum).toString());
408+
}
409+
return FontSize.medium;
410+
}

0 commit comments

Comments
 (0)