Skip to content

Commit 82a1e6b

Browse files
committed
Version 0.9.1
1 parent dd07a68 commit 82a1e6b

File tree

5 files changed

+48
-23
lines changed

5 files changed

+48
-23
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [0.9.1] - January 31, 2019:
2+
3+
* Adds full support for `sub` and `sup`. ([#46](https://github.com/Sub6Resources/flutter_html/pull/46))
4+
* Fixes weak warning caught by Pub analysis ([#54](https://github.com/Sub6Resources/flutter_html/issues/54))
5+
16
## [0.9.0] - January 31, 2019:
27

38
* Adds an alternate `RichText` parser and `useRichText` parameter. ([#37](https://github.com/Sub6Resources/flutter_html/pull/37))

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ A Flutter widget for rendering static html tags as Flutter widgets. (Will render
88
Add the following to your `pubspec.yaml` file:
99

1010
dependencies:
11-
flutter_html: ^0.9.0
11+
flutter_html: ^0.9.1
1212

1313
## Currently Supported HTML Tags:
14-
`a`, `abbr`, `acronym`, `address`, `article`, `aside`, `b`, `bdi`, `bdo`, `big`, `blockquote`, `body`, `br`, `caption`, `cite`, `code`, `data`, `dd`, `del`, `dfn`, `div`, `dl`, `dt`, `em`, `figcaption`, `figure`, `footer`, `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `header`, `hr`, `i`, `img`, `ins`, `kbd`, `li`, `main`, `mark`, `nav`, `noscript`, `ol`, `p`, `pre`, `q`, `rp`, `rt`, `ruby`, `s`, `samp`, `section`, `small`, `span`, `strike`, `strong`, `table`, `tbody`, `td`, `template`, `tfoot`, `th`, `thead`, `time`, `tr`, `tt`, `u`, `ul`, `var`
14+
`a`, `abbr`, `acronym`, `address`, `article`, `aside`, `b`, `bdi`, `bdo`, `big`, `blockquote`, `body`, `br`, `caption`, `cite`, `code`, `data`, `dd`, `del`, `dfn`, `div`, `dl`, `dt`, `em`, `figcaption`, `figure`, `footer`, `h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `header`, `hr`, `i`, `img`, `ins`, `kbd`, `li`, `main`, `mark`, `nav`, `noscript`, `ol`, `p`, `pre`, `q`, `rp`, `rt`, `ruby`, `s`, `samp`, `section`, `small`, `span`, `strike`, `strong`, `sub`, `sup`, `table`, `tbody`, `td`, `template`, `tfoot`, `th`, `thead`, `time`, `tr`, `tt`, `u`, `ul`, `var`
1515

1616
### Partially supported elements:
1717
> These are common elements that aren't yet fully supported, but won't be ignored and will still render somewhat correctly.
@@ -21,7 +21,7 @@ Add the following to your `pubspec.yaml` file:
2121
### List of _planned_ supported elements:
2222
> These are elements that are planned, but present a specific challenge that makes them somewhat difficult to implement.
2323
24-
`audio`, `details`, `source`, `sub`, `summary`, `sup`, `svg`, `track`, `video`, `wbr`
24+
`audio`, `details`, `source`, `summary`, `svg`, `track`, `video`, `wbr`
2525

2626
### List of elements that I don't plan on implementing:
2727

lib/flutter_html.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Html extends StatelessWidget {
1313
this.onLinkTap,
1414
this.renderNewlines = false,
1515
this.customRender,
16-
this.blockSpacing,
16+
this.blockSpacing = 14.0,
1717
this.useRichText = false,
1818
}) : super(key: key);
1919

lib/html_parser.dart

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import 'package:html/dom.dart' as dom;
55

66
typedef CustomRender = Widget Function(dom.Node node, List<Widget> children);
77
typedef OnLinkTap = void Function(String url);
8-
const OFFSET_TAGS_FONT_SIZE_FACTOR = 0.7; //The ratio of the parent font for each of the offset tags: sup or sub
8+
const OFFSET_TAGS_FONT_SIZE_FACTOR =
9+
0.7; //The ratio of the parent font for each of the offset tags: sup or sub
910

1011
class LinkTextSpan extends TextSpan {
1112
// Beware!
@@ -757,7 +758,7 @@ class HtmlOldParser extends StatelessWidget {
757758
this.onLinkTap,
758759
this.renderNewlines = false,
759760
this.customRender,
760-
this.blockSpacing = 14.0,
761+
this.blockSpacing,
761762
this.html,
762763
});
763764

@@ -868,7 +869,7 @@ class HtmlOldParser extends StatelessWidget {
868869
Widget _parseNode(dom.Node node) {
869870
if (customRender != null) {
870871
final Widget customWidget =
871-
customRender(node, _parseNodeList(node.nodes));
872+
customRender(node, _parseNodeList(node.nodes));
872873
if (customWidget != null) {
873874
return customWidget;
874875
}
@@ -981,7 +982,8 @@ class HtmlOldParser extends StatelessWidget {
981982
);
982983
case "blockquote":
983984
return Padding(
984-
padding: EdgeInsets.fromLTRB(40.0, blockSpacing, 40.0, blockSpacing),
985+
padding:
986+
EdgeInsets.fromLTRB(40.0, blockSpacing, 40.0, blockSpacing),
985987
child: Container(
986988
width: width,
987989
child: Wrap(
@@ -1104,7 +1106,8 @@ class HtmlOldParser extends StatelessWidget {
11041106
);
11051107
case "figure":
11061108
return Padding(
1107-
padding: EdgeInsets.fromLTRB(40.0, blockSpacing, 40.0, blockSpacing),
1109+
padding:
1110+
EdgeInsets.fromLTRB(40.0, blockSpacing, 40.0, blockSpacing),
11081111
child: Column(
11091112
children: _parseNodeList(node.nodes),
11101113
crossAxisAlignment: CrossAxisAlignment.center,
@@ -1282,8 +1285,7 @@ class HtmlOldParser extends StatelessWidget {
12821285
mark,
12831286
Wrap(
12841287
crossAxisAlignment: WrapCrossAlignment.center,
1285-
children: _parseNodeList(node.nodes)
1286-
)
1288+
children: _parseNodeList(node.nodes))
12871289
],
12881290
),
12891291
);
@@ -1334,7 +1336,7 @@ class HtmlOldParser extends StatelessWidget {
13341336
width: width,
13351337
child: Wrap(
13361338
crossAxisAlignment: WrapCrossAlignment.center,
1337-
alignment: WrapAlignment.start, //@ominibyte Added this for when the line breaks. I think it looks better
1339+
alignment: WrapAlignment.start,
13381340
children: _parseNodeList(node.nodes),
13391341
),
13401342
),
@@ -1433,19 +1435,32 @@ class HtmlOldParser extends StatelessWidget {
14331435
);
14341436
case "sub":
14351437
case "sup":
1436-
//Use builder to capture the parent font to inherit the font styles
1437-
return Builder(builder: (BuildContext context){
1438+
//Use builder to capture the parent font to inherit the font styles
1439+
return Builder(builder: (BuildContext context) {
14381440
final DefaultTextStyle parent = DefaultTextStyle.of(context);
14391441
TextStyle parentStyle = parent.style;
14401442

1441-
var painter = new TextPainter(text: new TextSpan(text: node.text, style: parentStyle,), textDirection: TextDirection.ltr);
1443+
var painter = new TextPainter(
1444+
text: new TextSpan(
1445+
text: node.text,
1446+
style: parentStyle,
1447+
),
1448+
textDirection: TextDirection.ltr);
14421449
painter.layout();
14431450
//print(painter.size);
14441451

14451452
//Get the height from the default text
1446-
var height = painter.size.height * 1.35; //compute a higher height for the text to increase the offset of the Positioned text
1447-
1448-
painter = new TextPainter(text: new TextSpan(text: node.text, style: parentStyle.merge(TextStyle(fontSize: parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR)),), textDirection: TextDirection.ltr);
1453+
var height = painter.size.height *
1454+
1.35; //compute a higher height for the text to increase the offset of the Positioned text
1455+
1456+
painter = new TextPainter(
1457+
text: new TextSpan(
1458+
text: node.text,
1459+
style: parentStyle.merge(TextStyle(
1460+
fontSize:
1461+
parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR)),
1462+
),
1463+
textDirection: TextDirection.ltr);
14491464
painter.layout();
14501465
//print(painter.size);
14511466

@@ -1463,14 +1478,19 @@ class HtmlOldParser extends StatelessWidget {
14631478
children: [
14641479
//The Stack needs a non-positioned object for the next widget to respect the space so we create
14651480
//a sized box to fill the required space
1466-
SizedBox(width: width, height: height,),
1481+
SizedBox(
1482+
width: width,
1483+
height: height,
1484+
),
14671485
DefaultTextStyle.merge(
14681486
child: Positioned(
14691487
child: Wrap(children: _parseNodeList(node.nodes)),
14701488
bottom: node.localName == "sub" ? 0 : null,
14711489
top: node.localName == "sub" ? null : 0,
14721490
),
1473-
style: TextStyle(fontSize: parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR),
1491+
style: TextStyle(
1492+
fontSize: parentStyle.fontSize *
1493+
OFFSET_TAGS_FONT_SIZE_FACTOR),
14741494
)
14751495
],
14761496
)
@@ -1501,7 +1521,7 @@ class HtmlOldParser extends StatelessWidget {
15011521
),
15021522
);
15031523
case "template":
1504-
//Not usually displayed in HTML
1524+
//Not usually displayed in HTML
15051525
return Container();
15061526
case "tfoot":
15071527
return Column(
@@ -1579,7 +1599,7 @@ class HtmlOldParser extends StatelessWidget {
15791599
return Wrap();
15801600
}
15811601
if (node.text.trim() == "" && node.text.indexOf(" ") != -1) {
1582-
node.text = "";//@ominibyte Looks better without the space
1602+
node.text = " ";
15831603
}
15841604

15851605
String finalText = trimStringHtml(node.text);

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: flutter_html
22
description: A Flutter widget for rendering static html tags as Flutter widgets. (Will render over 70 different html tags!)
3-
version: 0.9.0
3+
version: 0.9.1
44
author: Matthew Whitaker <sub6resources@gmail.com>
55
homepage: https://github.com/Sub6Resources/flutter_html
66

0 commit comments

Comments
 (0)