From fbee5a49ee4c21bf0f31362bf1f9af46adba7a44 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Thu, 1 Oct 2020 09:59:52 +0200 Subject: Escape urls in anchors --- plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'plugins/base/src/main/kotlin/renderers') diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 01f4ed6d..3eb1c030 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -21,6 +21,7 @@ import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.query import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.utilities.htmlEscape +import org.jetbrains.dokka.utilities.urlEncoded import java.io.File import java.net.URI @@ -365,7 +366,7 @@ open class HtmlRenderer( .filter { sourceSetRestriction == null || it.sourceSets.any { s -> s in sourceSetRestriction } } .takeIf { it.isNotEmpty() } ?.let { - val anchorName = node.dci.dri.first().toString() + val anchorName = node.dci.dri.first().anchor withAnchor(anchorName) { div(classes = "table-row") { if (!style.contains(MultimoduleTable)) { @@ -498,7 +499,7 @@ open class HtmlRenderer( override fun FlowContent.buildHeader(level: Int, node: ContentHeader, content: FlowContent.() -> Unit) { - val anchor = node.extra[SimpleAttr.SimpleAttrKey("anchor")]?.extraValue + val anchor = node.extra[SimpleAttr.SimpleAttrKey("anchor")]?.extraValue?.urlEncoded() val classes = node.style.joinToString { it.toString() }.toLowerCase() when (level) { 1 -> h1(classes = classes) { withAnchor(anchor, content) } @@ -759,3 +760,6 @@ private val PageNode.isNavigable: Boolean get() = this !is RendererSpecificPage || strategy != RenderingStrategy.DoNothing fun PropertyContainer.extraHtmlAttributes() = allOfType() + +private val DRI.anchor: String + get() = toString().urlEncoded() -- cgit