Skip to content
This repository was archived by the owner on Jan 26, 2019. It is now read-only.

Commit 0da3481

Browse files
dtaohegemonic
authored andcommitted
tests for HTML block support (evilstreak#34)
- tests for @marijnh's HTML block commit - support self-closing HTML tags - default to code blocks where indented
1 parent fd27f4c commit 0da3481

File tree

8 files changed

+39
-0
lines changed

8 files changed

+39
-0
lines changed

lib/markdown.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ Markdown.dialects = {};
302302
**/
303303
Markdown.dialects.Gruber = {
304304
block: {
305+
htmlBlock: function htmlBlock( block, next ) {
306+
if ( block.match( /^<\w/ ) && block.match( /\/>\s*$|<\/\s*\w+\s*>\s*$/ ) )
307+
return [["__RAW", block.toString()]];
308+
},
309+
305310
atxHeader: function atxHeader( block, next ) {
306311
var m = block.match( /^(#{1,6})\s*(.*?)\s*#*\s*(?:\n|$)/ );
307312

@@ -1414,6 +1419,10 @@ function render_tree( jsonml ) {
14141419
return escapeHTML( jsonml );
14151420
}
14161421

1422+
if ( jsonml[0] == "__RAW" ) {
1423+
return jsonml[1];
1424+
}
1425+
14171426
var tag = jsonml.shift(),
14181427
attributes = {},
14191428
content = [];

test/features.t.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ dialects.Gruber = [
6363
"emphasis",
6464
"headers",
6565
"horizontal_rules",
66+
"html_blocks",
6667
"images",
6768
"linebreaks",
6869
"links",

test/features/code/html_block.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
["html",
2+
["p", "This should not render as a block since it's indented (code):"],
3+
["pre",
4+
["code",
5+
"<div>This should be escaped as HTML code.</div>"
6+
]
7+
]
8+
]

test/features/code/html_block.text

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This should not render as a block since it's indented (code):
2+
3+
<div>This should be escaped as HTML code.</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
["html",
2+
["p", "The following is an HTML block:"],
3+
["__RAW",
4+
"<div class=\"html-block\">I am an HTML block.</div>"
5+
]
6+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The following is an HTML block:
2+
3+
<div class="html-block">I am an HTML block.</div>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
["html",
2+
["p", "The following is a self-closing HTML block:"],
3+
["__RAW",
4+
"<img src=\"self-closing-html-block.jpg\" />"
5+
]
6+
]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The following is a self-closing HTML block:
2+
3+
<img src="self-closing-html-block.jpg" />

0 commit comments

Comments
 (0)