Skip to content

Commit 919ec5c

Browse files
committed
Merge branch 'master' of https://github.com/Sub6Resources/flutter_html into bugfix/hr-not-showing
2 parents ff3fdba + 957c9f8 commit 919ec5c

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/html_parser.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,10 @@ class HtmlParser extends StatelessWidget {
626626
parentAfterText = parentAfter?.text ?? " ";
627627
}
628628
/// If the text is the first element in the current tree node list, it
629-
/// starts with a whitespace, it isn't a line break, and either the
630-
/// whitespace is unnecessary or it is a block element, delete it.
629+
/// starts with a whitespace, it isn't a line break, either the
630+
/// whitespace is unnecessary or it is a block element, and either it is
631+
/// first element in the parent node list or the previous element
632+
/// in the parent node list ends with a whitespace, delete it.
631633
///
632634
/// We should also delete the whitespace at any point in the node list
633635
/// if the previous element is a <br> because that tag makes the element
@@ -637,6 +639,10 @@ class HtmlParser extends StatelessWidget {
637639
&& tree.element?.localName != "br"
638640
&& (!keepLeadingSpace.data
639641
|| BLOCK_ELEMENTS.contains(tree.element?.localName ?? ""))
642+
&& (elementIndex < 1
643+
|| (elementIndex >= 1
644+
&& parentNodes?[elementIndex - 1] is dom.Text
645+
&& parentNodes![elementIndex - 1].text!.endsWith(" ")))
640646
) {
641647
tree.text = tree.text!.replaceFirst(' ', '');
642648
} else if (textIndex >= 1

lib/image_render.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,10 @@ ImageRender assetImageRender({
7676
(context, attributes, element) {
7777
final assetPath = _src(attributes)!.replaceFirst('asset:', '');
7878
if (_src(attributes)!.endsWith(".svg")) {
79-
return SvgPicture.asset(assetPath);
79+
return SvgPicture.asset(
80+
assetPath,
81+
width: width ?? _width(attributes),
82+
height: height ?? _height(attributes));
8083
} else {
8184
return Image.asset(
8285
assetPath,

0 commit comments

Comments
 (0)