Skip to content

Commit b55c0b1

Browse files
authored
Merge pull request Sub6Resources#1 from Sub6Resources/new-parser
update from base repo
2 parents 3badf23 + b5046d9 commit b55c0b1

File tree

7 files changed

+176
-28
lines changed

7 files changed

+176
-28
lines changed

example/ios/Flutter/Flutter.podspec

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# NOTE: This podspec is NOT to be published. It is only used as a local source!
3+
#
4+
5+
Pod::Spec.new do |s|
6+
s.name = 'Flutter'
7+
s.version = '1.0.0'
8+
s.summary = 'High-performance, high-fidelity mobile apps.'
9+
s.description = <<-DESC
10+
Flutter provides an easy and productive way to build and deploy high-performance mobile apps for Android and iOS.
11+
DESC
12+
s.homepage = 'https://flutter.io'
13+
s.license = { :type => 'MIT' }
14+
s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' }
15+
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
16+
s.ios.deployment_target = '8.0'
17+
s.vendored_frameworks = 'Flutter.framework'
18+
end

example/lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const htmlData = """
4646
</p>
4747
<h3>Support for <code>sub</code>/<code>sup</code></h3>
4848
Solve for <var>x<sub>n</sub></var>: log<sub>2</sub>(<var>x</var><sup>2</sup>+<var>n</var>) = 9<sup>3</sup>
49-
<p>One of the most common equations in all of physics is <var>E</var>=<var>m</var><var>c</var><sup>2</sup>.</p>
49+
<p>One of the most <span>common</span> equations in all of physics is <var>E</var>=<var>m</var><var>c</var><sup>2</sup>.</p>
5050
<h3>Table support:</h3>
5151
<table>
5252
<colgroup>

lib/html_parser.dart

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import 'dart:collection';
22
import 'dart:math';
33

4+
import 'package:csslib/parser.dart' as cssparser;
5+
import 'package:csslib/visitor.dart' as css;
6+
import 'package:flutter/material.dart';
47
import 'package:flutter_html/flutter_html.dart';
8+
import 'package:flutter_html/src/html_elements.dart';
59
import 'package:flutter_html/src/layout_element.dart';
610
import 'package:flutter_html/src/utils.dart';
711
import 'package:flutter_html/style.dart';
8-
import 'package:flutter/material.dart';
9-
import 'package:csslib/visitor.dart' as css;
1012
import 'package:html/dom.dart' as dom;
11-
import 'package:flutter_html/src/html_elements.dart';
1213
import 'package:html/parser.dart' as htmlparser;
13-
import 'package:csslib/parser.dart' as cssparser;
1414

1515
typedef OnTap = void Function(String url);
1616
typedef CustomRender = Widget Function(
@@ -67,7 +67,7 @@ class HtmlParser extends StatelessWidget {
6767
cleanedTree,
6868
);
6969

70-
return RichText(text: parsedTree);
70+
return StyledText(textSpan: parsedTree, style: cleanedTree.style);
7171
}
7272

7373
/// [parseHTML] converts a string of HTML to a DOM document using the dart `html` library.
@@ -281,14 +281,15 @@ class HtmlParser extends StatelessWidget {
281281
Padding(
282282
padding: EdgeInsets.only(
283283
left: 30), //TODO derive this from list padding.
284-
child: RichText(
285-
text: TextSpan(
284+
child: StyledText(
285+
textSpan: TextSpan(
286286
children: tree.children
287287
?.map((tree) => parseTree(newContext, tree))
288288
?.toList() ??
289289
[],
290290
style: newContext.style.generateTextStyle(),
291291
),
292+
style: newContext.style,
292293
),
293294
)
294295
],
@@ -317,14 +318,15 @@ class HtmlParser extends StatelessWidget {
317318
},
318319
),
319320
},
320-
child: RichText(
321-
text: TextSpan(
321+
child: StyledText(
322+
textSpan: TextSpan(
322323
style: newContext.style.generateTextStyle(),
323324
children: tree.children
324325
.map((tree) => parseTree(newContext, tree))
325326
.toList() ??
326327
[],
327328
),
329+
style: newContext.style,
328330
),
329331
),
330332
);
@@ -349,14 +351,15 @@ class HtmlParser extends StatelessWidget {
349351
return WidgetSpan(
350352
child: Transform.translate(
351353
offset: Offset(0, verticalOffset),
352-
child: RichText(
353-
text: TextSpan(
354+
child: StyledText(
355+
textSpan: TextSpan(
354356
style: newContext.style.generateTextStyle(),
355357
children: tree.children
356358
.map((tree) => parseTree(newContext, tree))
357359
.toList() ??
358360
[],
359361
),
362+
style: newContext.style,
360363
),
361364
),
362365
);
@@ -694,12 +697,36 @@ class ContainerSpan extends StatelessWidget {
694697
margin: style?.margin,
695698
alignment: shrinkWrap ? null : style?.alignment,
696699
child: child ??
697-
RichText(
698-
text: TextSpan(
700+
StyledText(
701+
textSpan: TextSpan(
699702
style: newContext.style.generateTextStyle(),
700703
children: children,
701704
),
705+
style: newContext.style,
702706
),
703707
);
704708
}
705709
}
710+
711+
class StyledText extends StatelessWidget {
712+
final InlineSpan textSpan;
713+
final Style style;
714+
715+
const StyledText({
716+
this.textSpan,
717+
this.style,
718+
});
719+
720+
@override
721+
Widget build(BuildContext context) {
722+
return SizedBox(
723+
width: style.display == Display.BLOCK || style.display == Display.LIST_ITEM? double.infinity: null,
724+
child: Text.rich(
725+
textSpan,
726+
style: style.generateTextStyle(),
727+
textAlign: style.textAlign,
728+
textDirection: style.direction,
729+
),
730+
);
731+
}
732+
}

lib/src/layout_element.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ class TableRowLayoutElement extends LayoutElement {
125125
color: c.style.backgroundColor,
126126
border: c.style.border,
127127
),
128-
child: RichText(
129-
text: context.parser.parseTree(context, c),
128+
child: StyledText(
129+
textSpan: context.parser.parseTree(context, c),
130+
style: c.style,
130131
)));
131132
}
132133
return null;

lib/src/styled_element.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:flutter_html/style.dart';
33
import 'package:html/dom.dart' as dom;
4-
//TODO(Sub6Resources) don't use the internal code of the html package as it may change unexpectedly.
4+
//TODO(Sub6Resources): don't use the internal code of the html package as it may change unexpectedly.
55
import 'package:html/src/query_selector.dart';
66

77
/// A [StyledElement] applies a style to all of its children.
@@ -85,7 +85,7 @@ StyledElement parseStyledElement(
8585
? TextDirection.rtl
8686
: TextDirection.ltr;
8787
styledElement.style = Style(
88-
textDirection: textDirection,
88+
direction: textDirection,
8989
);
9090
break;
9191
case "big":

0 commit comments

Comments
 (0)