Skip to content

Commit 69e5fe0

Browse files
authored
Escape HTML attribute for fenced code blocks, in the info string; 2.0.3 (dart-archive/markdown#244)
Escape HTML attribute for fenced code blocks, in the info string; 2.0.3
1 parent 4df8a85 commit 69e5fe0

File tree

10 files changed

+27
-11
lines changed

10 files changed

+27
-11
lines changed

pkgs/markdown/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
* Render element attributes in the order they were defined.
44
Aligns more closely with the strict spec definition.
55
* Correctly render `&` within inline image titles.
6-
* Added 68 new GitHub emojis.
6+
* Add 68 new GitHub emojis.
7+
* Escape HTML attribute for fenced code blocks, in the info string.
78

89
## 2.0.2
910

pkgs/markdown/lib/src/block_parser.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ class FencedCodeBlockSyntax extends BlockSyntax {
443443

444444
var text = childLines.join('\n');
445445
if (parser.document.encodeHtml) {
446-
// Escape the code.
447446
text = escapeHtml(text);
448447
}
449448
var code = Element.text('code', text);
@@ -454,7 +453,13 @@ class FencedCodeBlockSyntax extends BlockSyntax {
454453
if (infoString.isNotEmpty) {
455454
// only use the first word in the syntax
456455
// http://spec.commonmark.org/0.22/#example-100
457-
infoString = infoString.split(' ').first;
456+
var firstSpace = infoString.indexOf(' ');
457+
if (firstSpace >= 0) {
458+
infoString = infoString.substring(0, firstSpace);
459+
}
460+
if (parser.document.encodeHtml) {
461+
infoString = escapeHtmlAttribute(infoString);
462+
}
458463
code.attributes['class'] = "language-$infoString";
459464
}
460465

pkgs/markdown/lib/src/util.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import 'package:charcode/charcode.dart';
55
String escapeHtml(String html) =>
66
const HtmlEscape(HtmlEscapeMode.element).convert(html);
77

8+
String escapeHtmlAttribute(String text) =>
9+
const HtmlEscape(HtmlEscapeMode.attribute).convert(text);
10+
811
// Escape the contents of [value], so that it may be used as an HTML attribute.
912

1013
// Based on http://spec.commonmark.org/0.28/#backslash-escapes.

pkgs/markdown/lib/src/version.dart

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkgs/markdown/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: markdown
2-
version: 2.0.3-dev
2+
version: 2.0.3
33

44
description: A library for converting markdown to HTML.
55
author: Dart Team <misc@dartlang.org>

pkgs/markdown/test/markdown_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ void main() {
2828
5 Ethernet ([Music](
2929
''', '''
3030
<p>5 Ethernet ([Music](</p>
31+
''');
32+
33+
validateCore('Escaping code block language', '''
34+
```"/><a/href="url">arbitrary_html</a>
35+
```
36+
''', '''
37+
<pre><code class="language-&quot;/&gt;&lt;a/href=&quot;url&quot;&gt;arbitrary_html&lt;/a&gt;"></code></pre>
3138
''');
3239
});
3340

pkgs/markdown/tool/common_mark_stats.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
"308": "strict",
245245
"309": "fail",
246246
"310": "fail",
247-
"311": "loose",
247+
"311": "fail",
248248
"312": "strict",
249249
"313": "strict"
250250
},

pkgs/markdown/tool/common_mark_stats.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
22 of 25 – 88.0% Block quotes
66
16 of 17 – 94.1% Code spans
77
124 of 128 – 96.9% Emphasis and strong emphasis
8-
10 of 12 – 83.3% Entity and numeric character references
8+
9 of 12 – 75.0% Entity and numeric character references
99
25 of 28 – 89.3% Fenced code blocks
1010
15 of 15 – 100.0% Hard line breaks
1111
43 of 43 – 100.0% HTML blocks
@@ -24,4 +24,4 @@
2424
11 of 11 – 100.0% Tabs
2525
3 of 3 – 100.0% Textual content
2626
19 of 19 – 100.0% Thematic breaks
27-
580 of 624 – 92.9% TOTAL
27+
579 of 624 – 92.8% TOTAL

pkgs/markdown/tool/gfm_stats.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@
265265
"321": "strict",
266266
"322": "fail",
267267
"323": "fail",
268-
"324": "loose",
268+
"324": "fail",
269269
"325": "strict",
270270
"326": "strict"
271271
},

pkgs/markdown/tool/gfm_stats.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
20 of 21 – 95.2% Code spans
88
0 of 1 – 0.0% Disallowed Raw HTML (extension)
99
125 of 129 – 96.9% Emphasis and strong emphasis
10-
10 of 12 – 83.3% Entity and numeric character references
10+
9 of 12 – 75.0% Entity and numeric character references
1111
25 of 28 – 89.3% Fenced code blocks
1212
15 of 15 – 100.0% Hard line breaks
1313
43 of 43 – 100.0% HTML blocks
@@ -28,4 +28,4 @@
2828
11 of 11 – 100.0% Tabs
2929
3 of 3 – 100.0% Textual content
3030
19 of 19 – 100.0% Thematic breaks
31-
601 of 654 – 91.9% TOTAL
31+
600 of 654 – 91.7% TOTAL

0 commit comments

Comments
 (0)