mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-20 20:00:33 +03:00
jsdoc md generator
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
# bbob-render
|
||||
Converts bbob-parser AST tree to html
|
||||
# bbob-html
|
||||
Converts bbob-parser AST tree to html
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
function render(tree, options) {
|
||||
|
||||
}
|
||||
|
||||
function attrs(obj) {
|
||||
let attr = '';
|
||||
@@ -20,16 +17,68 @@ function attrs(obj) {
|
||||
|
||||
function traverse(tree, cb) {
|
||||
if (Array.isArray(tree)) {
|
||||
let i = 0,
|
||||
length = tree.length;
|
||||
for (; i < length; i++) {
|
||||
tree.forEach((_, i) => {
|
||||
traverse(cb(tree[i]), cb);
|
||||
}
|
||||
} else if (typeof tree === 'object' && tree.hasOwnProperty('content')) {
|
||||
});
|
||||
} else if (typeof tree === 'object' && tree.content) {
|
||||
traverse(tree.content, cb);
|
||||
}
|
||||
|
||||
return tree;
|
||||
}
|
||||
|
||||
function render(tree, options) {
|
||||
return html(tree);
|
||||
|
||||
function html(tree) {
|
||||
let result = '';
|
||||
|
||||
traverse([].concat(tree), (node) => {
|
||||
if (!node) return;
|
||||
|
||||
if (typeof node === 'string' || typeof node === 'number') {
|
||||
result += node;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof node.tag === 'boolean' && !node.tag) {
|
||||
typeof node.content !== 'object' && (result += node.content);
|
||||
|
||||
return node.content;
|
||||
}
|
||||
|
||||
// treat as new root tree if node is an array
|
||||
if (Array.isArray(node)) {
|
||||
result += html(node);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const tag = node.tag || 'div';
|
||||
|
||||
if (isSingleTag(tag, singleTags, singleRegExp)) {
|
||||
result += `<${tag}${attrs(node.attrs)}`;
|
||||
|
||||
switch (closingSingleTag) {
|
||||
case 'tag':
|
||||
result += `></${tag}>`;
|
||||
|
||||
break;
|
||||
case 'slash':
|
||||
result += ' />';
|
||||
|
||||
break;
|
||||
default:
|
||||
result += '>';
|
||||
}
|
||||
} else {
|
||||
result += `<${tag}${node.attrs ? attrs(node.attrs) : ''}>${node.content ? html(node.content) : ''}</${tag}>`;
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = render;
|
||||
|
||||
Reference in New Issue
Block a user