From e9ab5d88150323067672661d37f8d7f8b146311d Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Fri, 27 Oct 2017 03:46:49 +0300 Subject: #228: Correctly render multiline indented code blocks Fix #228 --- core/src/main/kotlin/Kotlin/ContentBuilder.kt | 9 ++++++--- core/src/test/kotlin/format/HtmlFormatTest.kt | 4 ++++ core/src/test/kotlin/format/MarkdownFormatTest.kt | 4 ++++ core/testdata/format/indentedCodeBlock.html | 17 +++++++++++++++++ core/testdata/format/indentedCodeBlock.kt | 10 ++++++++++ core/testdata/format/indentedCodeBlock.md | 14 ++++++++++++++ 6 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 core/testdata/format/indentedCodeBlock.html create mode 100644 core/testdata/format/indentedCodeBlock.kt create mode 100644 core/testdata/format/indentedCodeBlock.md diff --git a/core/src/main/kotlin/Kotlin/ContentBuilder.kt b/core/src/main/kotlin/Kotlin/ContentBuilder.kt index 771bc44b..c60625a4 100644 --- a/core/src/main/kotlin/Kotlin/ContentBuilder.kt +++ b/core/src/main/kotlin/Kotlin/ContentBuilder.kt @@ -110,9 +110,12 @@ fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: LinkR } MarkdownTokenTypes.CODE_LINE -> { - val block = ContentBlockCode() - block.append(ContentText(node.text)) - parent.append(block) + val content = ContentText(node.text) + if (parent is ContentBlockCode) { + parent.append(content) + } else { + parent.append(ContentBlockCode().apply { append(content) }) + } } MarkdownTokenTypes.TEXT -> { diff --git a/core/src/test/kotlin/format/HtmlFormatTest.kt b/core/src/test/kotlin/format/HtmlFormatTest.kt index 4fe4f6ab..01e4559e 100644 --- a/core/src/test/kotlin/format/HtmlFormatTest.kt +++ b/core/src/test/kotlin/format/HtmlFormatTest.kt @@ -146,6 +146,10 @@ class HtmlFormatTest { verifyHtmlNode("blankLineInsideCodeBlock") } + @Test fun indentedCodeBlock() { + verifyHtmlNode("indentedCodeBlock") + } + private fun verifyHtmlNode(fileName: String, withKotlinRuntime: Boolean = false) { verifyHtmlNodes(fileName, withKotlinRuntime) { model -> model.members.single().members } } diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index 48b06d6e..fbebfbfd 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -376,6 +376,10 @@ class MarkdownFormatTest { verifyMarkdownPackage("newlineInTableCell") } + @Test fun indentedCodeBlock() { + verifyMarkdownNode("indentedCodeBlock") + } + private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") val options = DocumentationOptions("", "html", generateIndexPages = false, noStdlibLink = true) diff --git a/core/testdata/format/indentedCodeBlock.html b/core/testdata/format/indentedCodeBlock.html new file mode 100644 index 00000000..1ccf800a --- /dev/null +++ b/core/testdata/format/indentedCodeBlock.html @@ -0,0 +1,17 @@ + + + +foo - test + + +test / foo
+
+

foo

+ +fun foo(): Unit +

Create a new Foo value as follows:

+
    val foo = Foo.create {
+        type { "ABC" }
+    }
+ + diff --git a/core/testdata/format/indentedCodeBlock.kt b/core/testdata/format/indentedCodeBlock.kt new file mode 100644 index 00000000..19c5365b --- /dev/null +++ b/core/testdata/format/indentedCodeBlock.kt @@ -0,0 +1,10 @@ +/** + * Create a new Foo value as follows: + * + * val foo = Foo.create { + * type { "ABC" } + * } + */ +fun foo() { + +} \ No newline at end of file diff --git a/core/testdata/format/indentedCodeBlock.md b/core/testdata/format/indentedCodeBlock.md new file mode 100644 index 00000000..515bfee3 --- /dev/null +++ b/core/testdata/format/indentedCodeBlock.md @@ -0,0 +1,14 @@ +[test](test/index) / [foo](test/foo) + +# foo + +`fun foo(): Unit` + +Create a new Foo value as follows: + +``` + val foo = Foo.create { + type { "ABC" } + } +``` + -- cgit