Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Commit a8288ca

Browse files
authored
address a termination issue with GitHub alert syntax parsing (#576)
address a termination issue with GitHub alert syntax parsing
1 parent 7602f9f commit a8288ca

File tree

5 files changed

+52
-8
lines changed

5 files changed

+52
-8
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 7.2.1
2+
3+
* Address a termination issue with GitHub alert syntax parsing.
4+
15
## 7.2.0
26

37
* Require Dart `^3.1.0`.

lib/src/block_syntaxes/alert_block_syntax.dart

+7-4
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ class AlertBlockSyntax extends BlockSyntax {
2626
}
2727

2828
/// Whether this alert ends with a lazy continuation line.
29-
// The definition of lazy continuation lines:
30-
// https://spec.commonmark.org/0.30/#lazy-continuation-line
29+
///
30+
/// The definition of lazy continuation lines:
31+
/// https://spec.commonmark.org/0.30/#lazy-continuation-line
3132
static bool _lazyContinuation = false;
3233
static final _contentLineRegExp = RegExp(r'>?\s?(.*)*');
3334

@@ -40,7 +41,9 @@ class AlertBlockSyntax extends BlockSyntax {
4041
while (!parser.isDone) {
4142
final strippedContent =
4243
parser.current.content.replaceFirst(RegExp(r'^\s*>?\s*'), '');
43-
final match = _contentLineRegExp.firstMatch(strippedContent);
44+
final match = strippedContent.isEmpty
45+
? null
46+
: _contentLineRegExp.firstMatch(strippedContent);
4447
if (match != null) {
4548
childLines.add(Line(strippedContent));
4649
parser.advance();
@@ -100,7 +103,7 @@ class AlertBlockSyntax extends BlockSyntax {
100103
final titleText = typeTextMap[type]!;
101104
final titleElement = Element('p', [Text(titleText)])
102105
..attributes['class'] = 'markdown-alert-title';
103-
final elementClass = 'markdown-alert markdown-alert-${type.toLowerCase()}';
106+
final elementClass = 'markdown-alert markdown-alert-$type';
104107
return Element('div', [titleElement, ...children])
105108
..attributes['class'] = elementClass;
106109
}

lib/src/version.dart

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: markdown
2-
version: 7.2.0
2+
version: 7.2.1
33

44
description: >-
55
A portable Markdown library written in Dart that can parse Markdown into HTML.

test/extensions/alert_extension.unit

+39-2
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Test note alert x2.</p>
7474
<p>[!NOTE]
7575
Test blockquote.</p>
7676
</blockquote>
77-
>>>nested blockquote
77+
>>> nested blockquote
7878
> [!NOTE]
7979
>> Test nested blockquote.
8080
<<<
@@ -84,11 +84,48 @@ Test blockquote.</p>
8484
<p>Test nested blockquote.</p>
8585
</blockquote>
8686
</div>
87-
>>>escape brackets
87+
>>> escape brackets
8888
> \[!note\]
8989
> Test escape brackets.
9090
<<<
9191
<div class="markdown-alert markdown-alert-note">
9292
<p class="markdown-alert-title">Note</p>
9393
<p>Test escape brackets.</p>
9494
</div>
95+
>>> terminates properly
96+
> [!note]
97+
> A sample note.
98+
99+
Additional markdown text.
100+
<<<
101+
<div class="markdown-alert markdown-alert-note">
102+
<p class="markdown-alert-title">Note</p>
103+
<p>A sample note.</p>
104+
</div>
105+
<p>Additional markdown text.</p>
106+
>>> supports multiple quoted lines
107+
> [!note]
108+
> A sample note
109+
> with two lines.
110+
111+
Additional markdown text.
112+
<<<
113+
<div class="markdown-alert markdown-alert-note">
114+
<p class="markdown-alert-title">Note</p>
115+
<p>A sample note
116+
with two lines.</p>
117+
</div>
118+
<p>Additional markdown text.</p>
119+
>>> supports multiple lines
120+
> [!note]
121+
> A sample note
122+
with two lines.
123+
124+
Additional markdown text.
125+
<<<
126+
<div class="markdown-alert markdown-alert-note">
127+
<p class="markdown-alert-title">Note</p>
128+
<p>A sample note
129+
with two lines.</p>
130+
</div>
131+
<p>Additional markdown text.</p>

0 commit comments

Comments
 (0)