markdown: Only add \n\n on multiple paragraphs

Signed-off-by: Johannes Löthberg <johannes@kyriasis.com>
This commit is contained in:
Johannes Löthberg 2017-01-17 20:32:06 +01:00
parent 893a5c971f
commit 35d70f0b35

View file

@ -78,8 +78,20 @@ export default class Markdown {
} }
} else { } else {
renderer.paragraph = function(node, entering) { renderer.paragraph = function(node, entering) {
if (entering) { // If there is only one top level node, just return the
this.lit('\n\n'); // bare text: it's a single line of text and so should be
// 'inline', rather than unnecessarily wrapped in its own
// p tag. If, however, we have multiple nodes, each gets
// its own p tag to keep them as separate paragraphs.
var par = node;
while (par.parent) {
node = par;
par = par.parent;
}
if (node != par.lastChild) {
if (!entering) {
this.lit('\n\n');
}
} }
} }
} }