diff --git a/CHANGELOG.md b/CHANGELOG.md index dd0e9f1062..4f66a560c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [0.9.1] - January 31, 2019: + +* Adds full support for `sub` and `sup`. ([#46](https://github.com/Sub6Resources/flutter_html/pull/46)) +* Fixes weak warning caught by Pub analysis ([#54](https://github.com/Sub6Resources/flutter_html/issues/54)) + ## [0.9.0] - January 31, 2019: * Adds an alternate `RichText` parser and `useRichText` parameter. ([#37](https://github.com/Sub6Resources/flutter_html/pull/37)) diff --git a/README.md b/README.md index 70a7b278b3..52279d2e3a 100644 --- a/README.md +++ b/README.md @@ -8,10 +8,10 @@ A Flutter widget for rendering static html tags as Flutter widgets. (Will render Add the following to your `pubspec.yaml` file: dependencies: - flutter_html: ^0.9.0 + flutter_html: ^0.9.1 ## Currently Supported HTML Tags: -`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` +`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` ### Partially supported elements: > 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: ### List of _planned_ supported elements: > These are elements that are planned, but present a specific challenge that makes them somewhat difficult to implement. -`audio`, `details`, `source`, `sub`, `summary`, `sup`, `svg`, `track`, `video`, `wbr` +`audio`, `details`, `source`, `summary`, `svg`, `track`, `video`, `wbr` ### List of elements that I don't plan on implementing: diff --git a/lib/flutter_html.dart b/lib/flutter_html.dart index dd383fbf56..49399c2fd4 100644 --- a/lib/flutter_html.dart +++ b/lib/flutter_html.dart @@ -13,7 +13,7 @@ class Html extends StatelessWidget { this.onLinkTap, this.renderNewlines = false, this.customRender, - this.blockSpacing, + this.blockSpacing = 14.0, this.useRichText = false, }) : super(key: key); diff --git a/lib/html_parser.dart b/lib/html_parser.dart index adc996ef41..cc54c1fc39 100644 --- a/lib/html_parser.dart +++ b/lib/html_parser.dart @@ -5,7 +5,8 @@ import 'package:html/dom.dart' as dom; typedef CustomRender = Widget Function(dom.Node node, List children); typedef OnLinkTap = void Function(String url); -const OFFSET_TAGS_FONT_SIZE_FACTOR = 0.7; //The ratio of the parent font for each of the offset tags: sup or sub +const OFFSET_TAGS_FONT_SIZE_FACTOR = + 0.7; //The ratio of the parent font for each of the offset tags: sup or sub class LinkTextSpan extends TextSpan { // Beware! @@ -757,7 +758,7 @@ class HtmlOldParser extends StatelessWidget { this.onLinkTap, this.renderNewlines = false, this.customRender, - this.blockSpacing = 14.0, + this.blockSpacing, this.html, }); @@ -868,7 +869,7 @@ class HtmlOldParser extends StatelessWidget { Widget _parseNode(dom.Node node) { if (customRender != null) { final Widget customWidget = - customRender(node, _parseNodeList(node.nodes)); + customRender(node, _parseNodeList(node.nodes)); if (customWidget != null) { return customWidget; } @@ -981,7 +982,8 @@ class HtmlOldParser extends StatelessWidget { ); case "blockquote": return Padding( - padding: EdgeInsets.fromLTRB(40.0, blockSpacing, 40.0, blockSpacing), + padding: + EdgeInsets.fromLTRB(40.0, blockSpacing, 40.0, blockSpacing), child: Container( width: width, child: Wrap( @@ -1104,7 +1106,8 @@ class HtmlOldParser extends StatelessWidget { ); case "figure": return Padding( - padding: EdgeInsets.fromLTRB(40.0, blockSpacing, 40.0, blockSpacing), + padding: + EdgeInsets.fromLTRB(40.0, blockSpacing, 40.0, blockSpacing), child: Column( children: _parseNodeList(node.nodes), crossAxisAlignment: CrossAxisAlignment.center, @@ -1282,8 +1285,7 @@ class HtmlOldParser extends StatelessWidget { mark, Wrap( crossAxisAlignment: WrapCrossAlignment.center, - children: _parseNodeList(node.nodes) - ) + children: _parseNodeList(node.nodes)) ], ), ); @@ -1334,7 +1336,7 @@ class HtmlOldParser extends StatelessWidget { width: width, child: Wrap( crossAxisAlignment: WrapCrossAlignment.center, - alignment: WrapAlignment.start, //@ominibyte Added this for when the line breaks. I think it looks better + alignment: WrapAlignment.start, children: _parseNodeList(node.nodes), ), ), @@ -1433,19 +1435,32 @@ class HtmlOldParser extends StatelessWidget { ); case "sub": case "sup": - //Use builder to capture the parent font to inherit the font styles - return Builder(builder: (BuildContext context){ + //Use builder to capture the parent font to inherit the font styles + return Builder(builder: (BuildContext context) { final DefaultTextStyle parent = DefaultTextStyle.of(context); TextStyle parentStyle = parent.style; - var painter = new TextPainter(text: new TextSpan(text: node.text, style: parentStyle,), textDirection: TextDirection.ltr); + var painter = new TextPainter( + text: new TextSpan( + text: node.text, + style: parentStyle, + ), + textDirection: TextDirection.ltr); painter.layout(); //print(painter.size); //Get the height from the default text - var height = painter.size.height * 1.35; //compute a higher height for the text to increase the offset of the Positioned text - - painter = new TextPainter(text: new TextSpan(text: node.text, style: parentStyle.merge(TextStyle(fontSize: parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR)),), textDirection: TextDirection.ltr); + var height = painter.size.height * + 1.35; //compute a higher height for the text to increase the offset of the Positioned text + + painter = new TextPainter( + text: new TextSpan( + text: node.text, + style: parentStyle.merge(TextStyle( + fontSize: + parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR)), + ), + textDirection: TextDirection.ltr); painter.layout(); //print(painter.size); @@ -1463,14 +1478,19 @@ class HtmlOldParser extends StatelessWidget { children: [ //The Stack needs a non-positioned object for the next widget to respect the space so we create //a sized box to fill the required space - SizedBox(width: width, height: height,), + SizedBox( + width: width, + height: height, + ), DefaultTextStyle.merge( child: Positioned( child: Wrap(children: _parseNodeList(node.nodes)), bottom: node.localName == "sub" ? 0 : null, top: node.localName == "sub" ? null : 0, ), - style: TextStyle(fontSize: parentStyle.fontSize * OFFSET_TAGS_FONT_SIZE_FACTOR), + style: TextStyle( + fontSize: parentStyle.fontSize * + OFFSET_TAGS_FONT_SIZE_FACTOR), ) ], ) @@ -1501,7 +1521,7 @@ class HtmlOldParser extends StatelessWidget { ), ); case "template": - //Not usually displayed in HTML + //Not usually displayed in HTML return Container(); case "tfoot": return Column( @@ -1579,7 +1599,7 @@ class HtmlOldParser extends StatelessWidget { return Wrap(); } if (node.text.trim() == "" && node.text.indexOf(" ") != -1) { - node.text = "";//@ominibyte Looks better without the space + node.text = " "; } String finalText = trimStringHtml(node.text); diff --git a/pubspec.yaml b/pubspec.yaml index 5450c8afe1..6b561a39b1 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_html description: A Flutter widget for rendering static html tags as Flutter widgets. (Will render over 70 different html tags!) -version: 0.9.0 +version: 0.9.1 author: Matthew Whitaker homepage: https://github.com/Sub6Resources/flutter_html