Skip to content

Commit fb645f7

Browse files
kapouerry
authored andcommitted
Update ronnjs (fix rendering of html self-closing tags)
1 parent 50c38de commit fb645f7

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

tools/ronnjs/lib/ext/markdown.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,11 +1252,12 @@ expose.renderJsonML = function( jsonml, options ) {
12521252
options = options || {};
12531253
// include the root element in the rendered output?
12541254
options.root = options.root || false;
1255+
options.xhtml = options.xhtml || false;
12551256

12561257
var content = [];
12571258

12581259
if ( options.root ) {
1259-
content.push( render_tree( jsonml ) );
1260+
content.push( render_tree( jsonml, options.xhtml ) );
12601261
}
12611262
else {
12621263
jsonml.shift(); // get rid of the tag
@@ -1265,14 +1266,14 @@ expose.renderJsonML = function( jsonml, options ) {
12651266
}
12661267

12671268
while ( jsonml.length ) {
1268-
content.push( render_tree( jsonml.shift() ) );
1269+
content.push( render_tree( jsonml.shift(), options.xhtml ) );
12691270
}
12701271
}
12711272

1272-
return content.join( "\n" ).replace( /\n+$/, "" );
1273+
return content.join( "\n\n" );
12731274
}
12741275

1275-
function render_tree( jsonml ) {
1276+
function render_tree( jsonml, xhtml ) {
12761277
// basic case
12771278
if ( typeof jsonml === "string" ) {
12781279
return jsonml.replace( /&/g, "&" )
@@ -1289,24 +1290,25 @@ function render_tree( jsonml ) {
12891290
}
12901291

12911292
while ( jsonml.length ) {
1292-
content.push( arguments.callee( jsonml.shift() ) );
1293+
content.push( arguments.callee( jsonml.shift(), xhtml ) );
12931294
}
12941295

12951296
var tag_attrs = "";
12961297
for ( var a in attributes ) {
12971298
tag_attrs += " " + a + '="' + attributes[ a ] + '"';
12981299
}
1299-
1300-
var newlinetab = "\n ",
1301-
newline = "\n";
1302-
1303-
if ( ~["em", "strong", "img", "br", "a"].indexOf( tag ) ) {
1304-
newlinetab = "";
1305-
newline = "";
1306-
}
1307-
1300+
1301+
// if xhtml, self-close empty tags
13081302
// be careful about adding whitespace here for inline elements
1309-
return "<"+ tag + tag_attrs + ">" + newlinetab + content.join( "" ).replace( /\n$/, "" ).replace( /\n/g, "\n " ) + newline + "</" + tag + ">" + newline;
1303+
var markup = "<"+ tag + tag_attrs;
1304+
var contentstr = content.join( "" );
1305+
if ( xhtml && contentstr.length == 0 ) {
1306+
markup += " />";
1307+
}
1308+
else {
1309+
markup += ">" + contentstr + "</" + tag + ">";
1310+
}
1311+
return markup;
13101312
}
13111313

13121314
function convert_tree_to_html( tree, references ) {

tools/ronnjs/lib/ronn.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,11 @@ exports.Ronn = function(text, version, manual, date) {
267267

268268
function toHTML(node) {
269269
// problème ici : les & sont remplacés par des &amp;
270-
return md.renderJsonML(node, {root:true});
270+
return md.renderJsonML(node, {root:true, xhtml:true});
271271
}
272272

273273
function toHTMLfragment(node) {
274-
return md.renderJsonML(node);
274+
return md.renderJsonML(node, {xhtml:true});
275275
}
276276

277277
function comment(out, str) {

0 commit comments

Comments
 (0)