Skip to content

Commit 63f7bb0

Browse files
committed
Revert "WIP: Tables"
This reverts commit d86fc77.
1 parent 2f0090e commit 63f7bb0

File tree

7 files changed

+106
-106
lines changed

7 files changed

+106
-106
lines changed

example/lib/main.dart

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,29 @@ const htmlData = """
5656
<circle r="32" cx="65" cy="65" fill="#0F0" opacity="0.5"/>
5757
<circle r="32" cx="50" cy="35" fill="#00F" opacity="0.5"/>
5858
</svg>
59+
<ol>
60+
<li>This</li>
61+
<li><p>is</p></li>
62+
<li>an</li>
63+
<li>
64+
ordered
65+
<ul>
66+
<li>With<br /><br />...</li>
67+
<li>a</li>
68+
<li>nested</li>
69+
<li>unordered
70+
<ol>
71+
<li>With a nested</li>
72+
<li>ordered list.</li>
73+
</ol>
74+
</li>
75+
<li>list</li>
76+
</ul>
77+
</li>
78+
<li>list! Lorem ipsum dolor sit <b>amet cale aaihg aie a gama eia aai aia ia af a</b></li>
79+
<li><h2>Header 2</h2></li>
80+
<h2><li>Header 2</li></h2>
81+
</ol>
5982
""";
6083

6184
class _MyHomePageState extends State<MyHomePage> {
@@ -88,15 +111,15 @@ class _MyHomePageState extends State<MyHomePage> {
88111
// alignment: Alignment.center,
89112
),
90113
"#whitespace": Style(
91-
backgroundColor: Colors.deepPurple,
114+
backgroundColor: Colors.purple,
92115
),
93116
},
94117
customRender: {
95118
"flutter": (RenderContext context, Widget child, attributes) {
96119
return FlutterLogo(
97120
style: (attributes['horizontal'] != null)? FlutterLogoStyle.horizontal: FlutterLogoStyle.markOnly,
98121
textColor: context.style.color,
99-
size: context.style.fontSize * 8,
122+
size: context.style.fontSize * 5,
100123
);
101124
}
102125
},

lib/html_parser.dart

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import 'dart:collection';
22
import 'dart:math';
33

