html-to-article-json
Version:
Converting HTML to article-json
41 lines (35 loc) • 922 B
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var hasNoContentNodes = function hasNoContentNodes(children) {
return children.every(function (child) {
return child.mark && !child.content || child.type !== 'text' && child.type !== 'linebreak';
});
};
var assureMinimumContent = function assureMinimumContent(node) {
if (node.children && hasNoContentNodes(node.children)) {
node.children.unshift({
type: 'linebreak'
});
}
};
var assureOneChild = function assureOneChild(tree) {
if (tree.length === 0) {
tree.push({
type: 'paragraph',
children: []
});
}
};
exports.default = function (tree) {
assureOneChild(tree);
tree.forEach(function (node) {
if (node.type === 'blockquote') {
assureOneChild(node.children);
node.children.forEach(assureMinimumContent);
} else {
assureMinimumContent(node);
}
});
};