Skip to content

Support for HTML blocks (w/ tests) #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions lib/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,11 @@ Markdown.dialects = {};
**/
Markdown.dialects.Gruber = {
block: {
htmlBlock: function htmlBlock( block, next ) {
if ( block.match( /^<\w/ ) && block.match( /\/>\s*$|<\/\s*\w+\s*>\s*$/ ) )
return [["__RAW", block.toString()]];
},

atxHeader: function atxHeader( block, next ) {
var m = block.match( /^(#{1,6})\s*(.*?)\s*#*\s*(?:\n|$)/ );

Expand Down Expand Up @@ -1445,6 +1450,10 @@ function render_tree( jsonml ) {
return escapeHTML( jsonml );
}

if ( jsonml[0] == "__RAW" ) {
return jsonml[1];
}

var tag = jsonml.shift(),
attributes = {},
content = [];
Expand Down
1 change: 1 addition & 0 deletions test/features.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ dialects.Gruber = [
"emphasis",
"headers",
"horizontal_rules",
"html_blocks",
"images",
"linebreaks",
"links",
Expand Down
8 changes: 8 additions & 0 deletions test/features/code/html_block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
["html",
["p", "This should not render as a block since it's indented (code):"],
["pre",
["code",
"<div>This should be escaped as HTML code.</div>"
]
]
]
3 changes: 3 additions & 0 deletions test/features/code/html_block.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This should not render as a block since it's indented (code):

<div>This should be escaped as HTML code.</div>
5 changes: 5 additions & 0 deletions test/features/html_blocks/embedded_markdown.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
["html",
["__RAW",
"<div>**Embedded Markdown** is *not* supported.</div>"
]
]
1 change: 1 addition & 0 deletions test/features/html_blocks/embedded_markdown.text
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div>**Embedded Markdown** is *not* supported.</div>
6 changes: 6 additions & 0 deletions test/features/html_blocks/html_block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
["html",
["p", "The following is an HTML block:"],
["__RAW",
"<div class=\"html-block\">I am an HTML block.</div>"
]
]
3 changes: 3 additions & 0 deletions test/features/html_blocks/html_block.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The following is an HTML block:

<div class="html-block">I am an HTML block.</div>
6 changes: 6 additions & 0 deletions test/features/html_blocks/self_closing.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
["html",
["p", "The following is a self-closing HTML block:"],
["__RAW",
"<img src=\"self-closing-html-block.jpg\" />"
]
]
3 changes: 3 additions & 0 deletions test/features/html_blocks/self_closing.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The following is a self-closing HTML block:

<img src="self-closing-html-block.jpg" />