From 8a439143252026b0bda1d1f23c688c861ae0c528 Mon Sep 17 00:00:00 2001 From: Paweł Marks Date: Fri, 28 Feb 2020 15:33:54 +0100 Subject: Adds group wraping --- plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt | 5 ++++- plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'plugins/base') diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt index 9c22c879..960a39fd 100644 --- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt @@ -32,10 +32,13 @@ abstract class DefaultRenderer( abstract fun buildPage(page: ContentPage, content: (T, ContentPage) -> Unit): String abstract fun buildError(node: ContentNode) - open fun T.buildGroup(node: ContentGroup, pageContext: ContentPage) { + open fun T.buildGroup(node: ContentGroup, pageContext: ContentPage) = wrapGroup(node, pageContext) { node.children.forEach { it.build(this, pageContext) } } + open fun T.wrapGroup(node: ContentGroup, pageContext: ContentPage, childrenCallback: T.() -> Unit) = + childrenCallback() + open fun T.buildLinkText(nodes: List, pageContext: ContentPage) { nodes.forEach { it.build(this, pageContext) } } diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 8bf00043..dcd65c21 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -23,6 +23,16 @@ open class HtmlRenderer( StyleAndScriptsAppender ) + override fun FlowContent.wrapGroup( + node: ContentGroup, + pageContext: ContentPage, + childrenCallback: FlowContent.() -> Unit + ) = when { + node.style.contains(TextStyle.Paragraph) -> p { childrenCallback() } + node.style.contains(TextStyle.Block) -> div { childrenCallback() } + else -> childrenCallback() + } + override fun FlowContent.buildList(node: ContentList, pageContext: ContentPage) = if (node.ordered) ol { buildListItems(node.children, pageContext) -- cgit