Skip to content

Commit

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

// as per https://www.michaelperrin.fr/blog/2019/02/advanced-regular-expressions
static final _linkRegExp =
RegExp(r'\[(?<text>.+)\]\((?<url>[^ ]+)(?: "(?<title>.+)")?\)');
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 @@ -225,6 +225,23 @@ void main() {
expect(andBack, markdown);
});

test('double link', () {
final markdown =
'This **house** is a [circus](https://github.com) and [home](https://github.com)\n\n';
final document = parchmentMarkdown.decode(markdown);
final delta = document.toDelta();

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

expect(delta.elementAt(5).data, 'home');
expect(delta.elementAt(5).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 fd011a3

Please sign in to comment.