feat: reorganize builder

This commit is contained in:
obvTiger 2025-03-27 13:28:12 +01:00
parent ff7bb041ef
commit 362b7aa15e
18 changed files with 1094 additions and 310 deletions

View file

@ -0,0 +1,47 @@
/**
* Generates HTML for the root node of the AST.
*/
class RootNodeGenerator {
/**
* Creates a new root node generator.
* @param {Object} options - Options for the generator
* @param {Object} parentGenerator - Parent HTML generator for recursion
*/
constructor(options, parentGenerator) {
this.options = options;
this.parentGenerator = parentGenerator;
}
/**
* Determines if this generator can handle the given node.
* @param {Object} node - The node to check
* @returns {boolean} - True if this generator can handle the node
*/
canHandle(node) {
return node.type === "root";
}
/**
* Generates HTML for the root node.
* @param {Object} node - The node to generate HTML for
* @returns {string} - The generated HTML
*/
generate(node) {
if (this.options.debug) {
console.log(`\n[RootNodeGenerator] Processing root node with ${node.children.length} children`);
}
let html = "";
node.children.forEach((child, index) => {
if (this.options.debug) {
console.log(`[RootNodeGenerator] Processing child ${index + 1}/${node.children.length}`);
}
html += this.parentGenerator.generateHTML(child);
});
return html;
}
}
module.exports = RootNodeGenerator;