44
import 'package:flutter_html/flutter_html.dart';
5+
import 'package:flutter_html/src/layout_element.dart';
56
import 'package:flutter_html/src/utils.dart';
67
import 'package:flutter_html/style.dart';
78
import 'package:flutter/material.dart';
@@ -96,6 +97,8 @@ class HtmlParser extends StatelessWidget {
9697
return parseInteractableElement(node, children);
9798
} else if (REPLACED_ELEMENTS.contains(node.localName)) {
9899
return parseReplacedElement(node);
100+
} else if (LAYOUT_ELEMENTS.contains(node.localName)) {
101+
return parseLayoutElement(node, children);
99102
} else if (customRenderTags.contains(node.localName)) {
100103
return parseStyledElement(node, children);
101104
} else {
@@ -235,47 +238,6 @@ class HtmlParser extends StatelessWidget {
235238
),
236239
),
237240
);
238-
} else if(tree.style?.display == Display.TABLE) {
239-
return WidgetSpan(
240-
child: DefaultTextStyle(
241-
style: TextStyle(color: Colors.white),
242-
child: IntrinsicWidth(
243-
child: ContainerSpan(
244-
style: Style(border: Border.all(color: Colors.white)),
245-
child: Column(
246-
crossAxisAlignment: CrossAxisAlignment.stretch,
247-
children: [
248-
IntrinsicHeight(
249-
child: Row(
250-
children: [Expanded(child: Placeholder()), Expanded(child: FlutterLogo())],
251-
mainAxisAlignment: MainAxisAlignment.center,
252-
crossAxisAlignment: CrossAxisAlignment.stretch,
253-
),
254-
),
255-
IntrinsicHeight(
256-
child: Row(
257-
children: [Expanded(child: Text('Hello\nWorld!')), Expanded(child: ContainerSpan(child: Placeholder()))],
258-
mainAxisAlignment: MainAxisAlignment.center,
259-
crossAxisAlignment: CrossAxisAlignment.stretch,
260-
),
261-
),
262-
IntrinsicHeight(
263-
child: Row(
264-
children: [Expanded(child: Placeholder()), Expanded(child: Text('Hi'))],
265-
mainAxisAlignment: MainAxisAlignment.center,
266-
crossAxisAlignment: CrossAxisAlignment.stretch,
267-
),
268-
),
269-
],
270-
),
271-
),
272-
),
273-
),
274-
);
275-
// } else if(tree.style?.display == Display.TABLE_CELL) {
276-
// return TextSpan();
277-
// } else if(tree.style?.display == Display.TABLE_ROW) {
278-
//
279241
} else if (tree is ReplacedElement) {
280242
if (tree is TextContentElement) {
281243
return TextSpan(text: tree.text);
@@ -298,6 +260,10 @@ class HtmlParser extends StatelessWidget {
298260
),
299261
),
300262
);
263+
} else if (tree is LayoutElement) {
264+
return WidgetSpan(
265+
child: tree.toWidget(context),
266+
);
301267
} else {
302268
///[tree] is an inline element.
303269
return TextSpan(
@@ -533,14 +499,7 @@ class HtmlParser extends StatelessWidget {
533499
toRemove.add(child);
534500
} else if (child is TextContentElement &&
535501
child.style.whiteSpace != WhiteSpace.PRE &&
536-
(
537-
tree.style.display == Display.BLOCK ||
538-
tree.style.display == Display.TABLE ||
539-
tree.style.display == Display.TABLE_ROW_GROUP ||
540-
tree.style.display == Display.TABLE_ROW ||
541-
tree.style.display == Display.TABLE_FOOTER_GROUP ||
542-
tree.style.display == Display.TABLE_HEADER_GROUP
543-
) &&
502+
tree.style.display == Display.BLOCK &&
544503
child.text.trim().isEmpty) {
545504
//TODO should this be moved to the whitespace functions?
546505
toRemove.add(child);

lib/src/html_elements.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,6 @@ const STYLED_ELEMENTS = [
7070
"pre",
7171
"section",
7272
"ul",
73-
74-
//TABLE ELEMENTS
75-
"table",
76-
"td",
77-
"th",
78-
"tr",
79-
"tbody",
80-
"tfoot",
81-
"thead",
8273
];
8374

8475
const INTERACTABLE_ELEMENTS = [
@@ -96,6 +87,14 @@ const REPLACED_ELEMENTS = [
9687
"video",
9788
];
9889

90+
const LAYOUT_ELEMENTS = [
91+
"table",
92+
"tr",
93+
"tbody",
94+
"tfoot",
95+
"thead",
96+
];
97+
9998
/**
10099
Here is a list of elements with planned support:
101100
a - i [x]

lib/src/layout_element.dart

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import 'package:flutter/material.dart';
2+
import 'package:flutter_html/html_parser.dart';
3+
import 'package:flutter_html/src/styled_element.dart';
4+
import 'package:flutter_html/style.dart';
5+
import 'package:html/dom.dart' as dom;
6+
7+
/// A [LayoutElement] is an element that breaks the normal Inline flow of
8+
/// an html document with a more complex layout. LayoutElements handle
9+
abstract class LayoutElement extends StyledElement {
10+
LayoutElement({
11+
String name,
12+
List<StyledElement> children,
13+
Style style,
14+
dom.Element node,
15+
}) : super(name: name, children: children, style: style, node: node);
16+
17+
Widget toWidget(RenderContext context);
18+
}
19+
20+
class TableLayoutElement extends LayoutElement {
21+
TableLayoutElement({
22+
@required List<StyledElement> children,
23+
}) : super(children: children);
24+
25+
@override
26+
Widget toWidget(RenderContext context) {
27+
return Table(
28+
// children: children.where((e) => e.name == 'tr').map(),
29+
);
30+
}
31+
}
32+
33+
class TableRowLayoutElement extends LayoutElement {
34+
TableRowLayoutElement({
35+
@required List<StyledElement> children,
36+
}) : super(children: children);
37+
38+
@override
39+
Widget toWidget(RenderContext context) {
40+
return Container(child: Text("TABLE ROW"));
41+
}
42+
43+
TableRow toTableRow(RenderContext context) {
44+
45+
}
46+
}
47+
48+
LayoutElement parseLayoutElement(dom.Element element, List<StyledElement> children) {
49+
switch (element.localName) {
50+
case "table":
51+
return TableLayoutElement(
52+
children: children,
53+
);
54+
break;
55+
case "tr":
56+
return TableLayoutElement(
57+
children: children,
58+
);
59+
break;
60+
default:
61+
return TableLayoutElement(
62+
children: children
63+
);
64+
}
65+
}

lib/src/replaced_element.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,11 @@ class VideoContentElement extends ReplacedElement {
202202

203203
/// [SvgContentElement] is a [ReplacedElement] with an SVG as its contents.
204204
class SvgContentElement extends ReplacedElement {
205-
final String name;
206205
final String data;
207206
final double width;
208207
final double height;
209208

210209
SvgContentElement({
211-
this.name,
212210
this.data,
213211
this.width,
214212
this.height,
@@ -285,7 +283,6 @@ ReplacedElement parseReplacedElement(dom.Element element) {
285283
);
286284
case "svg":
287285
return SvgContentElement(
288-
name: "svg",
289286
data: element.outerHtml,
290287
width: double.tryParse(element.attributes['width'] ?? ""),
291288
height: double.tryParse(element.attributes['height'] ?? ""),

lib/src/styled_element.dart

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -343,42 +343,6 @@ StyledElement parseStyledElement(
343343
baselineOffset: 1,
344344
);
345345
break;
346-
case "table":
347-
styledElement.style = Style(
348-
display: Display.TABLE,
349-
);
350-
break;
351-
case "tbody":
352-
styledElement.style = Style(
353-
display: Display.TABLE_ROW_GROUP,
354-
);
355-
break;
356-
case "td":
357-
styledElement.style = Style(
358-
display: Display.TABLE_CELL,
359-
);
360-
break;
361-
case "th":
362-
styledElement.style = Style(
363-
display: Display.TABLE_CELL,
364-
fontWeight: FontWeight.bold,
365-
);
366-
break;
367-
case "thead":
368-
styledElement.style = Style(
369-
display: Display.TABLE_HEADER_GROUP,
370-
);
371-
break;
372-
case "tfoot":
373-
styledElement.style = Style(
374-
display: Display.TABLE_FOOTER_GROUP,
375-
);
376-
break;
377-
case "tr":
378-
styledElement.style = Style(
379-
display: Display.TABLE_ROW,
380-
);
381-
break;
382346
case "tt":
383347
continue monospace;
384348
underline:

lib/style.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,13 +215,6 @@ enum Display {
215215
INLINE,
216216
INLINE_BLOCK,
217217
LIST_ITEM,
218-
TABLE,
219-
TABLE_ROW,
220-
TABLE_CELL,
221-
TABLE_ROW_GROUP,
222-
TABLE_HEADER_GROUP,
223-
TABLE_FOOTER_GROUP,
224-
TABLE_CAPTION,
225218
}
226219

227220
enum ListStyleType {

0 commit comments

Comments
 (0)