From 4f4b86b873b7676979d3258030fdfc382e22a06b Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Tue, 16 May 2017 20:44:28 +0300 Subject: Fix invalid line breaks in table cells for markdown formats #KT-16234 fixed --- core/src/main/kotlin/Formats/MarkdownFormatService.kt | 6 +++++- core/src/test/kotlin/format/MarkdownFormatTest.kt | 4 ++++ core/testdata/format/newlineInTableCell.kt | 6 ++++++ core/testdata/format/newlineInTableCell.package.md | 8 ++++++++ 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 core/testdata/format/newlineInTableCell.kt create mode 100644 core/testdata/format/newlineInTableCell.package.md diff --git a/core/src/main/kotlin/Formats/MarkdownFormatService.kt b/core/src/main/kotlin/Formats/MarkdownFormatService.kt index f7c17401..a7c18a28 100644 --- a/core/src/main/kotlin/Formats/MarkdownFormatService.kt +++ b/core/src/main/kotlin/Formats/MarkdownFormatService.kt @@ -87,7 +87,11 @@ open class MarkdownOutputBuilder(to: StringBuilder, maxBackticksInCodeBlock = maxBackticksInCodeBlock.coerceAtLeast(longestBackTickRun) } else { - to.append(text.htmlEscape()) + if (text == "\n" && inTableCell) { + to.append(" ") + } else { + to.append(text.htmlEscape()) + } } } diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt index 52a62656..e3f4bae7 100644 --- a/core/src/test/kotlin/format/MarkdownFormatTest.kt +++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt @@ -364,6 +364,10 @@ class MarkdownFormatTest { verifyMarkdownNode("nestedLists") } + @Test fun newlineInTableCell() { + verifyMarkdownPackage("newlineInTableCell") + } + private fun buildMultiplePlatforms(path: String): DocumentationModule { val module = DocumentationModule("test") val options = DocumentationOptions("", "html", generateIndexPages = false, noStdlibLink = true) diff --git a/core/testdata/format/newlineInTableCell.kt b/core/testdata/format/newlineInTableCell.kt new file mode 100644 index 00000000..3e0616f0 --- /dev/null +++ b/core/testdata/format/newlineInTableCell.kt @@ -0,0 +1,6 @@ +/** + * There is `long long int` story + * full of + * new lines + */ +class A \ No newline at end of file diff --git a/core/testdata/format/newlineInTableCell.package.md b/core/testdata/format/newlineInTableCell.package.md new file mode 100644 index 00000000..4b3875ba --- /dev/null +++ b/core/testdata/format/newlineInTableCell.package.md @@ -0,0 +1,8 @@ +[test](test/index) + +## Package <root> + +### Types + +| [A](test/-a/index) | `class A`
There is `long long int` story full of new lines | + -- cgit