From 92075236fb1356fe6023edff1e43fe3125b76c18 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Tue, 10 Feb 2015 18:11:15 +0100 Subject: fix handling of triple backticks --- src/Kotlin/ContentBuilder.kt | 5 +++++ src/Kotlin/DocumentationBuilder.kt | 7 ++++++- test/data/format/tripleBackticks.html | 18 ++++++++++++++++++ test/data/format/tripleBackticks.kt | 7 +++++++ test/src/format/HtmlFormatTest.kt | 6 ++++++ 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/data/format/tripleBackticks.html create mode 100644 test/data/format/tripleBackticks.kt diff --git a/src/Kotlin/ContentBuilder.kt b/src/Kotlin/ContentBuilder.kt index abe24917..60b0e9e9 100644 --- a/src/Kotlin/ContentBuilder.kt +++ b/src/Kotlin/ContentBuilder.kt @@ -95,6 +95,11 @@ public fun DocumentationBuilder.buildContentTo(tree: MarkdownNode, target: Conte processChildren() parent.append(nodeStack.pop()) } + MarkdownTokenTypes.CODE -> { + val block = ContentBlockCode() + block.append(ContentText(node.text)) + parent.append(block) + } MarkdownElementTypes.PARAGRAPH -> { nodeStack.push(ContentParagraph()) processChildren() diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index c9c45214..d166fa82 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -45,7 +45,12 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati if (kdoc == null) { return Content.Empty } - val tree = parseMarkdown(kdoc.getContent()) + var kdocText = kdoc.getContent() + // workaround for code fence parsing problem in IJ markdown parser + if (kdocText.endsWith("```") || kdocText.endsWith("~~~")) { + kdocText += "\n" + } + val tree = parseMarkdown(kdocText) //println(tree.toTestString()) val content = buildContent(tree) if (kdoc is KDocSection) { diff --git a/test/data/format/tripleBackticks.html b/test/data/format/tripleBackticks.html new file mode 100644 index 00000000..ad4251a9 --- /dev/null +++ b/test/data/format/tripleBackticks.html @@ -0,0 +1,18 @@ + + +test / f + + +test /  / f
+
+

f

+
fun f(): Unit

Description

+
+
+

Description

+

+code sample
+

+
+ + diff --git a/test/data/format/tripleBackticks.kt b/test/data/format/tripleBackticks.kt new file mode 100644 index 00000000..54dfa6d5 --- /dev/null +++ b/test/data/format/tripleBackticks.kt @@ -0,0 +1,7 @@ +/** + * Description + * ``` + * code sample + * ``` + */ +fun f() {} diff --git a/test/src/format/HtmlFormatTest.kt b/test/src/format/HtmlFormatTest.kt index e180a86c..7dfa80be 100644 --- a/test/src/format/HtmlFormatTest.kt +++ b/test/src/format/HtmlFormatTest.kt @@ -57,4 +57,10 @@ public class HtmlFormatTest { htmlService.appendNodes(tempLocation, output, model.members.single().members) } } + + Test fun tripleBackticks() { + verifyOutput("test/data/format/tripleBackticks.kt", ".html") { model, output -> + htmlService.appendNodes(tempLocation, output, model.members.single().members) + } + } } -- cgit