From 216d548e9837222c4e0df38aea3345e07c7b9d42 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Wed, 6 Jul 2016 15:07:44 +0200 Subject: [PATCH] fix rendering of code blocks escaped with multiple backticks or containing backslashes #KT-12998 Fixed #KT-12999 Fixed --- idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt | 8 +++++++- .../testData/editor/quickDoc/OnMethodUsageWithMarkdown.kt | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt b/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt index ed60be75ebc..ebea243f86d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt +++ b/idea/src/org/jetbrains/kotlin/idea/kdoc/KDocRenderer.kt @@ -154,7 +154,13 @@ object KDocRenderer { sb.trimEnd() wrapChildren("p", newline = true) } - MarkdownElementTypes.CODE_SPAN -> wrapChildren("code") + MarkdownElementTypes.CODE_SPAN -> { + val startDelimiter = node.child(MarkdownTokenTypes.BACKTICK)?.text + if (startDelimiter != null) { + val text = node.text.substring(startDelimiter.length).removeSuffix(startDelimiter) + sb.append("").append(text.htmlEscape()).append("") + } + } MarkdownElementTypes.CODE_BLOCK, MarkdownElementTypes.CODE_FENCE -> { sb.trimEnd() diff --git a/idea/testData/editor/quickDoc/OnMethodUsageWithMarkdown.kt b/idea/testData/editor/quickDoc/OnMethodUsageWithMarkdown.kt index dae621b13af..dc51d2f542a 100644 --- a/idea/testData/editor/quickDoc/OnMethodUsageWithMarkdown.kt +++ b/idea/testData/editor/quickDoc/OnMethodUsageWithMarkdown.kt @@ -12,6 +12,9 @@ * Single stars embedded in a word like Embedded*Star have to be preserved as well. * * Exclamation marks are also important! Also in `code blocks!` + * + * bt+ : ``prefix ` postfix`` + * backslash: `\` */ fun testMethod() { @@ -30,3 +33,4 @@ fun test() { //INFO:

See this class

//INFO:

This is emphasized text but text_with_underscores has to preserve the underscores. Single stars embedded in a word like Embedded*Star have to be preserved as well.

//INFO:

Exclamation marks are also important! Also in code blocks!

+//INFO:

bt+ : prefix ` postfix backslash: \