Do not allow empty inline tags

This commit is contained in:
Vishesh Handa
2020-09-02 17:38:43 +02:00
parent 074e918db4
commit 1f071771ca
2 changed files with 84 additions and 1 deletions

View File

@ -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);
}
}
}
}

View File

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