From 1f071771ca4a632a5611e615166718e75768d2ef Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Wed, 2 Sep 2020 17:38:43 +0200 Subject: [PATCH] Do not allow empty inline tags --- lib/core/processors/inline_tags.dart | 5 +- test/processors/inline_tags_test.dart | 80 +++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/lib/core/processors/inline_tags.dart b/lib/core/processors/inline_tags.dart index 7d5c6271..d4ee305a 100644 --- a/lib/core/processors/inline_tags.dart +++ b/lib/core/processors/inline_tags.dart @@ -26,7 +26,10 @@ class InlineTagsProcessor { var all = tag.split(prefix); for (var t in all) { - tags.add(t.trim()); + t = t.trim(); + if (t.isNotEmpty) { + tags.add(t); + } } } } diff --git a/test/processors/inline_tags_test.dart b/test/processors/inline_tags_test.dart index bffa3542..0757e437 100644 --- a/test/processors/inline_tags_test.dart +++ b/test/processors/inline_tags_test.dart @@ -56,4 +56,84 @@ void main() { expect(tags, {'one', 'two', 'foo', 'doo'}); }); + + test('Should Ignore headers', () { + var body = "# Hi\nHow are you?"; + + var p = InlineTagsProcessor(tagPrefixes: {'#', '+', '@'}); + var tags = p.extractTags(body); + + expect(tags.isEmpty, true); + }); + + test('Markdown Example', () { + var body = """# Markdown Example +Markdown allows you to easily include formatted text, images, and even formatted Dart code in your app. + +## Titles + +Setext-style + +This is an H1 ============= This is an H2 ------------- + +Atx-style + +# This is an H1 ## This is an H2 ###### This is an H6 + +Select the valid headers: + +- [x] # hello +- [ ] #hello + +## Links + +[Google's Homepage][Google] + +[inline-style](https://www.google.com) [reference-style][Google] + +## Images + + + +## Tables + +|Syntax |Result | +|---------------------------------------|-------------------------------------| +|*italic 1* |italic 1 | +|_italic 2_ | italic 2 | +|**bold 1** |bold 1 | +|__bold 2__ |bold 2 | +|This is a ~~strikethrough~~ |This is a strikethrough | +|***italic bold 1*** |italic bold 1 | +|___italic bold 2___ |italic bold 2 | +|***~~italic bold strikethrough 1~~***|***italic bold strikethrough 1***| +|~~***italic bold strikethrough 2***~~|italic bold strikethrough 2| + +## Styling +Style text as italic, bold, strikethrough, or inline code. + +- Use bulleted lists +- To better clarify +- Your points + +## Code blocks +Formatted Dart code looks really pretty too: + +void main() { runApp(MaterialApp( home: Scaffold( body: Markdown(data: markdownData), ), )); } + +## Markdown widget + +This is an example of how to create your own Markdown widget: + + Markdown(data: 'Hello world!'); + +Enjoy! + +[Google]: https://www.google.com/"""; + + var p = InlineTagsProcessor(tagPrefixes: {'#', '+', '@'}); + var tags = p.extractTags(body); + + expect(tags, {'hello'}); + }); }