[mod] output:html:xml nutzen
This commit is contained in:
parent
1812d5781a
commit
95469e839f
|
|
@ -9,60 +9,124 @@ class type_output_html implements type_output<string>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
|
private render_element_internal(
|
||||||
|
element : type_element,
|
||||||
|
options : {
|
||||||
|
depth ?: int;
|
||||||
|
level ?: int;
|
||||||
|
} = {}
|
||||||
|
) : lib_plankton.xml.class_node
|
||||||
|
{
|
||||||
|
options = Object.assign(
|
||||||
|
{
|
||||||
|
"depth": 0,
|
||||||
|
"level": 0,
|
||||||
|
},
|
||||||
|
options
|
||||||
|
);
|
||||||
|
return lib_plankton.call.distinguish<lib_plankton.xml.class_node>(
|
||||||
|
element,
|
||||||
|
{
|
||||||
|
"text": ({"content": content}) => new lib_plankton.xml.class_node_complex(
|
||||||
|
"span",
|
||||||
|
{
|
||||||
|
"class": "sd-text",
|
||||||
|
},
|
||||||
|
[
|
||||||
|
new lib_plankton.xml.class_node_text(content),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
"group": ({"members": members}) => new lib_plankton.xml.class_node_complex(
|
||||||
|
"div",
|
||||||
|
{
|
||||||
|
"class": "sd-group",
|
||||||
|
},
|
||||||
|
(
|
||||||
|
members
|
||||||
|
.map(
|
||||||
|
x => this.render_element_internal(
|
||||||
|
x,
|
||||||
|
{
|
||||||
|
"depth": options.depth,
|
||||||
|
"level": options.level,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
"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_element_internal(
|
||||||
|
content,
|
||||||
|
{
|
||||||
|
"depth": (options.depth + 1),
|
||||||
|
"level": (options.level + 1),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
]
|
||||||
|
),
|
||||||
|
"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_element_internal(
|
||||||
|
item,
|
||||||
|
{
|
||||||
|
"level": options.level,
|
||||||
|
"depth": (options.depth + 1),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"fallback": (element) => new lib_plankton.xml.class_node_complex(
|
||||||
|
"pre",
|
||||||
|
{
|
||||||
|
"class": "sd-unhandled",
|
||||||
|
"rel": element.kind,
|
||||||
|
},
|
||||||
|
[
|
||||||
|
new lib_plankton.xml.class_node_text(
|
||||||
|
JSON.stringify(element, undefined, " "),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @implementation
|
||||||
|
*/
|
||||||
public render_element(
|
public render_element(
|
||||||
element : type_element
|
element : type_element
|
||||||
) : string
|
) : string
|
||||||
{
|
{
|
||||||
return lib_plankton.call.distinguish<string>(
|
return this.render_element_internal(element).compile();
|
||||||
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>"
|
|
||||||
),
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue