diff options
Diffstat (limited to 'plugins/base/src/main')
3 files changed, 25 insertions, 11 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 |