diff options
author | Paweł Marks <pmarks@virtuslab.com> | 2020-03-03 23:38:23 +0100 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-03-04 14:28:14 +0100 |
commit | d08591dea709917553c0d6de024820bb29b328fb (patch) | |
tree | 5844f98629d654ffb4fbaa0471484b149b487361 /plugins/base/src/main/kotlin/renderers/html | |
parent | 156396f7520b3ac45e37068d6b72087008322cbe (diff) | |
download | dokka-d08591dea709917553c0d6de024820bb29b328fb.tar.gz dokka-d08591dea709917553c0d6de024820bb29b328fb.tar.bz2 dokka-d08591dea709917553c0d6de024820bb29b328fb.zip |
Platform dependent hints for renderer
Diffstat (limited to 'plugins/base/src/main/kotlin/renderers/html')
-rw-r--r-- | plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index dcd65c21..0dd3b34b 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -33,24 +33,46 @@ open class HtmlRenderer( else -> childrenCallback() } - override fun FlowContent.buildList(node: ContentList, pageContext: ContentPage) = - if (node.ordered) ol { - buildListItems(node.children, pageContext) - } - else ul { - buildListItems(node.children, pageContext) - } + override fun FlowContent.buildPlatformDependent(content: PlatformHintedContent, pageContext: ContentPage) { + val distinct = content.platforms.map { + it to createHTML(prettyPrint = false).div { + buildContentNode(content.inner, pageContext, it) + }.drop(5).dropLast(6) // TODO: Find a way to do it without arbitrary trims + }.groupBy(Pair<PlatformData, String>::second, Pair<PlatformData, String>::first) + + if (distinct.size == 1) + consumer.onTagContentUnsafe { +distinct.keys.single() } + else + distinct.forEach { text, platforms -> + consumer.onTagContentUnsafe { +platforms.joinToString(prefix = "$text [", postfix = "]") { it.name } } + } + } + + override fun FlowContent.buildList( + node: ContentList, + pageContext: ContentPage, + platformRestriction: PlatformData? + ) = if (node.ordered) ol { buildListItems(node.children, pageContext, platformRestriction) } + else ul { buildListItems(node.children, pageContext, platformRestriction) } - open fun OL.buildListItems(items: List<ContentNode>, pageContext: ContentPage) { + open fun OL.buildListItems( + items: List<ContentNode>, + pageContext: ContentPage, + platformRestriction: PlatformData? = null + ) { items.forEach { if (it is ContentList) buildList(it, pageContext) else - li { it.build(this, pageContext) } + li { it.build(this, pageContext, platformRestriction) } } } - open fun UL.buildListItems(items: List<ContentNode>, pageContext: ContentPage) { + open fun UL.buildListItems( + items: List<ContentNode>, + pageContext: ContentPage, + platformRestriction: PlatformData? = null + ) { items.forEach { if (it is ContentList) buildList(it, pageContext) @@ -73,14 +95,18 @@ open class HtmlRenderer( } } - override fun FlowContent.buildTable(node: ContentTable, pageContext: ContentPage) { + override fun FlowContent.buildTable( + node: ContentTable, + pageContext: ContentPage, + platformRestriction: PlatformData? + ) { table { thead { node.header.forEach { tr { it.children.forEach { th { - it.build(this@table, pageContext) + it.build(this@table, pageContext, platformRestriction) } } } @@ -91,7 +117,7 @@ open class HtmlRenderer( tr { it.children.forEach { td { - it.build(this, pageContext) + it.build(this, pageContext, platformRestriction) } } } @@ -141,7 +167,11 @@ open class HtmlRenderer( override fun FlowContent.buildLink(address: String, content: FlowContent.() -> Unit) = a(href = address, block = content) - override fun FlowContent.buildCode(code: List<ContentNode>, language: String, pageContext: ContentPage) { + override fun FlowContent.buildCode( + code: List<ContentNode>, + language: String, + pageContext: ContentPage + ) { buildNewLine() code.forEach { +((it as? ContentText)?.text ?: run { context.logger.error("Cannot cast $it as ContentText!"); "" }) |