diff --git a/CHANGELOG.md b/CHANGELOG.md index 55760bf5..f7859d45 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/src/block_syntaxes/alert_block_syntax.dart b/lib/src/block_syntaxes/alert_block_syntax.dart index 54286040..0f4f5b11 100644 --- a/lib/src/block_syntaxes/alert_block_syntax.dart +++ b/lib/src/block_syntaxes/alert_block_syntax.dart @@ -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); } /// Whether this alert ends with a lazy continuation line. @@ -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) { @@ -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 diff --git a/lib/src/patterns.dart b/lib/src/patterns.dart index 4899ea16..2690419c 100644 --- a/lib/src/patterns.dart +++ b/lib/src/patterns.dart @@ -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, diff --git a/lib/src/version.dart b/lib/src/version.dart index b0cf8611..f10c4ff9 100644 --- a/lib/src/version.dart +++ b/lib/src/version.dart @@ -1,2 +1,2 @@ // Generated code. Do not modify. -const packageVersion = '7.2.2-wip'; +const packageVersion = '7.2.2'; diff --git a/pubspec.yaml b/pubspec.yaml index bd85b659..7cb8b6fb 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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 diff --git a/test/extensions/alert_extension.unit b/test/extensions/alert_extension.unit index 0f422b5c..9a21f186 100644 --- a/test/extensions/alert_extension.unit +++ b/test/extensions/alert_extension.unit @@ -129,3 +129,34 @@ Additional markdown text. with two lines.
Additional markdown text.
+>>> supports continuation lines +> [!note] +> A sample note +with two lines. + +Additional markdown text. +<<< +Note
+A sample note +with two lines.
+Additional markdown text.
+>>> crash repro #584.1 +> [!Warning] +> +> Some extensions won't work on dynamic types. +<<< +Warning
+Some extensions won't work on dynamic types.
+Note
+if you receive the following error:
+