From de809e8076b3cde06dc29328298112ed4a7026b3 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Wed, 19 Aug 2020 20:09:12 +0200 Subject: Draft for improving code formatting #1346 --- .../javadoc/renderer/JavadocContentToHtmlTranslator.kt | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'plugins/javadoc/src/main') diff --git a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToHtmlTranslator.kt b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToHtmlTranslator.kt index 413b6387..7f179f75 100644 --- a/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToHtmlTranslator.kt +++ b/plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToHtmlTranslator.kt @@ -20,7 +20,7 @@ internal class JavadocContentToHtmlTranslator( is ContentText -> htmlForText(node) is ContentDRILink -> buildLinkFromNode(node, relative) is ContentResolvedLink -> buildLinkFromNode(node, relative) - is ContentCode -> htmlForCode(node.children, relative) + is ContentCode -> htmlForCode(node, relative) is ContentList -> htmlForList(node.children, relative) is JavadocSignatureContentNode -> htmlForSignature(node, relative) is ContentBreakLine -> "
" @@ -44,16 +44,17 @@ internal class JavadocContentToHtmlTranslator( private fun htmlForParagraph(nodes: List, relative: PageNode?) = "

${htmlForContentNodes(nodes, relative)}

" - private fun htmlForCode(code: List, relative: PageNode?): String { - fun nodeToText(node: ContentNode): String = when (node) { - is ContentText -> node.text - is ContentBreakLine -> "" + private fun htmlForCode(code: ContentCode, relative: PageNode?): String { + fun nodeToText(node: ContentNode, insidePre: Boolean = false): String = when (node) { + is ContentText -> node.text.htmlEscape() + is ContentBreakLine -> if(insidePre) "\n" else "
" is ContentDRILink -> buildLinkFromNode(node, relative) is ContentResolvedLink -> buildLinkFromNode(node, relative) - is ContentCode -> node.children.joinToString("") { nodeToText(it) } + is ContentCodeBlock -> "
${node.children.joinToString("") { nodeToText(it, insidePre = true) }}
" + is ContentCodeInline -> "${node.children.joinToString("") { nodeToText(it) }}" else -> run { context.logger.error("Cannot cast $node as ContentText!"); "" } } - return code.map(::nodeToText).joinToString("
", """""", "") { it } + return nodeToText(code) } private fun htmlForList(elements: List, relative: PageNode?) = -- cgit