From c2afb348bb0d3dd60d336aa312b5fcedfb31b966 Mon Sep 17 00:00:00 2001 From: Alex Waters Date: Mon, 1 May 2017 14:00:31 +0930 Subject: Fix Markdown list spacing, ordering, and erroneous new lines --- core/src/main/kotlin/Kotlin/ContentBuilder.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'core/src/main/kotlin/Kotlin/ContentBuilder.kt') diff --git a/core/src/main/kotlin/Kotlin/ContentBuilder.kt b/core/src/main/kotlin/Kotlin/ContentBuilder.kt index c124821e..a244a48e 100644 --- a/core/src/main/kotlin/Kotlin/ContentBuilder.kt +++ b/core/src/main/kotlin/Kotlin/ContentBuilder.kt @@ -96,7 +96,9 @@ fun buildContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (Stri } } MarkdownTokenTypes.EOL -> { - if (keepEol(nodeStack.peek()) && node.parent?.children?.last() != node) { + if ((keepEol(nodeStack.peek()) && node.parent?.children?.last() != node) || + // Keep extra blank lines when processing lists (affects Markdown formatting) + (processingList(nodeStack.peek()) && node.previous?.type == MarkdownTokenTypes.EOL)) { parent.append(ContentText(node.text)) } } @@ -156,6 +158,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 keepEol(node: ContentNode) = node is ContentParagraph || node is ContentSection || node is ContentBlockCode +private fun processingList(node: ContentNode) = node is ContentOrderedList || node is ContentUnorderedList fun buildInlineContentTo(tree: MarkdownNode, target: ContentBlock, linkResolver: (String) -> ContentBlock) { val inlineContent = tree.children.singleOrNull { it.type == MarkdownElementTypes.PARAGRAPH }?.children ?: listOf(tree) -- cgit