Skip to content

Commit

Permalink
Trim four-spaces inside indented code block
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev committed Sep 8, 2022
1 parent 56ff8f3 commit 42aea80
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plugins/base/src/main/kotlin/parsers/MarkdownParser.kt
Expand Up @@ -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
Expand Down Expand Up @@ -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()
)
})

Expand Down
37 changes: 37 additions & 0 deletions 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
Expand Down Expand Up @@ -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" +
"}"
)
)
)
}
}
}

}

0 comments on commit 42aea80

Please sign in to comment.