Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.5

- **FIXED**: Fixed parsing url such as `[text](https://domain.com/path(with)brackets)`.

## 0.0.4

- **CHANGED**: Improved link tap handling.
Expand Down
16 changes: 11 additions & 5 deletions lib/src/parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,21 @@ List<MD$Span> _parseInlineSpans(String text) {

// find closing ')'
var urlEnd = -1;
for (var k = urlIdx + 1; k < codes.length; k++) {
for (var k = urlIdx + 1, opens = 0; k < codes.length; k++) {
final ck = codes[k];
if (ck == esc) {
k++;
continue;
continue; // skip escaped char
}
if (ck == url$end) {
urlEnd = k;
break;
if (ck == url$start) {
opens++; // count opening '('
} else if (ck == url$end) {
if (opens > 0) {
opens--; // count closing ')'
} else {
urlEnd = k; // found the closing ')'
break;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: >
Markdown library written in Dart.
It can parse and display Markdown.

version: 0.0.4
version: 0.0.5

homepage: https://github.com/DoctorinaAI/md
repository: https://github.com/DoctorinaAI/md
Expand Down
66 changes: 66 additions & 0 deletions test/parser/parser_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,72 @@ void main() => group('Parse', () {
);
});

test('Urls', () {
var markdown = markdownDecoder.convert('[text](url)');
expect(
markdown.text,
allOf(
isNotEmpty,
equals('text'),
),
);
expect(
markdown.blocks,
allOf(
isNotEmpty,
hasLength(equals(1)),
everyElement(isA<MD$Paragraph>()),
),
);
expect(
markdown.blocks.single,
isA<MD$Paragraph>().having(
(p) => p.spans,
'spans',
allOf(
isNotEmpty,
hasLength(equals(1)),
everyElement(isA<MD$Span>()
.having((s) => s.style, 'style', equals(MD$Style.link))
.having((s) => s.extra, 'extra', containsPair('url', 'url'))),
),
),
);

// Should be with url: `url()`
markdown = markdownDecoder.convert('[text](url(with)brackets)');
expect(
markdown.text,
allOf(
isNotEmpty,
equals('text'),
),
);
expect(
markdown.blocks,
allOf(
isNotEmpty,
hasLength(equals(1)),
everyElement(isA<MD$Paragraph>()),
),
);
expect(
markdown.blocks.single,
isA<MD$Paragraph>().having(
(p) => p.spans,
'spans',
allOf(
isNotEmpty,
hasLength(equals(1)),
everyElement(isA<MD$Span>()
.having((s) => s.style, 'style', equals(MD$Style.link))
.having((s) => s.extra, 'extra',
containsPair('url', 'url(with)brackets'))),
),
),
);
});

test('Empty input', () {
expect(markdownDecoder.convert('').blocks, isEmpty);
});
Expand Down