/**
*/
class type_output_html implements type_output
{
public readonly kind : string = "html";
public readonly data : {};
public constructor(data : {}) {this.data = data;}
/**
*/
private render_object_internal(
object : type_object,
options : {
level ?: int;
depth ?: int;
} = {}
) : lib_plankton.xml.class_node
{
options = Object.assign(
{
"level": 0,
"depth": 0,
},
options
);
return lib_plankton.call.distinguish(
object,
{
"text": ({"content": content}) => new lib_plankton.xml.class_node_complex(
"span",
{
"class": "sd-text",
},
[
new lib_plankton.xml.class_node_text(content),
]
),
"code": ({"content": content}) => new lib_plankton.xml.class_node_complex(
"code",
{
"class": "sd-code",
},
[
new lib_plankton.xml.class_node_text(content),
]
),
"link": ({"target": target, "label": label}) => new lib_plankton.xml.class_node_complex(
"a",
{
"class": "sd-link",
"href": target,
},
(
(label === null)
? []
: [new lib_plankton.xml.class_node_text(label)]
)
),
"image": ({"url": url, "label": label}) => new lib_plankton.xml.class_node_complex(
"img",
{
"class": "sd-image",
"alt": label,
"src": url,
},
[]
),
"paragraph": ({"content": content}) => new lib_plankton.xml.class_node_complex(
"p",
{
"class": "sd-paragraph",
},
[
this.render_object_internal(
content,
{
"level": options.level,
"depth": (options.depth + 1),
}
),
]
),
"section": ({"title": title, "content": content}) => new lib_plankton.xml.class_node_complex(
"section",
{
"class": "sd-section",
},
[
new lib_plankton.xml.class_node_complex(
("h" + (options.level + 1).toFixed(0)),
{},
[
new lib_plankton.xml.class_node_text(title),
]
),
this.render_object_internal(
content,
{
"level": (options.level + 1),
"depth": (options.depth + 1),
}
),
]
),
"group": ({"members": members}) => new lib_plankton.xml.class_node_complex(
"div",
{
"class": "sd-group",
},
(
members
.map(
x => this.render_object_internal(
x,
{
"depth": options.depth,
"level": options.level,
}
)
)
)
),
"list": ({"items": items}) => new lib_plankton.xml.class_node_complex(
"ul",
{
"class": "sd-list",
},
(
items
.map(
item => new lib_plankton.xml.class_node_complex(
"li",
{},
[
this.render_object_internal(
item,
{
"level": options.level,
"depth": (options.depth + 1),
}
),
]
)
)
),
),
"table": ({"head": head, "rows": rows}) => new lib_plankton.xml.class_node_complex(
"table",
{
"class": "sd-table",
},
(
[]
.concat(
(head === null)
? []
: [
new lib_plankton.xml.class_node_complex(
"thead",
{},
[
new lib_plankton.xml.class_node_complex(
"tr",
{},
(
head.map(
cell => new lib_plankton.xml.class_node_complex(
"th",
{},
[
this.render_object_internal(
cell,
{
"level": options.level,
"depth": (options.depth + 1),
}
),
]
)
)
)
),
]
),
]
)
.concat(
[
new lib_plankton.xml.class_node_complex(
"tbody",
{},
(
rows.map(
row => new lib_plankton.xml.class_node_complex(
"tr",
{},
(
row.map(
cell => new lib_plankton.xml.class_node_complex(
"td",
{},
[
this.render_object_internal(
cell,
{
"level": options.level,
"depth": (options.depth + 1),
}
),
]
)
)
)
)
)
)
)
]
)
),
),
},
{
"fallback": (object) => new lib_plankton.xml.class_node_complex(
"pre",
{
"class": "sd-unhandled",
"rel": object.kind,
},
[
new lib_plankton.xml.class_node_text(
JSON.stringify(object, undefined, " "),
)
]
),
}
);
}
/**
* @implementation
*/
public render_object(
object : type_object
) : string
{
return this.render_object_internal(object).compile();
}
/**
* @implementation
*/
public render_document(
document : type_document
) : string
{
return lib_plankton.string.coin(
"\n{{html}}",
{
"html": new lib_plankton.xml.class_node_complex(
"html",
{},
[
new lib_plankton.xml.class_node_complex(
"head",
{
},
[
new lib_plankton.xml.class_node_complex(
"meta",
{
"charset": "utf-8",
},
[
]
),
new lib_plankton.xml.class_node_complex(
"title",
{
},
[
new lib_plankton.xml.class_node_text(
document.content_title
),
]
),
]
),
new lib_plankton.xml.class_node_complex(
"body",
{
},
[
this.render_object_internal(
document.content_main,
{
"depth": 1,
}
),
]
)
]
).compile()
}
);
}
}
/**
*/
output_kind_register(
"html",
(data, sub) => (
new type_output_html(
{
}
)
)
);