/** */ class type_output_markdown implements type_output { public readonly kind : string = "markdown"; public readonly data : {}; public constructor(data : {}) {this.data = data;} /** */ private render_object_internal( object : type_object, options : { depth ?: int; headline_level ?: int; list_level ?: int; } = {} ) : string { options = Object.assign( { "depth": 0, "headline_level": 0, "list_level": 0, }, options ); return lib_plankton.call.distinguish( object, { "text": ({"content": content}) => lib_plankton.string.coin( "{{content}}", { "content": content, } ), "code": ({"content": content}) => lib_plankton.string.coin( "`{{content}}`", { "content": content, } ), "link": ({"target": target, "label": label}) => lib_plankton.string.coin( "[{{label}}]({{target}})", { "target": target, "label": label, } ), "section": ({"title": title, "content": content}) => lib_plankton.string.coin( "{{head}}\n\n{{body}}\n\n\n", { "head": lib_plankton.string.coin( "{{prefix}} {{value}}", { "prefix": "#".repeat(options.level + 1), "value": title, } ), "body": this.render_object_internal( content, { "depth": (options.depth + 1), "headline_level": (options.level + 1), "list_level": options.list_level, } ), } ), "group": ({"members": members}) => lib_plankton.string.coin( "{{members}}", { "members": ( members .map( x => this.render_object_internal( x, { "depth": options.depth, "headline_level": options.level, "list_level": options.list_level } ) ) .join( "" ) ) } ), "list": ({"items": items}) => lib_plankton.string.coin( "{{items}}", { "items": ( items .map( item => lib_plankton.string.coin( "{{indentation}}- {{content}}", { "indentation": " ".repeat(options.list_level), "content": this.render_object_internal( item, { "depth": (options.depth + 1), "headline_level": options.level, "list_level": (options.list_level + 1), } ), }, ) ) .join( "\n" ) ), } ), "table": ({"head": head, "rows": rows}) => lib_plankton.string.coin( "(unhandled)", { } ), }, { "fallback": (object) => lib_plankton.string.coin( "(unhandled)", { } ), } ); } /** * @implementation */ public render_object( object : type_object ) : string { return this.render_object_internal(object); } /** * @implementation */ public render_document( document : type_document ) : string { return this.render_object_internal( document.content_main, { } ); } } /** */ output_kind_register( "markdown", (data, sub) => ( new type_output_markdown( { } ) ) );