aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/renderers
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src/main/kotlin/renderers')
-rw-r--r--plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt4
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt65
2 files changed, 40 insertions, 29 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
index a089f8f5..1684f819 100644
--- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt
@@ -23,7 +23,7 @@ abstract class DefaultRenderer<T>(
protected open val preprocessors: Iterable<PageTransformer> = emptyList()
- abstract fun T.buildHeader(level: Int, content: T.() -> Unit)
+ abstract fun T.buildHeader(level: Int, node: ContentHeader, content: T.() -> Unit)
abstract fun T.buildLink(address: String, content: T.() -> Unit)
abstract fun T.buildList(
node: ContentList,
@@ -78,7 +78,7 @@ abstract class DefaultRenderer<T>(
pageContext: ContentPage,
sourceSetRestriction: Set<SourceSetData>? = null
) {
- buildHeader(node.level) { node.children.forEach { it.build(this, pageContext, sourceSetRestriction) } }
+ buildHeader(node.level, node) { node.children.forEach { it.build(this, pageContext, sourceSetRestriction) } }
}
open fun ContentNode.build(
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
index 64c03bc7..388ee72f 100644
--- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -197,29 +197,31 @@ open class HtmlRenderer(
.filter { sourceSetRestriction == null || it.sourceSets.any { s -> s in sourceSetRestriction } }
.takeIf { it.isNotEmpty() }
?.let {
- div(classes = "table-row") {
- it.filterIsInstance<ContentLink>().takeIf { it.isNotEmpty() }?.let {
- div("main-subrow " + node.style.joinToString(" ")) {
- it.filter { sourceSetRestriction == null || it.sourceSets.any { s -> s in sourceSetRestriction } }
- .forEach {
- it.build(this, pageContext, sourceSetRestriction)
- if (ContentKind.shouldBePlatformTagged(node.dci.kind) && (node.sourceSets.size == 1))
- createPlatformTags(node)
- }
+ withAnchor(node.dci.dri.first().toString()) {
+ div(classes = "table-row") {
+ it.filterIsInstance<ContentLink>().takeIf { it.isNotEmpty() }?.let {
+ div("main-subrow " + node.style.joinToString(" ")) {
+ it.filter { sourceSetRestriction == null || it.sourceSets.any { s -> s in sourceSetRestriction } }
+ .forEach {
+ it.build(this, pageContext, sourceSetRestriction)
+ if (ContentKind.shouldBePlatformTagged(node.dci.kind) && (node.sourceSets.size == 1))
+ createPlatformTags(node)
+ }
+ }
}
- }
- it.filter { it !is ContentLink }.takeIf { it.isNotEmpty() }?.let {
- div("platform-dependent-row keyValue") {
- val title = it.filter { it.style.contains(ContentStyle.RowTitle) }
- div {
- title.forEach {
- it.build(this, pageContext, sourceSetRestriction)
+ it.filter { it !is ContentLink }.takeIf { it.isNotEmpty() }?.let {
+ div("platform-dependent-row keyValue") {
+ val title = it.filter { it.style.contains(ContentStyle.RowTitle) }
+ div {
+ title.forEach {
+ it.build(this, pageContext, sourceSetRestriction)
+ }
}
- }
- div("title") {
- (it - title).forEach {
- it.build(this, pageContext, sourceSetRestriction)
+ div("title") {
+ (it - title).forEach {
+ it.build(this, pageContext, sourceSetRestriction)
+ }
}
}
}
@@ -255,17 +257,26 @@ open class HtmlRenderer(
}
- override fun FlowContent.buildHeader(level: Int, content: FlowContent.() -> Unit) {
+ override fun FlowContent.buildHeader(level: Int, node: ContentHeader, content: FlowContent.() -> Unit) {
+ val anchor = node.extra[SimpleAttr.SimpleAttrKey("anchor")]?.extraValue
when (level) {
- 1 -> h1(block = content)
- 2 -> h2(block = content)
- 3 -> h3(block = content)
- 4 -> h4(block = content)
- 5 -> h5(block = content)
- else -> h6(block = content)
+ 1 -> h1() { withAnchor(anchor, content) }
+ 2 -> h2() { withAnchor(anchor, content) }
+ 3 -> h3() { withAnchor(anchor, content) }
+ 4 -> h4() { withAnchor(anchor, content) }
+ 5 -> h5() { withAnchor(anchor, content) }
+ else -> h6() { withAnchor(anchor, content) }
}
}
+ private fun FlowContent.withAnchor(anchorName: String?, content: FlowContent.() -> Unit) {
+ a {
+ anchorName?.let { attributes["name"] = it }
+ }
+ content()
+ }
+
+
override fun FlowContent.buildNavigation(page: PageNode) =
div(classes = "breadcrumbs") {
locationProvider.ancestors(page).asReversed().forEach { node ->