md2hatena
Version:
Markdown to Hatena Syntax converter
43 lines (39 loc) • 743 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = joinNodes;
var isBlockType = {
heading: true,
paragraph: true,
html: true,
yaml: true,
list: true,
table: true,
code: true,
thematicBreak: true,
blockquote: true
};
function joinNodes(nodes, results) {
if (nodes.length === 0) {
return '';
}
var items = [];
var i = 0;
while (i < nodes.length) {
items.push(results[i]);
if (isBlockType[nodes[i].type]) {
var j = i + 1;
while (nodes[j] && results[j] === '') {
j++;
}
if (nodes[j] && isBlockType[nodes[j].type]) {
items.push('\n\n');
}
i = j;
} else {
i++;
}
}
return items.join('');
}