aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/base/src/main/kotlin/parsers/MarkdownParser.kt3
-rw-r--r--plugins/base/src/test/kotlin/markdown/ParserTest.kt10
-rw-r--r--plugins/base/src/test/kotlin/model/CommentTest.kt37
-rw-r--r--plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt17
4 files changed, 52 insertions, 15 deletions
diff --git a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
index 2e301f1e..a1648b16 100644
--- a/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
+++ b/plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
@@ -10,6 +10,7 @@ import org.intellij.markdown.ast.impl.ListItemCompositeNode
import org.intellij.markdown.flavours.gfm.GFMElementTypes
import org.intellij.markdown.flavours.gfm.GFMFlavourDescriptor
import org.intellij.markdown.flavours.gfm.GFMTokenTypes
+import org.intellij.markdown.html.HtmlGenerator
import org.jetbrains.dokka.base.parsers.factories.DocTagsFromIElementFactory
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.links.PointingToDeclaration
@@ -343,7 +344,7 @@ open class MarkdownParser(
DocTagsFromIElementFactory.getInstance(node.type, children = node.children.mergeLeafASTNodes().flatMap {
DocTagsFromIElementFactory.getInstance(
MarkdownTokenTypes.TEXT,
- body = text.substring(it.startOffset, it.endOffset)
+ body = HtmlGenerator.trimIndents(text.substring(it.startOffset, it.endOffset), 4).toString()
)
})
diff --git a/plugins/base/src/test/kotlin/markdown/ParserTest.kt b/plugins/base/src/test/kotlin/markdown/ParserTest.kt
index 8e813eba..fd723263 100644
--- a/plugins/base/src/test/kotlin/markdown/ParserTest.kt
+++ b/plugins/base/src/test/kotlin/markdown/ParserTest.kt
@@ -1340,11 +1340,11 @@ class ParserTest : KDocTest() {
CodeBlock(
listOf(
Text(
- " val x = 1\n" +
- " val y = 2\n" +
- " if (x == 1) {\n" +
- " println(y)\n" +
- " }"
+ "val x = 1\n" +
+ "val y = 2\n" +
+ "if (x == 1) {\n" +
+ " println(y)\n" +
+ "}"
)
)
)
diff --git a/plugins/base/src/test/kotlin/model/CommentTest.kt b/plugins/base/src/test/kotlin/model/CommentTest.kt
index 0742587a..c511a3de 100644
--- a/plugins/base/src/test/kotlin/model/CommentTest.kt
+++ b/plugins/base/src/test/kotlin/model/CommentTest.kt
@@ -1,6 +1,8 @@
package model
+import org.jetbrains.dokka.model.DClass
import org.jetbrains.dokka.model.DProperty
+import org.jetbrains.dokka.model.doc.CodeBlock
import org.jetbrains.dokka.model.doc.CustomTagWrapper
import org.jetbrains.dokka.model.doc.Text
import org.junit.jupiter.api.Test
@@ -267,4 +269,39 @@ class CommentTest : AbstractModelTest("/src/main/kotlin/comment/Test.kt", "comme
}
}
}
+
+ @Test
+ fun `should remove spaces inside indented code block`() {
+ inlineModelTest(
+ """
+ |/**
+ | * Welcome:
+ | *
+ | * ```kotlin
+ | * fun main() {
+ | * println("Hello World!")
+ | * }
+ | * ```
+ | *
+ | * fun thisIsACodeBlock() {
+ | * val butWhy = "per markdown spec, because four-spaces prefix"
+ | * }
+ | */
+ |class Foo
+ """
+ ) {
+ with((this / "comment" / "Foo").cast<DClass>()) {
+ docs()[0].children[2] equals CodeBlock(
+ listOf(
+ Text(
+ "fun thisIsACodeBlock() {\n" +
+ " val butWhy = \"per markdown spec, because four-spaces prefix\"\n" +
+ "}"
+ )
+ )
+ )
+ }
+ }
+ }
+
}
diff --git a/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt b/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt
index 5c57c403..fe1a42c8 100644
--- a/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt
+++ b/plugins/base/src/test/kotlin/translators/DefaultDescriptorToDocumentableTranslatorTest.kt
@@ -5,7 +5,6 @@ import org.jetbrains.dokka.base.testApi.testRunner.BaseAbstractTest
import org.jetbrains.dokka.links.DRI
import org.jetbrains.dokka.model.*
import org.jetbrains.dokka.model.doc.*
-import org.junit.Assert
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Disabled
@@ -148,15 +147,15 @@ class DefaultDescriptorToDocumentableTranslatorTest : BaseAbstractTest() {
CodeBlock(
children = listOf(
Text(
- """ val soapAttrs = attrs("soap-env" to "http://www.w3.org/2001/12/soap-envelope",
- "soap-env:encodingStyle" to "http://www.w3.org/2001/12/soap-encoding")
- val soapXml = node("soap-env:Envelope", soapAttrs,
- node("soap-env:Body", attrs("xmlns:m" to "http://example"),
- node("m:GetExample",
- node("m:GetExampleName", "BasePair")
- )
+ """val soapAttrs = attrs("soap-env" to "http://www.w3.org/2001/12/soap-envelope",
+ "soap-env:encodingStyle" to "http://www.w3.org/2001/12/soap-encoding")
+val soapXml = node("soap-env:Envelope", soapAttrs,
+ node("soap-env:Body", attrs("xmlns:m" to "http://example"),
+ node("m:GetExample",
+ node("m:GetExampleName", "BasePair")
)
- )"""
+ )
+)"""
)
)
)