Skip to content

Commit

Permalink
Add support for brackets in link text to markdown codecs
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbengtsson committed May 10, 2024
1 parent fd011a3 commit d0ba673
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/parchment/lib/src/codecs/markdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class _ParchmentMarkdownDecoder extends Converter<String, ParchmentDocument> {
r'(`(?<inline_code_text>.+?)`)',
);

static final _linkRegExp = RegExp(r'\[([^\]]+)\]\(([^)]+)\)');
static final _linkRegExp = RegExp(r'\[(.+?)\]\(([^)]+)\)');
static final _ulRegExp = RegExp(r'^( *)\* +(.*)');
static final _olRegExp = RegExp(r'^( *)\d+[.)] +(.*)');
static final _clRegExp = RegExp(r'^( *)- +\[( |x|X)\] +(.*)');
Expand Down
17 changes: 17 additions & 0 deletions packages/parchment/test/codecs/markdown_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,23 @@ void main() {
expect(andBack, markdown);
});

test('complex link', () {
final markdown =
'This a complex link [1[2(3) 4]5 6](https://github.com/[abc]) and [normal one](https://github.com)\n\n';
final document = parchmentMarkdown.decode(markdown);
final delta = document.toDelta();

expect(delta.elementAt(1).data, '1[2(3) 4]5 6');
expect(delta.elementAt(1).attributes?['b'], null);
expect(delta.elementAt(1).attributes?['a'], 'https://github.com/[abc]');

expect(delta.elementAt(3).data, 'normal one');
expect(delta.elementAt(3).attributes?['a'], 'https://github.com');

final andBack = parchmentMarkdown.encode(document);
expect(andBack, markdown);
});

test('style around link', () {
final markdown =
'This **house** is a **[circus](https://github.com)**\n\n';
Expand Down

0 comments on commit d0ba673

Please sign in to comment.