Commit 09b63e2c authored by Mike Hoolehan's avatar Mike Hoolehan Committed by Adam Barth

Ignore HTML in flutter_markdown content without error (#8420)

* Gracefully ignore html content

* Test for less than, consolidate table tests

* Specify missing type annotation

* Add Mike Hoolehan to AUTHORS
parent e7bde11c
......@@ -14,3 +14,4 @@ Michael Beckler <mcbeckler@gmail.com>
Alexandre Ardhuin <alexandre.ardhuin@gmail.com>
Luke Freeman <luke@goposse.com>
Vincent Le Quéméner <eu.lequem@gmail.com>
Mike Hoolehan <mike@hoolehan.com>
......@@ -219,13 +219,16 @@ class _Renderer implements md.NodeVisitor {
@override
void visitText(md.Text text) {
_MarkdownNodeList topList = _currentBlock.stack.last;
List<_MarkdownNode> top = topList.list;
if (_currentBlock != null) { // ignore if no corresponding block
_MarkdownNodeList topList = _currentBlock.stack.last;
List<_MarkdownNode> top = topList.list;
if (_currentBlock.tag == 'pre')
top.add(new _MarkdownNodeTextSpan(_syntaxHighlighter.format(text.text)));
else
top.add(new _MarkdownNodeString(text.text));
if (_currentBlock.tag == 'pre')
top.add(
new _MarkdownNodeTextSpan(_syntaxHighlighter.format(text.text)));
else
top.add(new _MarkdownNodeString(text.text));
}
}
@override
......
......@@ -7,7 +7,7 @@ homepage: http://flutter.io
dependencies:
flutter:
sdk: flutter
markdown: '^0.9.0'
markdown: '^0.11.0'
string_scanner: ^1.0.0
dev_dependencies:
......
......@@ -84,6 +84,28 @@ void main() {
expect(span.children[0].recognizer.runtimeType, equals(TapGestureRecognizer));
});
testWidgets('HTML tag ignored ', (WidgetTester tester) async {
final List<String> mdData = <String>[
'Line 1\n<p>HTML content</p>\nLine 2',
'Line 1\n<!-- HTML\n comment\n ignored --><\nLine 2'
];
for (String mdLine in mdData) {
await tester.pumpWidget(new MarkdownBody(data: mdLine));
Iterable<Widget> widgets = tester.allWidgets;
_expectTextStrings(widgets, <String>['Line 1', 'Line 2']);
}
});
testWidgets('Less than', (WidgetTester tester) async {
final String mdLine = 'Line 1 <\n\nc < c c\n\n< Line 2';
await tester.pumpWidget(new MarkdownBody(data: mdLine));
Iterable<Widget> widgets = tester.allWidgets;
_expectTextStrings(widgets, <String>['Line 1 &lt;','c &lt; c c','&lt; Line 2']);
});
testWidgets('Changing config - data', (WidgetTester tester) async {
await tester.pumpWidget(new Markdown(data: 'Data1'));
_expectTextStrings(tester.allWidgets, <String>['Data1']);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment