From 4fa9524e52d8ff422bb355336e3810ab28ae135c Mon Sep 17 00:00:00 2001 From: vmishenev Date: Wed, 25 Aug 2021 17:14:31 +0300 Subject: Manual highlighting webhelp (#2079) * Add manual code highlighting * Fix test * Add kotlinAsJava highlighting * Add runtime highlighting via Prism * Add copy-button for code block * Add tests and refactor * Replace `
` for prism.js * Parse trivial default values Co-authored-by: Marcin Aman --- .../base/src/main/kotlin/renderers/html/HtmlRenderer.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt') diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 3cf914ce..31753332 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -677,13 +677,15 @@ open class HtmlRenderer( pageContext: ContentPage ) { div("sample-container") { - val stylesWithBlock = code.style + TextStyle.Block - code(stylesWithBlock.joinToString(" ") { it.toString().toLowerCase() }) { - attributes["theme"] = "idea" - pre { + val codeLang = "lang-" + code.language.ifEmpty { "kotlin" } + val stylesWithBlock = code.style + TextStyle.Block + codeLang + pre { + code(stylesWithBlock.joinToString(" ") { it.toString().toLowerCase() }) { + attributes["theme"] = "idea" code.children.forEach { buildContentNode(it, pageContext) } } } + copyButton() } } @@ -691,7 +693,9 @@ open class HtmlRenderer( code: ContentCodeInline, pageContext: ContentPage ) { - code { + val codeLang = "lang-" + code.language.ifEmpty { "kotlin" } + val stylesWithBlock = code.style + codeLang + code(stylesWithBlock.joinToString(" ") { it.toString().toLowerCase() }) { code.children.forEach { buildContentNode(it, pageContext) } } } @@ -725,6 +729,7 @@ open class HtmlRenderer( TextStyle.Italic -> i { body() } TextStyle.Strikethrough -> strike { body() } TextStyle.Strong -> strong { body() } + is TokenStyle -> span("token " + styleToApply.toString().toLowerCase()) { body() } else -> body() } } -- cgit