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
This commit is contained in:
Mike Hoolehan 2017-02-27 22:13:24 +02:00 committed by Adam Barth
parent e7bde11cc3
commit 09b63e2c93
4 changed files with 33 additions and 7 deletions

View File

@ -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>

View File

@ -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

View File

@ -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:

View File

@ -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']);