Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.
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: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## 7.2.2-wip
## 7.2.2

* Fix a crash parsing alert block syntax (#584).
* Have alert block syntax support multiple paragraphs (#577).
* Require Dart `^3.2.0`.

## 7.2.1
Expand Down
11 changes: 5 additions & 6 deletions lib/src/block_syntaxes/alert_block_syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ class AlertBlockSyntax extends BlockSyntax {

@override
bool canParse(BlockParser parser) {
return pattern.hasMatch(parser.current.content) &&
parser.lines.any((line) => _contentLineRegExp.hasMatch(line.content));
return alertPattern.hasMatch(parser.current.content);
Copy link
Contributor Author

@devoncarew devoncarew Mar 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on #585 (comment) and https://github.com/dart-lang/markdown/issues/579 I removed the reference here to BlockParser.lines; I suspect it caused quadratic parsing times.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SGTM

}

/// Whether this alert ends with a lazy continuation line.
Expand All @@ -39,9 +38,9 @@ class AlertBlockSyntax extends BlockSyntax {
_lazyContinuation = false;

while (!parser.isDone) {
final strippedContent =
parser.current.content.replaceFirst(RegExp(r'^\s*>?\s*'), '');
final match = strippedContent.isEmpty
final lineContent = parser.current.content.trimLeft();
final strippedContent = lineContent.replaceFirst(RegExp(r'^>?\s*'), '');
final match = strippedContent.isEmpty && !lineContent.startsWith('>')
? null
: _contentLineRegExp.firstMatch(strippedContent);
if (match != null) {
Expand All @@ -51,7 +50,7 @@ class AlertBlockSyntax extends BlockSyntax {
continue;
}

final lastLine = childLines.last;
final lastLine = childLines.isEmpty ? Line('') : childLines.last;

// A paragraph continuation is OK. This is content that cannot be parsed
// as any other syntax except Paragraph, and it doesn't match the bar in
Expand Down
6 changes: 3 additions & 3 deletions lib/src/patterns.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ final htmlCharactersPattern = RegExp(
final linkReferenceDefinitionPattern = RegExp(r'^[ ]{0,3}\[');

/// Alert type patterns.
/// A alert block is similar to a blockquote,
/// starts with `> [!TYPE]`, and only 5 types are supported
/// with case-insensitive.
///
/// A alert block is similar to a blockquote, starts with `> [!TYPE]`, and only
/// 5 types are supported (case-insensitive).
final alertPattern = RegExp(
r'^\s{0,3}>\s{0,3}\\?\[!(note|tip|important|caution|warning)\\?\]\s*$',
caseSensitive: false,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: markdown
version: 7.2.2-wip

version: 7.2.2
description: >-
A portable Markdown library written in Dart that can parse Markdown into HTML.
repository: https://github.com/dart-lang/markdown

topics:
- markdown

Expand Down
31 changes: 31 additions & 0 deletions test/extensions/alert_extension.unit
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,34 @@ Additional markdown text.
with two lines.</p>
</div>
<p>Additional markdown text.</p>
>>> supports continuation lines
> [!note]
> A sample note
with two lines.

Additional markdown text.
<<<
<div class="markdown-alert markdown-alert-note">
<p class="markdown-alert-title">Note</p>
<p>A sample note
with two lines.</p>
</div>
<p>Additional markdown text.</p>
>>> crash repro #584.1
> [!Warning]
>
> Some extensions won't work on dynamic types.
<<<
<div class="markdown-alert markdown-alert-warning">
<p class="markdown-alert-title">Warning</p>
<p>Some extensions won't work on dynamic types.</p>
</div>
>>> crash repro #584.2
> [!NOTE]
>
> if you receive the following error:
<<<
<div class="markdown-alert markdown-alert-note">
<p class="markdown-alert-title">Note</p>
<p>if you receive the following error:</p>
</div>