82 lines
1.3 KiB
TypeScript
82 lines
1.3 KiB
TypeScript
|
|
/**
|
|
*/
|
|
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"
|
|
),
|
|
"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"
|
|
),
|
|
},
|
|
{
|
|
"fallback": (element) => (
|
|
"<pre class=\"sd-unhandled\" rel=\"" + element.kind + "\">"
|
|
+
|
|
JSON.stringify(element, undefined, " ")
|
|
+
|
|
"</pre>"
|
|
),
|
|
}
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
output_kind_register(
|
|
"html",
|
|
(data, sub) => (
|
|
new type_output_html(
|
|
{
|
|
}
|
|
)
|
|
)
|
|
);
|