aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src')
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt22
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/Tags.kt12
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/command/consumers/ReplaceVersionsConsumer.kt2
-rw-r--r--plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt7
4 files changed, 29 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 4dd020ce..0ba085cd 100644
--- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -23,6 +23,8 @@ import org.jetbrains.dokka.utilities.htmlEscape
import org.jetbrains.kotlin.utils.addIfNotNull
import java.net.URI
+internal const val TEMPLATE_REPLACEMENT: String = "###"
+
open class HtmlRenderer(
context: DokkaContext
) : DefaultRenderer<FlowContent>(context) {
@@ -779,11 +781,11 @@ open class HtmlRenderer(
head {
meta(name = "viewport", content = "width=device-width, initial-scale=1", charset = "UTF-8")
title(page.name)
- templateCommand(PathToRootSubstitutionCommand("###", default = pathToRoot)) {
- link(href = "###images/logo-icon.svg", rel = "icon", type = "image/svg")
+ templateCommandAsHtmlComment(PathToRootSubstitutionCommand(TEMPLATE_REPLACEMENT, default = pathToRoot)) {
+ link(href = "${TEMPLATE_REPLACEMENT}images/logo-icon.svg", rel = "icon", type = "image/svg")
}
- templateCommand(PathToRootSubstitutionCommand("###", default = pathToRoot)) {
- script { unsafe { +"""var pathToRoot = "###";""" } }
+ templateCommandAsHtmlComment(PathToRootSubstitutionCommand(TEMPLATE_REPLACEMENT, default = pathToRoot)) {
+ script { unsafe { +"""var pathToRoot = "$TEMPLATE_REPLACEMENT";""" } }
}
// This script doesn't need to be there but it is nice to have since app in dark mode doesn't 'blink' (class is added before it is rendered)
script {
@@ -804,10 +806,10 @@ open class HtmlRenderer(
rel = LinkRel.stylesheet,
href = it
)
- else templateCommand(PathToRootSubstitutionCommand("###", default = pathToRoot)) {
+ else templateCommandAsHtmlComment(PathToRootSubstitutionCommand(TEMPLATE_REPLACEMENT, default = pathToRoot)) {
link(
rel = LinkRel.stylesheet,
- href = "###$it"
+ href = TEMPLATE_REPLACEMENT + it
)
}
it.substringBefore('?').substringAfterLast('.') == "js" ->
@@ -816,10 +818,10 @@ open class HtmlRenderer(
src = it
) {
async = true
- } else templateCommand(PathToRootSubstitutionCommand("###", default = pathToRoot)) {
+ } else templateCommandAsHtmlComment(PathToRootSubstitutionCommand(TEMPLATE_REPLACEMENT, default = pathToRoot)) {
script(
type = ScriptType.textJavaScript,
- src = "###$it"
+ src = TEMPLATE_REPLACEMENT + it
) {
if (it == "scripts/main.js")
defer = true
@@ -828,8 +830,8 @@ open class HtmlRenderer(
}
}
it.isImage() -> if (it.isAbsolute) link(href = it)
- else templateCommand(PathToRootSubstitutionCommand("###", default = pathToRoot)) {
- link(href = "###$it")
+ else templateCommandAsHtmlComment(PathToRootSubstitutionCommand(TEMPLATE_REPLACEMENT, default = pathToRoot)) {
+ link(href = TEMPLATE_REPLACEMENT + it)
}
else -> unsafe { +it }
}
diff --git a/plugins/base/src/main/kotlin/renderers/html/Tags.kt b/plugins/base/src/main/kotlin/renderers/html/Tags.kt
index a23c7bf1..94a53c27 100644
--- a/plugins/base/src/main/kotlin/renderers/html/Tags.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/Tags.kt
@@ -26,6 +26,18 @@ inline fun FlowOrPhrasingContent.strike(classes : String? = null, crossinline bl
open class STRIKE(initialAttributes: Map<String, String>, override val consumer: TagConsumer<*>) :
HTMLTag("strike", consumer, initialAttributes, null, false, false), HtmlBlockInlineTag
+const val TEMPLATE_COMMAND_SEPARATOR = ":"
+const val TEMPLATE_COMMAND_BEGIN_BORDER = "[+]cmd"
+const val TEMPLATE_COMMAND_END_BORDER = "[-]cmd"
+
+fun FlowOrMetaDataContent.templateCommandAsHtmlComment(data: Command, block: FlowOrMetaDataContent.() -> Unit = {}): Unit =
+ (consumer as? ImmediateResolutionTagConsumer)?.processCommand(data, block)
+ ?: let{
+ comment( "$TEMPLATE_COMMAND_BEGIN_BORDER$TEMPLATE_COMMAND_SEPARATOR${toJsonString(data)}")
+ block()
+ comment(TEMPLATE_COMMAND_END_BORDER)
+ }
+
fun FlowOrMetaDataContent.templateCommand(data: Command, block: TemplateBlock = {}): Unit =
(consumer as? ImmediateResolutionTagConsumer)?.processCommand(data, block)
?: TemplateCommand(attributesMapOf("data", toJsonString(data)), consumer).visit(block)
diff --git a/plugins/base/src/main/kotlin/renderers/html/command/consumers/ReplaceVersionsConsumer.kt b/plugins/base/src/main/kotlin/renderers/html/command/consumers/ReplaceVersionsConsumer.kt
index ea8cde0f..bbc33164 100644
--- a/plugins/base/src/main/kotlin/renderers/html/command/consumers/ReplaceVersionsConsumer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/command/consumers/ReplaceVersionsConsumer.kt
@@ -19,7 +19,7 @@ class ReplaceVersionsConsumer(private val context: DokkaContext) : ImmediateHtml
}
override fun <R> processCommandAndFinalize(command: Command, block: TemplateBlock, tagConsumer: ImmediateResolutionTagConsumer<R>): R {
- PathToRootConsumer.processCommand(command, block, tagConsumer)
+ processCommand(command, block, tagConsumer)
return tagConsumer.finalize()
}
} \ No newline at end of file
diff --git a/plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt b/plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt
index 9b010b56..fb9ec10e 100644
--- a/plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt
+++ b/plugins/base/src/test/kotlin/resourceLinks/ResourceLinksTest.kt
@@ -4,10 +4,11 @@ import org.jetbrains.dokka.DokkaConfiguration
import org.jetbrains.dokka.PluginConfigurationImpl
import org.jetbrains.dokka.base.DokkaBase
import org.jetbrains.dokka.base.DokkaBaseConfiguration
+import org.jetbrains.dokka.base.renderers.html.TEMPLATE_REPLACEMENT
import org.jetbrains.dokka.base.templating.toJsonString
+import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaPlugin
-import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.transformers.pages.PageTransformer
import org.jsoup.Jsoup
import org.junit.jupiter.api.Test
@@ -125,11 +126,11 @@ class ResourceLinksTest : BaseAbstractTest() {
if (isMultiModule) {
Jsoup
.parse(writerPlugin.writer.contents["example.html"])
- .body()
+ .head()
.select("link, script")
.let {
listOf("styles/customStyle.css").forEach { r ->
- assert(it.`is`("[href=###$r]"))
+ assert(it.`is`("[href=$TEMPLATE_REPLACEMENT$r]"))
}
}
} else {