aboutsummaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/main/kotlin/Kotlin/ContentBuilder.kt13
-rw-r--r--core/src/test/kotlin/format/MarkdownFormatTest.kt24
2 files changed, 34 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)
diff --git a/core/src/test/kotlin/format/MarkdownFormatTest.kt b/core/src/test/kotlin/format/MarkdownFormatTest.kt
index 16a81165..999d739b 100644
--- a/core/src/test/kotlin/format/MarkdownFormatTest.kt
+++ b/core/src/test/kotlin/format/MarkdownFormatTest.kt
@@ -332,6 +332,30 @@ class MarkdownFormatTest {
}
}
+ @Test fun linksInEmphasis() {
+ verifyMarkdownNode("linksInEmphasis")
+ }
+
+ @Test fun linksInStrong() {
+ verifyMarkdownNode("linksInStrong")
+ }
+
+ @Test fun linksInHeaders() {
+ verifyMarkdownNode("linksInHeaders")
+ }
+
+ @Test fun tokensInEmphasis() {
+ verifyMarkdownNode("tokensInEmphasis")
+ }
+
+ @Test fun tokensInStrong() {
+ verifyMarkdownNode("tokensInStrong")
+ }
+
+ @Test fun tokensInHeaders() {
+ verifyMarkdownNode("tokensInHeaders")
+ }
+
private fun buildMultiplePlatforms(path: String): DocumentationModule {
val module = DocumentationModule("test")
val options = DocumentationOptions("", "html", generateIndexPages = false)