Skip to content
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
10 changes: 7 additions & 3 deletions lib/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -1434,10 +1434,14 @@ function escapeHTML( text ) {
.replace( /'/g, "'" );
}

function render_tree( jsonml ) {
function render_tree( jsonml, options ) {
options = options || {};
// escape HTML in strings?
options.escape = options.escape || false;

// basic case
if ( typeof jsonml === "string" ) {
return escapeHTML( jsonml );
return options.escape ? escapeHTML( jsonml ) : jsonml;
}

var tag = jsonml.shift(),
Expand All @@ -1449,7 +1453,7 @@ function render_tree( jsonml ) {
}

while ( jsonml.length ) {
content.push( render_tree( jsonml.shift() ) );
content.push( render_tree( jsonml.shift(), {escape: tag == 'code'} ) );
}

var tag_attrs = "";
Expand Down
13 changes: 13 additions & 0 deletions test/interface.t.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,16 @@ test("arguments untouched", function(t) {

t.end();
});

test("code escaped", function(t){
var input = "Here is an <i>example</i> of HTML:\n\n <p>Paragraph</p>",
tree = markdown.parse( input ),
output = markdown.toHTML( tree ),
expected = "<p>Here is an <i>example</i> of HTML:</p>\n\n<pre><code>&lt;p&gt;Paragraph&lt;/p&gt;</code></pre>";

// Escaping is done at the toHTML stage, so we test our escaping here,
// and not in features.
t.equivalent( expected, output, "HTML inside code blocks is escaped" );

t.end();
});