diff options
author | Marcin Aman <maman@virtuslab.com> | 2020-08-19 20:09:12 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-28 15:37:55 +0200 |
commit | de809e8076b3cde06dc29328298112ed4a7026b3 (patch) | |
tree | 8773b5f9d0d148d366cd7f250c268716b156b55d /plugins/javadoc/src | |
parent | e64cb9bfbef093bcc4046a5081393f3c9778b42a (diff) | |
download | dokka-de809e8076b3cde06dc29328298112ed4a7026b3.tar.gz dokka-de809e8076b3cde06dc29328298112ed4a7026b3.tar.bz2 dokka-de809e8076b3cde06dc29328298112ed4a7026b3.zip |
Draft for improving code formatting #1346
Diffstat (limited to 'plugins/javadoc/src')
-rw-r--r-- | plugins/javadoc/src/main/kotlin/org/jetbrains/dokka/javadoc/renderer/JavadocContentToHtmlTranslator.kt | 15 |
1 files changed, 8 insertions, 7 deletions
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 -> "<br>" @@ -44,16 +44,17 @@ internal class JavadocContentToHtmlTranslator( private fun htmlForParagraph(nodes: List<ContentNode>, relative: PageNode?) = "<p>${htmlForContentNodes(nodes, relative)}</p>" - private fun htmlForCode(code: List<ContentNode>, 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 "<br>" is ContentDRILink -> buildLinkFromNode(node, relative) is ContentResolvedLink -> buildLinkFromNode(node, relative) - is ContentCode -> node.children.joinToString("") { nodeToText(it) } + is ContentCodeBlock -> "<pre><code>${node.children.joinToString("") { nodeToText(it, insidePre = true) }}</code></pre>" + is ContentCodeInline -> "<code>${node.children.joinToString("") { nodeToText(it) }}</code>" else -> run { context.logger.error("Cannot cast $node as ContentText!"); "" } } - return code.map(::nodeToText).joinToString("<br>", """<code>""", "</code>") { it } + return nodeToText(code) } private fun htmlForList(elements: List<ContentNode>, relative: PageNode?) = |