Improve the match pattern of inline html (dart-lang/markdown#464)
* improve the match pattern of inline html
* Change version to 6.0.2-dev
* Update CHANGELOG.md
* Fix a CommonMark version number
* Fix a spelling
diff --git a/pkgs/markdown/CHANGELOG.md b/pkgs/markdown/CHANGELOG.md
index 8900c14..edd336b 100644
--- a/pkgs/markdown/CHANGELOG.md
+++ b/pkgs/markdown/CHANGELOG.md
@@ -1,4 +1,4 @@
-## 6.0.1
+## 6.0.2-dev
* Fix a crash in checkbox lists when mixing checkbox items with
non-checkbox items.
@@ -6,6 +6,7 @@
* Deprecate `BlockTagBlockHtmlSyntax`, `LongBlockHtmlSyntax` and
`OtherTagBlockHtmlSyntax`. These syntaxes will be removed from the next major
version.
+* Add an option `caseSensitive` to `TextSyntax`.
## 6.0.0
diff --git a/pkgs/markdown/lib/src/inline_syntaxes/inline_html_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/inline_html_syntax.dart
index 0151ba0..fb5b528 100644
--- a/pkgs/markdown/lib/src/inline_syntaxes/inline_html_syntax.dart
+++ b/pkgs/markdown/lib/src/inline_syntaxes/inline_html_syntax.dart
@@ -4,9 +4,10 @@
import '../../markdown.dart';
import '../charcode.dart';
+import '../patterns.dart';
/// Leave inline HTML tags alone, from
-/// [CommonMark 0.28](http://spec.commonmark.org/0.28/#raw-html).
+/// [CommonMark 0.30](http://spec.commonmark.org/0.30/#raw-html).
///
/// This is not actually a good definition (nor CommonMark's) of an HTML tag,
/// but it is fast. It will leave text like `<a href='hi">` alone, which is
@@ -15,9 +16,29 @@
/// TODO(srawlins): improve accuracy while ensuring performance, once
/// Markdown benchmarking is more mature.
class InlineHtmlSyntax extends TextSyntax {
+ static const _pattern = '(?:$namedTagDefinition)'
+ // Or
+ '|'
+
+ // HTML comment, see
+ // https://spec.commonmark.org/0.30/#html-comment.
+ '<!--(?:(?:[^-<>]+-[^-<>]+)+|[^-<>]+)-->'
+ '|'
+
+ // Processing-instruction, see
+ // https://spec.commonmark.org/0.30/#processing-instruction
+ r'<\?.*?\?>'
+ '|'
+
+ // Declaration, see
+ // https://spec.commonmark.org/0.30/#declaration.
+ '(<![a-z]+.*?>)'
+ '|'
+
+ // CDATA section, see
+ // https://spec.commonmark.org/0.30/#cdata-section.
+ r'(<!\[CDATA\[.*?]]>)';
+
InlineHtmlSyntax()
- : super(
- r'<[/!?]?[A-Za-z][A-Za-z0-9-]*(?:\s[^>]*)?>',
- startCharacter: $lt,
- );
+ : super(_pattern, startCharacter: $lt, caseSensitive: false);
}
diff --git a/pkgs/markdown/lib/src/inline_syntaxes/text_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/text_syntax.dart
index 6ec4828..b73d09d 100644
--- a/pkgs/markdown/lib/src/inline_syntaxes/text_syntax.dart
+++ b/pkgs/markdown/lib/src/inline_syntaxes/text_syntax.dart
@@ -16,8 +16,12 @@
/// If [sub] is passed, it is used as a simple replacement for [pattern]. If
/// [startCharacter] is passed, it is used as a pre-matching check which is
/// faster than matching against [pattern].
- TextSyntax(super.pattern, {String sub = '', super.startCharacter})
- : substitute = sub;
+ TextSyntax(
+ super.pattern, {
+ String sub = '',
+ super.startCharacter,
+ super.caseSensitive,
+ }) : substitute = sub;
/// Adds a [Text] node to [parser] and returns `true` if there is a
/// [substitute], as long as the preceding character (if any) is not a `/`.
diff --git a/pkgs/markdown/lib/src/patterns.dart b/pkgs/markdown/lib/src/patterns.dart
index 71b2570..67b33ad 100644
--- a/pkgs/markdown/lib/src/patterns.dart
+++ b/pkgs/markdown/lib/src/patterns.dart
@@ -126,7 +126,7 @@
final dummyPattern = RegExp('');
/// A [String] pattern to match a named tag like `<table>` or `</table>`.
-const _namedTagDefinition =
+const namedTagDefinition =
// Opening tag begins.
'<'
@@ -196,5 +196,5 @@
// Because if a line is treated as an HTML block, it will output as Text node
// directly, the RawHtmlSyntax does not have a chance to validate if this
// HTML tag is legal or not.
- '(?<condition_7>(?:$_namedTagDefinition)\\s*\$))',
+ '(?<condition_7>(?:$namedTagDefinition)\\s*\$))',
caseSensitive: false);
diff --git a/pkgs/markdown/lib/src/version.dart b/pkgs/markdown/lib/src/version.dart
index da01dc7..1806888 100644
--- a/pkgs/markdown/lib/src/version.dart
+++ b/pkgs/markdown/lib/src/version.dart
@@ -1,2 +1,2 @@
// Generated code. Do not modify.
-const packageVersion = '6.0.1';
+const packageVersion = '6.0.2-dev';
diff --git a/pkgs/markdown/pubspec.yaml b/pkgs/markdown/pubspec.yaml
index ab02324..470875d 100644
--- a/pkgs/markdown/pubspec.yaml
+++ b/pkgs/markdown/pubspec.yaml
@@ -1,5 +1,5 @@
name: markdown
-version: 6.0.1
+version: 6.0.2-dev
description: A portable Markdown library written in Dart that can parse
Markdown into HTML.
diff --git a/pkgs/markdown/test/common_mark/raw_html.unit b/pkgs/markdown/test/common_mark/raw_html.unit
index a91a33f..cde09c4 100644
--- a/pkgs/markdown/test/common_mark/raw_html.unit
+++ b/pkgs/markdown/test/common_mark/raw_html.unit
@@ -5,7 +5,7 @@
>>> Raw HTML - 613
<a/><b2/>
<<<
-<p><a/><b2/></p>
+<p><a/><b2/></p>
>>> Raw HTML - 614
<a /><b2
data="foo" >
@@ -29,11 +29,11 @@
>>> Raw HTML - 618
<a h*#ref="hi">
<<<
-<p><a h*#ref="hi"></p>
+<p><a h*#ref="hi"></p>
>>> Raw HTML - 619
<a href="hi'> <a href=hi'>
<<<
-<p><a href="hi'> <a href=hi'></p>
+<p><a href="hi'> <a href=hi'></p>
>>> Raw HTML - 620
< a><
foo><bar/ >
@@ -42,12 +42,12 @@
<<<
<p>< a><
foo><bar/ >
-<foo bar=baz
+<foo bar=baz
bim!bop /></p>
>>> Raw HTML - 621
<a href='bar'title=title>
<<<
-<p><a href='bar'title=title></p>
+<p><a href='bar'title=title></p>
>>> Raw HTML - 622
</a></foo >
<<<
@@ -55,13 +55,13 @@
>>> Raw HTML - 623
</a href="foo">
<<<
-<p></a href="foo"></p>
+<p></a href="foo"></p>
>>> Raw HTML - 624
foo <!-- this is a
comment - with hyphen -->
<<<
-<p>foo <!-- this is a
-comment - with hyphen --></p>
+<p>foo <!-- this is a
+comment - with hyphen --></p>
>>> Raw HTML - 625
foo <!-- not a comment -- two hyphens -->
<<<
@@ -84,7 +84,7 @@
>>> Raw HTML - 629
foo <![CDATA[>&<]]>
<<<
-<p>foo <![CDATA[>&<]]></p>
+<p>foo <![CDATA[>&<]]></p>
>>> Raw HTML - 630
foo <a href="ö">
<<<
@@ -96,4 +96,4 @@
>>> Raw HTML - 632
<a href="\"">
<<<
-<p><a href="\""></p>
+<p><a href="""></p>
diff --git a/pkgs/markdown/test/gfm/raw_html.unit b/pkgs/markdown/test/gfm/raw_html.unit
index aec88ab..1802dba 100644
--- a/pkgs/markdown/test/gfm/raw_html.unit
+++ b/pkgs/markdown/test/gfm/raw_html.unit
@@ -5,7 +5,7 @@
>>> Raw HTML - 633
<a/><b2/>
<<<
-<p><a/><b2/></p>
+<p><a/><b2/></p>
>>> Raw HTML - 634
<a /><b2
data="foo" >
@@ -29,11 +29,11 @@
>>> Raw HTML - 638
<a h*#ref="hi">
<<<
-<p><a h*#ref="hi"></p>
+<p><a h*#ref="hi"></p>
>>> Raw HTML - 639
<a href="hi'> <a href=hi'>
<<<
-<p><a href="hi'> <a href=hi'></p>
+<p><a href="hi'> <a href=hi'></p>
>>> Raw HTML - 640
< a><
foo><bar/ >
@@ -42,12 +42,12 @@
<<<
<p>< a><
foo><bar/ >
-<foo bar=baz
+<foo bar=baz
bim!bop /></p>
>>> Raw HTML - 641
<a href='bar'title=title>
<<<
-<p><a href='bar'title=title></p>
+<p><a href='bar'title=title></p>
>>> Raw HTML - 642
</a></foo >
<<<
@@ -55,13 +55,13 @@
>>> Raw HTML - 643
</a href="foo">
<<<
-<p></a href="foo"></p>
+<p></a href="foo"></p>
>>> Raw HTML - 644
foo <!-- this is a
comment - with hyphen -->
<<<
-<p>foo <!-- this is a
-comment - with hyphen --></p>
+<p>foo <!-- this is a
+comment - with hyphen --></p>
>>> Raw HTML - 645
foo <!-- not a comment -- two hyphens -->
<<<
@@ -84,7 +84,7 @@
>>> Raw HTML - 649
foo <![CDATA[>&<]]>
<<<
-<p>foo <![CDATA[>&<]]></p>
+<p>foo <![CDATA[>&<]]></p>
>>> Raw HTML - 650
foo <a href="ö">
<<<
@@ -96,4 +96,4 @@
>>> Raw HTML - 652
<a href="\"">
<<<
-<p><a href="\""></p>
+<p><a href="""></p>
diff --git a/pkgs/markdown/tool/common_mark_stats.json b/pkgs/markdown/tool/common_mark_stats.json
index cdaa19a..a0ec35d 100644
--- a/pkgs/markdown/tool/common_mark_stats.json
+++ b/pkgs/markdown/tool/common_mark_stats.json
@@ -610,26 +610,26 @@
},
"Raw HTML": {
"612": "strict",
- "613": "fail",
+ "613": "strict",
"614": "strict",
"615": "strict",
"616": "strict",
"617": "strict",
- "618": "fail",
+ "618": "loose",
"619": "loose",
- "620": "fail",
- "621": "fail",
+ "620": "loose",
+ "621": "strict",
"622": "strict",
"623": "loose",
- "624": "loose",
+ "624": "strict",
"625": "strict",
"626": "strict",
"627": "strict",
"628": "strict",
- "629": "loose",
+ "629": "strict",
"630": "strict",
"631": "strict",
- "632": "fail"
+ "632": "loose"
},
"Setext headings": {
"80": "strict",
diff --git a/pkgs/markdown/tool/common_mark_stats.txt b/pkgs/markdown/tool/common_mark_stats.txt
index 1ab5d03..96db9f5 100644
--- a/pkgs/markdown/tool/common_mark_stats.txt
+++ b/pkgs/markdown/tool/common_mark_stats.txt
@@ -18,11 +18,11 @@
22 of 26 – 84.6% Lists
8 of 8 – 100.0% Paragraphs
1 of 1 – 100.0% Precedence
- 16 of 21 – 76.2% Raw HTML
+ 21 of 21 – 100.0% Raw HTML
26 of 27 – 96.3% Setext headings
2 of 2 – 100.0% Soft line breaks
11 of 11 – 100.0% Tabs
3 of 3 – 100.0% Textual content
19 of 19 – 100.0% Thematic breaks
- 615 of 652 – 94.3% TOTAL
- 549 of 615 – 89.3% TOTAL Strict
+ 620 of 652 – 95.1% TOTAL
+ 553 of 620 – 89.2% TOTAL Strict
diff --git a/pkgs/markdown/tool/gfm_stats.json b/pkgs/markdown/tool/gfm_stats.json
index 3ef3e95..558b177 100644
--- a/pkgs/markdown/tool/gfm_stats.json
+++ b/pkgs/markdown/tool/gfm_stats.json
@@ -623,26 +623,26 @@
},
"Raw HTML": {
"632": "strict",
- "633": "fail",
+ "633": "strict",
"634": "strict",
"635": "strict",
"636": "strict",
"637": "strict",
- "638": "fail",
+ "638": "loose",
"639": "loose",
- "640": "fail",
- "641": "fail",
+ "640": "loose",
+ "641": "strict",
"642": "strict",
"643": "loose",
- "644": "loose",
+ "644": "strict",
"645": "strict",
"646": "strict",
"647": "strict",
"648": "strict",
- "649": "loose",
+ "649": "strict",
"650": "strict",
"651": "strict",
- "652": "fail"
+ "652": "loose"
},
"Setext headings": {
"50": "strict",
diff --git a/pkgs/markdown/tool/gfm_stats.txt b/pkgs/markdown/tool/gfm_stats.txt
index e18f44f..8b065e0 100644
--- a/pkgs/markdown/tool/gfm_stats.txt
+++ b/pkgs/markdown/tool/gfm_stats.txt
@@ -20,7 +20,7 @@
22 of 26 – 84.6% Lists
8 of 8 – 100.0% Paragraphs
1 of 1 – 100.0% Precedence
- 16 of 21 – 76.2% Raw HTML
+ 21 of 21 – 100.0% Raw HTML
26 of 27 – 96.3% Setext headings
2 of 2 – 100.0% Soft line breaks
2 of 2 – 100.0% Strikethrough (extension)
@@ -28,5 +28,5 @@
11 of 11 – 100.0% Tabs
3 of 3 – 100.0% Textual content
19 of 19 – 100.0% Thematic breaks
- 627 of 671 – 93.4% TOTAL
- 552 of 627 – 88.0% TOTAL Strict
+ 632 of 671 – 94.2% TOTAL
+ 556 of 632 – 88.0% TOTAL Strict