Skip to content

Commit

Permalink
Version 0.9.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Sub6Resources committed Feb 1, 2019
1 parent dd07a68 commit 82a1e6b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion lib/flutter_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
56 changes: 38 additions & 18 deletions lib/html_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import 'package:html/dom.dart' as dom;

typedef CustomRender = Widget Function(dom.Node node, List<Widget> 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!
Expand Down Expand Up @@ -757,7 +758,7 @@ class HtmlOldParser extends StatelessWidget {
this.onLinkTap,
this.renderNewlines = false,
this.customRender,
this.blockSpacing = 14.0,
this.blockSpacing,
this.html,
});

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -1282,8 +1285,7 @@ class HtmlOldParser extends StatelessWidget {
mark,
Wrap(
crossAxisAlignment: WrapCrossAlignment.center,
children: _parseNodeList(node.nodes)
)
children: _parseNodeList(node.nodes))
],
),
);
Expand Down Expand Up @@ -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),
),
),
Expand Down Expand Up @@ -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);

Expand All @@ -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),
)
],
)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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 <sub6resources@gmail.com>
homepage: https://github.com/Sub6Resources/flutter_html

Expand Down

0 comments on commit 82a1e6b

Please sign in to comment.