Skip to content

Commit 90c0daa

Browse files
committed
Version 0.9.5
1 parent 2fbf45b commit 90c0daa

File tree

6 files changed

+118
-17
lines changed

6 files changed

+118
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [0.9.5] - March 11, 2019:
2+
3+
* Add support for `span` in `RichText` parser. ([#61](https://github.com/Sub6Resources/flutter_html/issues/61))
4+
* Adds `linkStyle` attribute. ([#70](https://github.com/Sub6Resources/flutter_html/pull/70))
5+
* Adds tests for `header`, `hr`, and `i` ([#62](https://github.com/Sub6Resources/flutter_html/issues/62))
6+
17
## [0.9.4] - February 5, 2019:
28

39
* Fixes `table` error in `RichText` parser. ([#58](https://github.com/Sub6Resources/flutter_html/issues/58))

README.md

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

1111
dependencies:
12-
flutter_html: ^0.9.4
12+
flutter_html: ^0.9.5
1313

1414
## Currently Supported HTML Tags:
1515
`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`
@@ -68,6 +68,9 @@ Check out the official Flutter WebView package here: https://pub.dartlang.org/pa
6868
padding: EdgeInsets.all(8.0),
6969
backgroundColor: Colors.white70,
7070
defaultTextStyle: TextStyle(fontFamily: 'serif'),
71+
linkStyle: const TextStyle(
72+
color: Colors.redAccent,
73+
),
7174
onLinkTap: (url) {
7275
// open url in a webview
7376
},
@@ -85,4 +88,4 @@ Check out the official Flutter WebView package here: https://pub.dartlang.org/pa
8588

8689
This package has a known issue where text does not wrap correctly. Setting `useRichText` to true fixes the issue
8790
by using an alternate parser. The alternate parser, however, does not support the `customRender` callback, and several elements
88-
supported by the default parser are not supported by the alternate parser.
91+
supported by the default parser are not supported by the alternate parser (see [#61](https://github.com/Sub6Resources/flutter_html/issues/61) for a list).

example/main.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ class _MyHomePageState extends State<MyHomePage> {
121121
""",
122122
//Optional parameters:
123123
padding: EdgeInsets.all(8.0),
124+
linkStyle: const TextStyle(
125+
color: Colors.redAccent,
126+
decorationColor: Colors.redAccent,
127+
decoration: TextDecoration.underline,
128+
),
124129
onLinkTap: (url) {
125130
print("Opening $url...");
126131
},

lib/html_parser.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ class HtmlRichTextParser extends StatelessWidget {
173173
"acronym",
174174
"ol",
175175
"ul",
176-
"blockquote"
176+
"blockquote",
177+
"span",
177178
];
178179

179180
// specialty elements require unique handling
@@ -476,6 +477,9 @@ class HtmlRichTextParser extends StatelessWidget {
476477
nextContext.indentLevel += 1;
477478
nextContext.blockType = 'blockquote';
478479
break;
480+
case "span":
481+
//No additional styles
482+
break;
479483
}
480484
nextContext.childStyle = childStyle;
481485
}
@@ -1275,10 +1279,7 @@ class HtmlOldParser extends StatelessWidget {
12751279
case "hr":
12761280
return Padding(
12771281
padding: EdgeInsets.only(top: 7.0, bottom: 7.0),
1278-
child: Container(
1279-
height: 0.0,
1280-
decoration: BoxDecoration(border: Border.all()),
1281-
),
1282+
child: Divider(height: 1.0, color: Colors.black38),
12821283
);
12831284
case "i":
12841285
return DefaultTextStyle.merge(

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.4
3+
version: 0.9.5
44
author: Matthew Whitaker <sub6resources@gmail.com>
55
homepage: https://github.com/Sub6Resources/flutter_html
66

test/html_parser_test.dart

Lines changed: 95 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import 'package:flutter_test/flutter_test.dart';
44
import 'package:flutter_html/flutter_html.dart';
55

66
void main() {
7-
8-
testWidgets("Check that default parser does not fail on empty data", (tester) async {
7+
testWidgets("Check that default parser does not fail on empty data",
8+
(tester) async {
99
await tester.pumpWidget(
1010
MaterialApp(
1111
home: Scaffold(
@@ -17,7 +17,8 @@ void main() {
1717
);
1818
});
1919

20-
testWidgets("Check that RichText parser does not fail on empty data", (tester) async {
20+
testWidgets("Check that RichText parser does not fail on empty data",
21+
(tester) async {
2122
await tester.pumpWidget(
2223
MaterialApp(
2324
home: Scaffold(
@@ -59,7 +60,8 @@ void main() {
5960
expect(find.byType(RichText), findsOneWidget);
6061
});
6162

62-
testWidgets("Check that tapping on the `a` tag calls the callback", (tester) async {
63+
testWidgets("Check that tapping on the `a` tag calls the callback",
64+
(tester) async {
6365
String html = "<a href='https://github.com'>Test link</a>";
6466
String urlTapped;
6567

@@ -79,7 +81,9 @@ void main() {
7981
expect(urlTapped, "https://github.com");
8082
});
8183

82-
testWidgets("Check that tapping on the `a` tag calls the callback `RichText` parser", (tester) async {
84+
testWidgets(
85+
"Check that tapping on the `a` tag calls the callback `RichText` parser",
86+
(tester) async {
8387
String html = "<a href='https://github.com'>Test link</a>";
8488
String urlTapped;
8589

@@ -112,7 +116,6 @@ void main() {
112116
),
113117
);
114118

115-
116119
expect(find.text("Abbreviation"), findsOneWidget);
117120

118121
await tester.pumpWidget(
@@ -140,7 +143,6 @@ void main() {
140143
),
141144
);
142145

143-
144146
expect(find.text("Acronym"), findsOneWidget);
145147

146148
await tester.pumpWidget(
@@ -168,7 +170,6 @@ void main() {
168170
),
169171
);
170172

171-
172173
expect(find.text("Address"), findsOneWidget);
173174

174175
//Not supported in `RichText` parser.
@@ -197,7 +198,6 @@ void main() {
197198
),
198199
);
199200

200-
201201
expect(find.text("Article"), findsOneWidget);
202202

203203
await tester.pumpWidget(
@@ -1004,4 +1004,90 @@ void main() {
10041004
expect(find.byType(BlockText), findsOneWidget);
10051005
});
10061006

1007+
testWidgets("Check that `header` tag renders", (tester) async {
1008+
String html = "<header>header</header>";
1009+
1010+
await tester.pumpWidget(
1011+
MaterialApp(
1012+
home: Scaffold(
1013+
body: Html(
1014+
data: html,
1015+
),
1016+
),
1017+
),
1018+
);
1019+
1020+
expect(find.text("header"), findsOneWidget);
1021+
1022+
await tester.pumpWidget(
1023+
MaterialApp(
1024+
home: Scaffold(
1025+
body: Html(
1026+
data: html,
1027+
useRichText: true,
1028+
),
1029+
),
1030+
),
1031+
);
1032+
1033+
expect(find.byType(BlockText), findsOneWidget);
1034+
});
1035+
1036+
testWidgets("Check that `hr` tag renders", (tester) async {
1037+
String html = "<hr />";
1038+
1039+
await tester.pumpWidget(
1040+
MaterialApp(
1041+
home: Scaffold(
1042+
body: Html(
1043+
data: html,
1044+
),
1045+
),
1046+
),
1047+
);
1048+
1049+
expect(find.byType(Divider), findsOneWidget);
1050+
1051+
await tester.pumpWidget(
1052+
MaterialApp(
1053+
home: Scaffold(
1054+
body: Html(
1055+
data: html,
1056+
useRichText: true,
1057+
),
1058+
),
1059+
),
1060+
);
1061+
1062+
expect(find.byType(Divider), findsOneWidget);
1063+
});
1064+
1065+
testWidgets("Check that `i` tag renders", (tester) async {
1066+
String html = "<i>i</i>";
1067+
1068+
await tester.pumpWidget(
1069+
MaterialApp(
1070+
home: Scaffold(
1071+
body: Html(
1072+
data: html,
1073+
),
1074+
),
1075+
),
1076+
);
1077+
1078+
expect(find.text("i"), findsOneWidget);
1079+
1080+
await tester.pumpWidget(
1081+
MaterialApp(
1082+
home: Scaffold(
1083+
body: Html(
1084+
data: html,
1085+
useRichText: true,
1086+
),
1087+
),
1088+
),
1089+
);
1090+
1091+
expect(find.byType(RichText), findsOneWidget);
1092+
});
10071093
}

0 commit comments

Comments
 (0)