-
-
Notifications
You must be signed in to change notification settings - Fork 917
details tag support #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import 'package:html/dom.dart' as dom; | |
|
||
typedef CustomRender = Widget Function(dom.Node node, List<Widget> children); | ||
typedef OnLinkTap = void Function(String url); | ||
typedef ParseNodeFunction = List<Widget> Function(List<dom.Node> nodeList); | ||
|
||
|
||
class HtmlParser { | ||
HtmlParser({ | ||
|
@@ -39,6 +40,7 @@ class HtmlParser { | |
"data", | ||
"dd", | ||
"del", | ||
"details", | ||
"dfn", | ||
"div", | ||
"dl", | ||
|
@@ -294,6 +296,8 @@ class HtmlParser { | |
decoration: TextDecoration.lineThrough, | ||
), | ||
); | ||
case "details": | ||
return DetailsWidget(node, _parseNodeList); | ||
case "dfn": | ||
return DefaultTextStyle.merge( | ||
child: Wrap( | ||
|
@@ -800,3 +804,45 @@ class HtmlParser { | |
return false; | ||
} | ||
} | ||
|
||
class DetailsWidget extends StatefulWidget { | ||
Sub6Resources marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
final ParseNodeFunction parseFunc; | ||
final dom.Element node; | ||
DetailsWidget(this.node, this.parseFunc); | ||
_DetailsWidgetState createState() => _DetailsWidgetState(); | ||
} | ||
|
||
class _DetailsWidgetState extends State<DetailsWidget> { | ||
dom.Node _summaryNode; | ||
bool _isOpen = false; | ||
|
||
void initState() { | ||
super.initState(); | ||
_summaryNode = widget.node.children | ||
.firstWhere((el) => el.localName == "summary", orElse: () => null); | ||
_isOpen = _summaryNode != null | ||
? _summaryNode.attributes.containsKey("open") | ||
: false; | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Column( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
GestureDetector( | ||
onTap: () { | ||
setState(() { | ||
_isOpen = !_isOpen; | ||
}); | ||
}, | ||
child: Text(_summaryNode != null ? _summaryNode.text : ""), | ||
Sub6Resources marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
), | ||
Wrap( | ||
children: | ||
_isOpen ? widget.parseFunc(widget.node.nodes) : [Container()], | ||
) | ||
], | ||
); | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.