aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin
diff options
context:
space:
mode:
authorAlex Waters <awaters@nextfaze.com>2017-04-28 14:56:44 +0930
committerSimon Ogorodnik <sem-oro@yandex.ru>2017-05-02 15:48:38 +0300
commitacbe2f8c47a81c8e6046214f600ffdef24890fa6 (patch)
tree114626d3489c1eb74c78f7e36a3d95b3ef2ab62b /core/src/main/kotlin
parent5d611906da72c6ceff3722d307cf663461c908e7 (diff)
downloaddokka-acbe2f8c47a81c8e6046214f600ffdef24890fa6.tar.gz
dokka-acbe2f8c47a81c8e6046214f600ffdef24890fa6.tar.bz2
dokka-acbe2f8c47a81c8e6046214f600ffdef24890fa6.zip
Fix missing whitespace around links and tokens in Markdown formatted text
Diffstat (limited to 'core/src/main/kotlin')
-rw-r--r--core/src/main/kotlin/Kotlin/ContentBuilder.kt13
1 files changed, 10 insertions, 3 deletions
diff --git a/core/src/main/kotlin/Kotlin/ContentBuilder.kt b/core/src/main/kotlin/Kotlin/ContentBuilder.kt
index 9c081d17..c124821e 100644
--- a/core/src/main/kotlin/Kotlin/ContentBuilder.kt
+++ b/core/src/main/kotlin/Kotlin/ContentBuilder.kt
@@ -87,9 +87,16 @@ fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (Stri
parent.append(link)
}
}
- MarkdownTokenTypes.WHITE_SPACE,
+ MarkdownTokenTypes.WHITE_SPACE -> {
+ // Don't append first space if start of header (it is added during formatting later)
+ // v
+ // #### Some Heading
+ if (nodeStack.peek() !is ContentHeading || node.parent?.children?.first() != node) {
+ parent.append(ContentText(node.text))
+ }
+ }
MarkdownTokenTypes.EOL -> {
- if (keepWhitespace(nodeStack.peek()) && node.parent?.children?.last() != node) {
+ if (keepEol(nodeStack.peek()) && node.parent?.children?.last() != node) {
parent.append(ContentText(node.text))
}
}
@@ -148,7 +155,7 @@ fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (Stri
private fun MarkdownNode.getLabelText() = children.filter { it.type == MarkdownTokenTypes.TEXT || it.type == MarkdownTokenTypes.EMPH }.joinToString("") { it.text }
-private fun keepWhitespace(node: ContentNode) = node is ContentParagraph || node is ContentSection || node is ContentBlockCode
+private fun keepEol(node: ContentNode) = node is ContentParagraph || node is ContentSection || node is ContentBlockCode
fun buildInlineContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (String) -> ContentBlock) {
val inlineContent = tree.children.singleOrNull { it.type == MarkdownElementTypes.PARAGRAPH }?.children ?: listOf(tree)