Skip to content

Commit 628b28c

Browse files
committed
fixed issue with non self closing br tag,
implemented better sizing or h1-h6 tags
1 parent 1402960 commit 628b28c

File tree

6 files changed

+58
-10
lines changed

6 files changed

+58
-10
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
# [2.0.0+1] - May 10th, 2020
1+
# [2.0.0+2] - May 11th, 2020
2+
3+
* Fixed an issue with non self closing `<br>` tag
4+
* Improved `<h1>-<h6>` sizing
5+
6+
## [2.0.0+1] - May 10th, 2020
27

38
* updated README
49

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ HTML.toTextSpan(
144144
Supports all tags which prints text normally like `p`, `div`, `span`, `body` etc.
145145
And the following special tags which change the text appearance
146146

147-
* `<h1> - <h5>`
147+
* `<h1> - <h6>`
148148
* `<b>` `<strong>`
149+
* `<br>` `<br />`
149150
* `<i>` `<em>`
150151
* `<u>`
151152
* `<strike>` `<del>` `<s>`

example/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ packages:
129129
path: ".."
130130
relative: true
131131
source: path
132-
version: "2.0.0"
132+
version: "2.0.0+1"
133133
sky_engine:
134134
dependency: transitive
135135
description: flutter

lib/src/html_stylist.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,14 @@ class HTML {
6060
{Function linksCallback,
6161
Map<String, TextStyle> overrideStyle,
6262
TextStyle defaultTextStyle}) {
63-
//to fix a known issue with &nbsp; when appears after a ending tag
63+
//to fix a known issue with &nbsp; when appearing after an ending tag
6464
htmlContent =
6565
htmlContent.replaceAll("&nbsp;", " ").replaceAll("&nbsp", " ");
6666

67+
//to fix a known issue with non self closing <br> tags
68+
htmlContent =
69+
htmlContent.replaceAll("<br>", "<br />");
70+
6771
Parser p = Parser(context, HtmlUnescape().convert(htmlContent),
6872
linksCallback: linksCallback,
6973
overrideStyleMap: overrideStyle ?? Map<String, TextStyle>(),

lib/src/internals.dart

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,32 +146,70 @@ class Parser {
146146
var styles = "";
147147
var tagName = event.name.toLowerCase();
148148
var overrideStyles;
149+
double defaultFontSize = defaultTextStyle?.fontSize;
150+
149151
if (overrideStyleMap.containsKey(tagName))
150152
overrideStyles = overrideStyleMap[tagName];
151153

152154
switch (tagName) {
153155
case "h1":
154-
double h1 = Theme.of(_context).textTheme.headline5.fontSize;
156+
double h1;
157+
if (defaultFontSize == null) {
158+
h1 = Theme.of(_context).textTheme.headline5.fontSize;
159+
} else {
160+
h1 = defaultFontSize * 2;
161+
}
155162
styles = "font-size: ${h1}px;";
156163
break;
157164

158165
case "h2":
159-
double h2 = Theme.of(_context).textTheme.headline6.fontSize;
166+
double h2;
167+
if (defaultFontSize == null) {
168+
h2 = Theme.of(_context).textTheme.headline6.fontSize;
169+
} else {
170+
h2 = defaultFontSize * 1.5;
171+
}
160172
styles = "font-size: ${h2}px; font-weight: medium;";
161173
break;
162174

163175
case "h3":
164-
double h3 = Theme.of(_context).textTheme.subtitle1.fontSize;
176+
double h3;
177+
if (defaultFontSize == null) {
178+
h3 = Theme.of(_context).textTheme.subtitle1.fontSize;
179+
} else {
180+
h3 = defaultFontSize * 1.17;
181+
}
165182
styles = "font-size: ${h3}px;";
166183
break;
167184

168185
case "h4":
169-
double h4 = Theme.of(_context).textTheme.bodyText1.fontSize;
186+
double h4;
187+
if (defaultFontSize == null) {
188+
h4 = Theme.of(_context).textTheme.bodyText1.fontSize;
189+
} else {
190+
h4 = defaultFontSize;
191+
}
170192
styles = "font-size: ${h4}px; font-weight: medium;";
171193
break;
172194

173195
case "h5":
174-
styles = "font-weight: bold;";
196+
double h5;
197+
if (defaultFontSize == null) {
198+
h5 = Theme.of(_context).textTheme.bodyText1.fontSize;
199+
} else {
200+
h5 = defaultFontSize * .83;
201+
}
202+
styles = "font-size: ${h5}px; font-weight: bold;";
203+
break;
204+
205+
case "h6":
206+
double h6;
207+
if (defaultFontSize == null) {
208+
h6 = Theme.of(_context).textTheme.bodyText2.fontSize;
209+
} else {
210+
h6 = defaultFontSize * .67;
211+
}
212+
styles = "font-size: ${h6}px; font-weight: bold;";
175213
break;
176214

177215
case "b":

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: simple_html_css
22
description: This package allows you to use simple HTML and inline CSS styles to style your text in flutter. A fork of css_text package.
3-
version: 2.0.0+1
3+
version: 2.0.0+2
44
homepage: https://github.com/ali-thowfeek/simple_html_css_flutter
55
repository: https://github.com/ali-thowfeek/simple_html_css_flutter
66
environment:

0 commit comments

Comments
 (0)