diff options
author | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2019-02-25 21:34:14 +0300 |
---|---|---|
committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2019-02-25 21:42:29 +0300 |
commit | 3fc4102597437dbf217c96b70000cac5fb9b591b (patch) | |
tree | 515ad5c61e277755cb230f96b54380e8d4d1ea8f /core | |
parent | f4aeac0a974837a18d0c18d42bd5980dffa043fb (diff) | |
download | dokka-3fc4102597437dbf217c96b70000cac5fb9b591b.tar.gz dokka-3fc4102597437dbf217c96b70000cac5fb9b591b.tar.bz2 dokka-3fc4102597437dbf217c96b70000cac5fb9b591b.zip |
Rework logic to avoid loosing tags inside pre
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/kotlin/Java/JavadocParser.kt | 26 | ||||
-rw-r--r-- | core/testdata/format/javadocHtml.java | 12 | ||||
-rw-r--r-- | core/testdata/format/javadocHtml.md | 16 |
3 files changed, 40 insertions, 14 deletions
diff --git a/core/src/main/kotlin/Java/JavadocParser.kt b/core/src/main/kotlin/Java/JavadocParser.kt index 3411b5c7..70af73f9 100644 --- a/core/src/main/kotlin/Java/JavadocParser.kt +++ b/core/src/main/kotlin/Java/JavadocParser.kt @@ -155,32 +155,30 @@ class JavadocParser( return htmlBuilder.toString().trim() } - private fun convertHtmlNode(node: Node): ContentNode? { + private fun convertHtmlNode(node: Node, insidePre: Boolean = false): ContentNode? { if (node is TextNode) { - return ContentText(node.text()) + val text = if (insidePre) node.wholeText else node.text() + return ContentText(text) } else if (node is Element) { - val childBlock = createBlock(node) - if (childBlock is ContentBlockCode) { - childBlock.append(ContentText(node.text())) - } else { - node.childNodes().forEach { - val child = convertHtmlNode(it) - if (child != null) { - childBlock.append(child) - } + val childBlock = createBlock(node, insidePre) + + node.childNodes().forEach { + val child = convertHtmlNode(it, insidePre || childBlock is ContentBlockCode) + if (child != null) { + childBlock.append(child) } - return (childBlock) } + return childBlock } return null } - private fun createBlock(element: Element): ContentBlock = when (element.tagName()) { + private fun createBlock(element: Element, insidePre: Boolean): ContentBlock = when (element.tagName()) { "p" -> ContentParagraph() "b", "strong" -> ContentStrong() "i", "em" -> ContentEmphasis() "s", "del" -> ContentStrikethrough() - "code" -> ContentCode() + "code" -> if (insidePre) ContentBlock() else ContentCode() "pre" -> ContentBlockCode() "ul" -> ContentUnorderedList() "ol" -> ContentOrderedList() diff --git a/core/testdata/format/javadocHtml.java b/core/testdata/format/javadocHtml.java index 622116b2..9e77402e 100644 --- a/core/testdata/format/javadocHtml.java +++ b/core/testdata/format/javadocHtml.java @@ -9,6 +9,18 @@ * <code>Code</code> * <pre>Block code</pre> * <ul><li>List Item</li></ul> + * <pre> + * with( some ) { + * multi = lines + * sample() + * } + * </pre> + * <pre> + * {@code + * with (some) { <code> } + * } + * </pre> + * */ public class C { } diff --git a/core/testdata/format/javadocHtml.md b/core/testdata/format/javadocHtml.md index 9b501fcb..77f6c829 100644 --- a/core/testdata/format/javadocHtml.md +++ b/core/testdata/format/javadocHtml.md @@ -16,6 +16,22 @@ Block code * List Item + +``` + + with( some ) { + multi = lines + sample() + } + ``` + + + +``` +with (some) { <code> } + + ``` + ### Constructors | [<init>](-init-.md) | `C()`<br>**Bold** **Strong** *Italic* *Emphasized* | |