docdef/source/outputs/implementations/html.ts

82 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-02-08 10:41:17 +01:00
/**
*/
class type_output_html implements type_output<string>
{
public readonly kind : string = "html";
public readonly data : {};
public constructor(data : {}) {this.data = data;}
/**
*/
public render_element(
element : type_element
) : string
{
return lib_plankton.call.distinguish<string>(
element,
{
"text": ({"content": content}) => (
"<span class=\"sd-text\">"
+
content
+
"</span>"
),
"group": ({"members": members}) => (
"<div class=\"sd-group\">\n"
+
members.map(x => this.render_element(x)).join("")
+
"</div>\n"
),
2024-02-08 11:10:07 +01:00
"section": ({"title": title, "content": content}) => (
"<section class=\"sd-section\">\n"
+
(
"<header>"
+
title
+
"</header>"
)
+
this.render_element(content)
+
"</section>\n"
),
"list": ({"items": items}) => (
"<ul class=\"sd-list\">\n"
+
items.map(x => this.render_element(x)).map(x => ("<li>" + x + "</li>\n")).join("")
+
"</ul>\n"
),
2024-02-08 10:41:17 +01:00
},
{
"fallback": (element) => (
2024-02-08 11:10:07 +01:00
"<pre class=\"sd-unhandled\" rel=\"" + element.kind + "\">"
2024-02-08 10:41:17 +01:00
+
JSON.stringify(element, undefined, " ")
+
"</pre>"
),
}
);
}
}
2024-02-08 11:10:07 +01:00
/**
*/
output_kind_register(
"html",
(data, sub) => (
new type_output_html(
{
}
)
)
);