From 5f7b0632411a5b8b7b484bb0eabcb705ade36788 Mon Sep 17 00:00:00 2001 From: Omer Strulovich Date: Thu, 9 Jun 2022 08:54:59 -0700 Subject: [PATCH] Handle escaped markdown characters in KDoc Summary: We never encountered that until now, so all it required was handling this case as well. Fixes https://github.com/facebookincubator/ktfmt/issues/329 Reviewed By: cgrushko Differential Revision: D37038044 fbshipit-source-id: 21d89dc7186f6e46369980d94a97da8548a0f793 --- .../main/java/com/facebook/ktfmt/kdoc/KDocFormatter.kt | 1 + .../test/java/com/facebook/ktfmt/format/FormatterTest.kt | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/core/src/main/java/com/facebook/ktfmt/kdoc/KDocFormatter.kt b/core/src/main/java/com/facebook/ktfmt/kdoc/KDocFormatter.kt index f49ac3d9..8c0af079 100644 --- a/core/src/main/java/com/facebook/ktfmt/kdoc/KDocFormatter.kt +++ b/core/src/main/java/com/facebook/ktfmt/kdoc/KDocFormatter.kt @@ -98,6 +98,7 @@ object KDocFormatter { KDocTokens.MARKDOWN_LINK -> { tokens.add(KDocToken(MARKDOWN_LINK, tokenText)) } + KDocTokens.MARKDOWN_ESCAPED_CHAR, KDocTokens.TEXT -> { var first = true for (word in tokenizeKdocText(tokenText)) { diff --git a/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt b/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt index 716b6977..2096f50d 100644 --- a/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt +++ b/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt @@ -1721,6 +1721,14 @@ class FormatterTest { | */ |""".trimMargin()) + @Test + fun `formatting kdoc with markdown errors`() = + assertFormatted( + """ + |/** \[ */ + |fun markdownError() = Unit + |""".trimMargin()) + @Test fun `return statement with value`() = assertFormatted(