From 95469e839f0bfbcbef364174b7754b9eaf0594f9 Mon Sep 17 00:00:00 2001 From: Fenris Wolf Date: Thu, 8 Feb 2024 16:57:51 +0100 Subject: [PATCH] [mod] output:html:xml nutzen --- source/outputs/implementations/html.ts | 164 +++++++++++++++++-------- 1 file changed, 114 insertions(+), 50 deletions(-) diff --git a/source/outputs/implementations/html.ts b/source/outputs/implementations/html.ts index 67952df..9b0f754 100644 --- a/source/outputs/implementations/html.ts +++ b/source/outputs/implementations/html.ts @@ -9,60 +9,124 @@ class type_output_html implements type_output /** */ + 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( + 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( element : type_element ) : string { - return lib_plankton.call.distinguish( - element, - { - "text": ({"content": content}) => ( - "" - + - content - + - "" - ), - "group": ({"members": members}) => ( - "
\n" - + - members.map(x => this.render_element(x)).join("") - + - "
\n" - ), - "section": ({"title": title, "content": content}) => ( - "
\n" - + - ( - "
" - + - title - + - "
" - ) - + - this.render_element(content) - + - "
\n" - ), - "list": ({"items": items}) => ( - "
    \n" - + - items.map(x => this.render_element(x)).map(x => ("
  • " + x + "
  • \n")).join("") - + - "
\n" - ), - }, - { - "fallback": (element) => ( - "
"
-					+
-					JSON.stringify(element, undefined, "    ")
-					+
-					"
" - ), - } - ); + return this.render_element_internal(element).compile(); } }