diff options
Diffstat (limited to 'core')
5 files changed, 193 insertions, 160 deletions
diff --git a/core/src/main/kotlin/model/doc/DocTag.kt b/core/src/main/kotlin/model/doc/DocTag.kt index 0224634b..94558ca7 100644 --- a/core/src/main/kotlin/model/doc/DocTag.kt +++ b/core/src/main/kotlin/model/doc/DocTag.kt @@ -28,6 +28,7 @@ class A(children: List<DocTag> = emptyList(), params: Map<String, String> = empt class Big(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params) class B(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params) class BlockQuote(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params) +object Br : DocTag(emptyList(), emptyMap()) class Cite(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params) class Code(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params) class Dd(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params) @@ -74,7 +75,7 @@ class Strong(children: List<DocTag> = emptyList(), params: Map<String, String> = class Sub(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params) class Sup(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params) class Table(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params) -class Text(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap(), val body: String = "") : DocTag(children, params) { +class Text(val body: String = "", children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params) { override fun equals(other: Any?): Boolean = super.equals(other) && this.body == (other as Text).body override fun hashCode(): Int = super.hashCode() + body.hashCode() } @@ -89,7 +90,7 @@ class Tt(children: List<DocTag> = emptyList(), params: Map<String, String> = emp class U(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params) class Ul(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params) class Var(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params) -class DocumentationLink(children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap(), val dri: DRI) : DocTag(children, params) { +class DocumentationLink(val dri: DRI, children: List<DocTag> = emptyList(), params: Map<String, String> = emptyMap()) : DocTag(children, params) { override fun equals(other: Any?): Boolean = super.equals(other) && this.dri == (other as DocumentationLink).dri override fun hashCode(): Int = super.hashCode() + dri.hashCode() } diff --git a/core/src/main/kotlin/parsers/MarkdownParser.kt b/core/src/main/kotlin/parsers/MarkdownParser.kt index 4f4a7e18..d70a2239 100644 --- a/core/src/main/kotlin/parsers/MarkdownParser.kt +++ b/core/src/main/kotlin/parsers/MarkdownParser.kt @@ -1,6 +1,8 @@ package org.jetbrains.dokka.parsers import com.intellij.psi.PsiElement +import org.intellij.markdown.IElementType +import org.intellij.markdown.MarkdownElementType import org.jetbrains.dokka.model.doc.* import org.intellij.markdown.MarkdownElementTypes import org.intellij.markdown.MarkdownTokenTypes @@ -47,7 +49,8 @@ class MarkdownParser ( private fun blockquotesHandler(node: ASTNode): DocTag = DocNodesFromIElementFactory.getInstance(node.type, children = node.children - .filterIsInstance<CompositeASTNode>().evaluateChildren()) + .filterIsInstance<CompositeASTNode>() + .evaluateChildren()) private fun listsHandler(node: ASTNode): DocTag { @@ -166,11 +169,14 @@ class MarkdownParser ( node.type, children = node .children - .let { listOf(Text( body = text.substring( - it.find { it.type == MarkdownTokenTypes.CODE_FENCE_CONTENT }?.startOffset ?: 0, - it.findLast { it.type == MarkdownTokenTypes.CODE_FENCE_CONTENT }?.endOffset ?: 0 //TODO: Problem with empty code fence - )) - ) }, + .dropWhile { it.type != MarkdownTokenTypes.CODE_FENCE_CONTENT } + .dropLastWhile { it.type != MarkdownTokenTypes.CODE_FENCE_CONTENT } + .map { + if(it.type == MarkdownTokenTypes.EOL) + LeafASTNode(MarkdownTokenTypes.HARD_LINE_BREAK, 0, 0) + else + it + }.evaluateChildren(), params = node .children .find { it.type == MarkdownTokenTypes.FENCE_LANG } @@ -208,6 +214,7 @@ class MarkdownParser ( MarkdownElementTypes.CODE_FENCE -> codeFencesHandler(node) MarkdownElementTypes.CODE_SPAN -> codeSpansHandler(node) MarkdownElementTypes.IMAGE -> imagesHandler(node) + MarkdownTokenTypes.HARD_LINE_BREAK -> DocNodesFromIElementFactory.getInstance(node.type) MarkdownTokenTypes.CODE_FENCE_CONTENT, MarkdownTokenTypes.CODE_LINE, MarkdownTokenTypes.TEXT -> DocNodesFromIElementFactory.getInstance( @@ -223,19 +230,16 @@ class MarkdownParser ( this.removeUselessTokens().mergeLeafASTNodes().map { visitNode(it) } private fun List<ASTNode>.removeUselessTokens(): List<ASTNode> = - this.filterIndexed { index, _ -> - !(this[index].type == MarkdownTokenTypes.EOL && - this.isLeaf(index - 1) && this.getOrNull(index - 1)?.type !in leafNodes && - this.isLeaf(index + 1) && this.getOrNull(index + 1)?.type !in leafNodes) && - this[index].type != MarkdownElementTypes.LINK_DEFINITION - } + this.filterIndexed { index, node -> !(node.type == MarkdownElementTypes.LINK_DEFINITION || ( + node.type == MarkdownTokenTypes.EOL && + this.getOrNull(index - 1)?.type == MarkdownTokenTypes.HARD_LINE_BREAK + )) } - private val notLeafNodes = listOf(MarkdownTokenTypes.HORIZONTAL_RULE) - private val leafNodes = listOf(MarkdownElementTypes.STRONG, MarkdownElementTypes.EMPH) + private val notLeafNodes = listOf(MarkdownTokenTypes.HORIZONTAL_RULE, MarkdownTokenTypes.HARD_LINE_BREAK) - private fun List<ASTNode>.isLeaf(index: Int): Boolean = + private fun List<ASTNode>.isNotLeaf(index: Int): Boolean = if(index in 0..this.lastIndex) - (this[index] is CompositeASTNode)|| this[index].type in notLeafNodes + (this[index] is CompositeASTNode) || this[index].type in notLeafNodes else false @@ -243,15 +247,15 @@ class MarkdownParser ( val children: MutableList<ASTNode> = mutableListOf() var index = 0 while(index <= this.lastIndex) { - if(this.isLeaf(index)) { + if(this.isNotLeaf(index)) { children += this[index] } else { val startOffset = this[index].startOffset - while(index < this.lastIndex) { - if(this.isLeaf(index + 1)) { + while(index < this.lastIndex ) { + if(this.isNotLeaf(index + 1) || this[index+1].startOffset != this[index].endOffset) { val endOffset = this[index].endOffset - if(text.substring(startOffset, endOffset).transform().isNotEmpty()) + if(text.substring(startOffset, endOffset).transform().trim().isNotEmpty()) children += LeafASTNode(MarkdownTokenTypes.TEXT, startOffset, endOffset) break } @@ -259,7 +263,7 @@ class MarkdownParser ( } if(index == this.lastIndex) { val endOffset = this[index].endOffset - if(text.substring(startOffset, endOffset).transform().isNotEmpty()) + if(text.substring(startOffset, endOffset).transform().trim().isNotEmpty()) children += LeafASTNode(MarkdownTokenTypes.TEXT, startOffset, endOffset) } } @@ -270,7 +274,8 @@ class MarkdownParser ( private fun String.transform() = this .replace(Regex("\n\n+"), "") // Squashing new lines between paragraphs - .replace(Regex("\n>+ "), "\n") // Replacement used in blockquotes, get rid of garbage + .replace(Regex("\n"), " ") + .replace(Regex(" >+ +"), " ") // Replacement used in blockquotes, get rid of garbage } diff --git a/core/src/main/kotlin/parsers/factories/DocNodesFromIElementFactory.kt b/core/src/main/kotlin/parsers/factories/DocNodesFromIElementFactory.kt index b899679d..d4c6e752 100644 --- a/core/src/main/kotlin/parsers/factories/DocNodesFromIElementFactory.kt +++ b/core/src/main/kotlin/parsers/factories/DocNodesFromIElementFactory.kt @@ -12,7 +12,7 @@ object DocNodesFromIElementFactory { when(type) { MarkdownElementTypes.SHORT_REFERENCE_LINK, MarkdownElementTypes.FULL_REFERENCE_LINK, - MarkdownElementTypes.INLINE_LINK -> if(dri == null) A(children, params) else DocumentationLink(children, params, dri) + MarkdownElementTypes.INLINE_LINK -> if(dri == null) A(children, params) else DocumentationLink(dri, children, params) MarkdownElementTypes.STRONG -> B(children, params) MarkdownElementTypes.BLOCK_QUOTE -> BlockQuote(children, params) MarkdownElementTypes.CODE_SPAN, @@ -30,8 +30,9 @@ object DocNodesFromIElementFactory { MarkdownElementTypes.ORDERED_LIST -> Ol(children, params) MarkdownElementTypes.UNORDERED_LIST -> Ul(children, params) MarkdownElementTypes.PARAGRAPH -> P(children, params) - MarkdownTokenTypes.TEXT -> Text(children, params, body ?: throw NullPointerException("Text body should be at least empty string passed to DocNodes factory!")) + MarkdownTokenTypes.TEXT -> Text(body ?: throw NullPointerException("Text body should be at least empty string passed to DocNodes factory!"), children, params ) MarkdownTokenTypes.HORIZONTAL_RULE -> HorizontalRule + MarkdownTokenTypes.HARD_LINE_BREAK -> Br else -> CustomDocTag(children, params) } }
\ No newline at end of file diff --git a/core/src/main/kotlin/parsers/factories/DocNodesFromStringFactory.kt b/core/src/main/kotlin/parsers/factories/DocNodesFromStringFactory.kt index dc74ecc1..4ff9a9d4 100644 --- a/core/src/main/kotlin/parsers/factories/DocNodesFromStringFactory.kt +++ b/core/src/main/kotlin/parsers/factories/DocNodesFromStringFactory.kt @@ -11,8 +11,9 @@ object DocNodesFromStringFactory { "big" -> Big(children, params) "b" -> B(children, params) "blockquote" -> BlockQuote(children, params) - "bite" -> Cite(children, params) - "bode" -> Code(children, params) + "br" -> Br + "cite" -> Cite(children, params) + "code" -> Code(children, params) "dd" -> Dd(children, params) "dfn" -> Dfn(children, params) "dir" -> Dir(children, params) @@ -57,7 +58,7 @@ object DocNodesFromStringFactory { "sub" -> Sub(children, params) "sup" -> Sup(children, params) "table" -> Table(children, params) - "#text" -> Text(children, params, body ?: throw NullPointerException("Text body should be at least empty string passed to DocNodes factory!")) + "#text" -> Text(body ?: throw NullPointerException("Text body should be at least empty string passed to DocNodes factory!"), children, params) "tBody" -> TBody(children, params) "td" -> Td(children, params) "tFoot" -> TFoot(children, params) @@ -69,7 +70,7 @@ object DocNodesFromStringFactory { "u" -> U(children, params) "ul" -> Ul(children, params) "var" -> Var(children, params) - "documentationlink" -> DocumentationLink(children, params, dri ?: throw NullPointerException("DRI cannot be passed null while constructing documentation link!")) + "documentationlink" -> DocumentationLink(dri ?: throw NullPointerException("DRI cannot be passed null while constructing documentation link!"), children, params) "hr" -> HorizontalRule else -> CustomDocTag(children, params) } diff --git a/core/src/test/kotlin/markdown/ParserTest.kt b/core/src/test/kotlin/markdown/ParserTest.kt index 35b004e7..dee8e907 100644 --- a/core/src/test/kotlin/markdown/ParserTest.kt +++ b/core/src/test/kotlin/markdown/ParserTest.kt @@ -16,7 +16,26 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text(body = "This is simple test of string\nNext line"))) + P(listOf(Text("This is simple test of string Next line"))) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } + + @Test fun `Simple text with new line`() { + val kdoc = """ + | This is simple test of string\ + | Next line + """.trimMargin() + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Text("This is simple test of string"), + Br, + Text("Next line") + )) ) ) ) @@ -33,12 +52,12 @@ class ParserTest : KDocTest() { Description( P( listOf( - Text(body = "This is "), - B(listOf(Text(body = "simple"))), - Text(body = " test of "), - I(listOf(Text(body = "string"))), - Text(body = "\nNext "), - B(listOf(I(listOf(Text(body = "line"))))) + Text("This is "), + B(listOf(Text("simple"))), + Text(" test of "), + I(listOf(Text("string"))), + Text(" Next "), + B(listOf(I(listOf(Text("line"))))) ) ) ) @@ -54,7 +73,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text(body = "This is simple text with: colon!"))) + P(listOf(Text("This is simple text with: colon!"))) ) ) ) @@ -70,7 +89,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text(body = "Text\nand\nString"))) + P(listOf(Text("Text and String"))) ) ) ) @@ -82,7 +101,7 @@ class ParserTest : KDocTest() { | Paragraph number | one | - | Paragraph + | Paragraph\ | number two """.trimMargin() val expectedDocumentationNode = DocumentationNode( @@ -90,8 +109,8 @@ class ParserTest : KDocTest() { Description( P( listOf( - P(listOf(Text(body = "Paragraph number\none"))), - P(listOf(Text(body = "Paragraph\nnumber two"))) + P(listOf(Text("Paragraph number one"))), + P(listOf(Text("Paragraph"), Br, Text("number two"))) ) ) ) @@ -105,7 +124,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(I(listOf(Text(body = "text"))))) + P(listOf(I(listOf(Text("text"))))) ) ) ) @@ -117,7 +136,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text(body = "text_with_underscores"))) + P(listOf(Text("text_with_underscores"))) ) ) ) @@ -129,7 +148,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(I(listOf(Text(body = "text"))))) + P(listOf(I(listOf(Text("text"))))) ) ) ) @@ -141,7 +160,7 @@ class ParserTest : KDocTest() { val expectedDocumentationNode = DocumentationNode( listOf( Description( - P(listOf(Text(body = "Embedded*Star"))) + P(listOf(Text("Embedded*Star"))) ) ) ) @@ -159,8 +178,8 @@ class ParserTest : KDocTest() { Description( Ul( listOf( - Li(listOf(P(listOf(Text(body = "list item 1"))))), - Li(listOf(P(listOf(Text(body = "list item 2"))))) + Li(listOf(P(listOf(Text("list item 1"))))), + Li(listOf(P(listOf(Text("list item 2"))))) ) ) ) @@ -173,7 +192,7 @@ class ParserTest : KDocTest() { val kdoc = """ | * list item 1 | continue 1 - | * list item 2 + | * list item 2\ | continue 2 """.trimMargin() val expectedDocumentationNode = DocumentationNode( @@ -181,8 +200,8 @@ class ParserTest : KDocTest() { Description( Ul( listOf( - Li(listOf(P(listOf(Text(body = "list item 1\ncontinue 1"))))), - Li(listOf(P(listOf(Text(body = "list item 2\ncontinue 2"))))) + Li(listOf(P(listOf(Text("list item 1 continue 1"))))), + Li(listOf(P(listOf(Text("list item 2"), Br, Text("continue 2"))))) ) ) ) @@ -203,14 +222,14 @@ class ParserTest : KDocTest() { Description( Ul(listOf( Li(listOf(P(listOf( - Text(body = "list "), - B(listOf(Text(body = "item"))), - Text(body = " 1\ncontinue 1") + Text("list "), + B(listOf(Text("item"))), + Text(" 1 continue 1") )))), Li(listOf(P(listOf( - Text(body = "list "), - B(listOf(Text(body = "item"))), - Text(body = " 2\ncontinue 2") + Text("list "), + B(listOf(Text("item"))), + Text(" 2 continue 2") )))) )) ) @@ -238,19 +257,19 @@ class ParserTest : KDocTest() { Description( P(listOf( Ul(listOf( - Li(listOf(P(listOf(Text(body = "Outer first\nOuter next line"))))), - Li(listOf(P(listOf(Text(body = "Outer second"))))), + Li(listOf(P(listOf(Text("Outer first Outer next line"))))), + Li(listOf(P(listOf(Text("Outer second"))))), Ul(listOf( - Li(listOf(P(listOf(Text(body = "Middle first\nMiddle next line"))))), - Li(listOf(P(listOf(Text(body = "Middle second"))))), + Li(listOf(P(listOf(Text("Middle first Middle next line"))))), + Li(listOf(P(listOf(Text("Middle second"))))), Ul(listOf( - Li(listOf(P(listOf(Text(body = "Inner first\nInner next line"))))) + Li(listOf(P(listOf(Text("Inner first Inner next line"))))) )), - Li(listOf(P(listOf(Text(body = "Middle third"))))) + Li(listOf(P(listOf(Text("Middle third"))))) )), - Li(listOf(P(listOf(Text(body = "Outer third"))))) + Li(listOf(P(listOf(Text("Outer third"))))) )), - P(listOf(Text(body = "New paragraph"))) + P(listOf(Text("New paragraph"))) )) ) ) @@ -268,8 +287,8 @@ class ParserTest : KDocTest() { Description( Ol( listOf( - Li(listOf(P(listOf(Text(body = "list item 1"))))), - Li(listOf(P(listOf(Text(body = "list item 2"))))) + Li(listOf(P(listOf(Text("list item 1"))))), + Li(listOf(P(listOf(Text("list item 2"))))) ), mapOf("start" to "1") ) @@ -290,8 +309,8 @@ class ParserTest : KDocTest() { Description( Ol( listOf( - Li(listOf(P(listOf(Text(body = "list item 1"))))), - Li(listOf(P(listOf(Text(body = "list item 2"))))) + Li(listOf(P(listOf(Text("list item 1"))))), + Li(listOf(P(listOf(Text("list item 2"))))) ), mapOf("start" to "9") ) @@ -313,8 +332,8 @@ class ParserTest : KDocTest() { Description( Ol( listOf( - Li(listOf(P(listOf(Text(body = "list item 1\ncontinue 1"))))), - Li(listOf(P(listOf(Text(body = "list item 2\ncontinue 2"))))) + Li(listOf(P(listOf(Text("list item 1 continue 1"))))), + Li(listOf(P(listOf(Text("list item 2 continue 2"))))) ), mapOf("start" to "2") ) @@ -336,14 +355,14 @@ class ParserTest : KDocTest() { Description( Ol(listOf( Li(listOf(P(listOf( - Text(body = "list "), - B(listOf(Text(body = "item"))), - Text(body = " 1\ncontinue 1") + Text("list "), + B(listOf(Text("item"))), + Text(" 1 continue 1") )))), Li(listOf(P(listOf( - Text(body = "list "), - B(listOf(Text(body = "item"))), - Text(body = " 2\ncontinue 2") + Text("list "), + B(listOf(Text("item"))), + Text(" 2 continue 2") )))) ), mapOf("start" to "1") @@ -373,25 +392,25 @@ class ParserTest : KDocTest() { Description( P(listOf( Ol(listOf( - Li(listOf(P(listOf(Text(body = "Outer first\nOuter next line"))))), - Li(listOf(P(listOf(Text(body = "Outer second"))))), + Li(listOf(P(listOf(Text("Outer first Outer next line"))))), + Li(listOf(P(listOf(Text("Outer second"))))), Ol(listOf( - Li(listOf(P(listOf(Text(body = "Middle first\nMiddle next line"))))), - Li(listOf(P(listOf(Text(body = "Middle second"))))), + Li(listOf(P(listOf(Text("Middle first Middle next line"))))), + Li(listOf(P(listOf(Text("Middle second"))))), Ol(listOf( - Li(listOf(P(listOf(Text(body = "Inner first\nInner next line"))))) + Li(listOf(P(listOf(Text("Inner first Inner next line"))))) ), mapOf("start" to "1") ), - Li(listOf(P(listOf(Text(body = "Middle third"))))) + Li(listOf(P(listOf(Text("Middle third"))))) ), mapOf("start" to "1") ), - Li(listOf(P(listOf(Text(body = "Outer third"))))) + Li(listOf(P(listOf(Text("Outer third"))))) ), mapOf("start" to "1") ), - P(listOf(Text(body = "New paragraph"))) + P(listOf(Text("New paragraph"))) )) ) ) @@ -418,23 +437,23 @@ class ParserTest : KDocTest() { Description( P(listOf( Ol(listOf( - Li(listOf(P(listOf(Text(body = "Outer first\nOuter next line"))))), - Li(listOf(P(listOf(Text(body = "Outer second"))))), + Li(listOf(P(listOf(Text("Outer first Outer next line"))))), + Li(listOf(P(listOf(Text("Outer second"))))), Ul(listOf( - Li(listOf(P(listOf(Text(body = "Middle first\nMiddle next line"))))), - Li(listOf(P(listOf(Text(body = "Middle second"))))), + Li(listOf(P(listOf(Text("Middle first Middle next line"))))), + Li(listOf(P(listOf(Text("Middle second"))))), Ol(listOf( - Li(listOf(P(listOf(Text(body = "Inner first\nInner next line"))))) + Li(listOf(P(listOf(Text("Inner first Inner next line"))))) ), mapOf("start" to "1") ), - Li(listOf(P(listOf(Text(body = "Middle third"))))) + Li(listOf(P(listOf(Text("Middle third"))))) )), - Li(listOf(P(listOf(Text(body = "Outer third"))))) + Li(listOf(P(listOf(Text("Outer third"))))) ), mapOf("start" to "1") ), - P(listOf(Text(body = "New paragraph"))) + P(listOf(Text("New paragraph"))) )) ) ) @@ -453,9 +472,9 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf( - H1(listOf(Text(body = "Header 1"))), - P(listOf(Text(body = "Following text"))), - P(listOf(Text(body = "New paragraph"))) + H1(listOf(Text("Header 1"))), + P(listOf(Text("Following text"))), + P(listOf(Text("New paragraph"))) )) ) ) @@ -483,18 +502,18 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf( - H1(listOf(Text(body = "Header 1"))), - P(listOf(Text(body = "Text 1"))), - H2(listOf(Text(body = "Header 2"))), - P(listOf(Text(body = "Text 2"))), - H3(listOf(Text(body = "Header 3"))), - P(listOf(Text(body = "Text 3"))), - H4(listOf(Text(body = "Header 4"))), - P(listOf(Text(body = "Text 4"))), - H5(listOf(Text(body = "Header 5"))), - P(listOf(Text(body = "Text 5"))), - H6(listOf(Text(body = "Header 6"))), - P(listOf(Text(body = "Text 6"))) + H1(listOf(Text("Header 1"))), + P(listOf(Text("Text 1"))), + H2(listOf(Text("Header 2"))), + P(listOf(Text("Text 2"))), + H3(listOf(Text("Header 3"))), + P(listOf(Text("Text 3"))), + H4(listOf(Text("Header 4"))), + P(listOf(Text("Text 4"))), + H5(listOf(Text("Header 5"))), + P(listOf(Text("Text 5"))), + H6(listOf(Text("Header 6"))), + P(listOf(Text("Text 6"))) )) ) ) @@ -504,16 +523,16 @@ class ParserTest : KDocTest() { @Test fun `Bold New Line Bold`() { val kdoc = """ - | **line 1** + | **line 1**\ | **line 2** """.trimMargin() val expectedDocumentationNode = DocumentationNode( listOf( Description( P(listOf( - B(listOf(Text(body = "line 1"))), - Text(body = "\n"), - B(listOf(Text(body = "line 2"))) + B(listOf(Text("line 1"))), + Br, + B(listOf(Text("line 2"))) )) ) ) @@ -538,13 +557,13 @@ class ParserTest : KDocTest() { Description( P(listOf( HorizontalRule, - P(listOf(Text(body = "text 1"))), + P(listOf(Text("text 1"))), HorizontalRule, - P(listOf(Text(body = "text 2"))), + P(listOf(Text("text 2"))), HorizontalRule, - P(listOf(Text(body = "text 3"))), + P(listOf(Text("text 3"))), HorizontalRule, - P(listOf(Text(body = "text 4"))), + P(listOf(Text("text 4"))), HorizontalRule )) ) @@ -567,11 +586,13 @@ class ParserTest : KDocTest() { Description( P(listOf( BlockQuote(listOf( - P(listOf(Text(body = "Blockquotes are very handy in email to emulate reply text.\nThis line is part of the same quote."))) + P(listOf( + Text("Blockquotes are very handy in email to emulate reply text. This line is part of the same quote.") + )) )), - P(listOf(Text(body = "Quote break."))), + P(listOf(Text("Quote break."))), BlockQuote(listOf( - P(listOf(Text(body = "Quote"))) + P(listOf(Text("Quote"))) )) )) ) @@ -599,15 +620,15 @@ class ParserTest : KDocTest() { Description( P(listOf( BlockQuote(listOf( - P(listOf(Text(body = "text 1\ntext 2"))), + P(listOf(Text("text 1 text 2"))), BlockQuote(listOf( - P(listOf(Text(body = "text 3\ntext 4"))) + P(listOf(Text("text 3 text 4"))) )), - P(listOf(Text(body = "text 5"))) + P(listOf(Text("text 5"))) )), - P(listOf(Text(body = "Quote break."))), + P(listOf(Text("Quote break."))), BlockQuote(listOf( - P(listOf(Text(body = "Quote"))) + P(listOf(Text("Quote"))) )) )) ) @@ -637,24 +658,24 @@ class ParserTest : KDocTest() { P(listOf( BlockQuote(listOf( P(listOf( - Text(body = "text "), - B(listOf(Text(body = "1"))), - Text(body = "\ntext 2") + Text("text "), + B(listOf(Text("1"))), + Text("\ntext 2") )), BlockQuote(listOf( - H1(listOf(Text(body = "text 3"))), + H1(listOf(Text("text 3"))), Ul(listOf( - Li(listOf(P(listOf(Text(body = "text 4"))))), + Li(listOf(P(listOf(Text("text 4"))))), Ul(listOf( - Li(listOf(P(listOf(Text(body = "text 5"))))) + Li(listOf(P(listOf(Text("text 5"))))) ) ))) )), - P(listOf(Text(body = "text 6"))) + P(listOf(Text("text 6"))) )), - P(listOf(Text(body = "Quote break."))), + P(listOf(Text("Quote break."))), BlockQuote(listOf( - P(listOf(Text(body = "Quote"))) + P(listOf(Text("Quote"))) )) )) ) @@ -672,8 +693,8 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf( - Code(listOf(Text(body = "Some code"))), - Text(body = "\nSample text") + Code(listOf(Text("Some code"))), + Text(" Sample text") )) ) ) @@ -700,12 +721,16 @@ class ParserTest : KDocTest() { P(listOf( Code( listOf( - Text(body = "val x: Int = 0\nval y: String = \"Text\"\n\n val z: Boolean = true\n" + - "for(i in 0..10) {\n println(i)\n}") + Text("val x: Int = 0"), Br, + Text("val y: String = \"Text\""), Br, Br, + Text(" val z: Boolean = true"), Br, + Text("for(i in 0..10) {"), Br, + Text(" println(i)"), Br, + Text("}") ), mapOf("lang" to "kotlin") ), - P(listOf(Text(body = "Sample text"))) + P(listOf(Text("Sample text"))) )) ) ) @@ -722,7 +747,7 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf(A( - listOf(Text(body = "I'm an inline-style link")), + listOf(Text("I'm an inline-style link")), mapOf("href" to "https://www.google.com") ))) ) @@ -739,7 +764,7 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf(A( - listOf(Text(body = "I'm an inline-style link with title")), + listOf(Text("I'm an inline-style link with title")), mapOf("href" to "https://www.google.com", "title" to "Google's Homepage") ))) ) @@ -758,7 +783,7 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf(P(listOf(A( - listOf(Text(body = "I'm a reference-style link")), + listOf(Text("I'm a reference-style link")), mapOf("href" to "https://www.mozilla.org") ))))) ) @@ -777,7 +802,7 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf(P(listOf(A( - listOf(Text(body = "You can use numbers for reference-style link definitions")), + listOf(Text("You can use numbers for reference-style link definitions")), mapOf("href" to "http://slashdot.org") ))))) ) @@ -796,12 +821,12 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf(P(listOf( - Text(body = "Or leave it empty and use the "), + Text("Or leave it empty and use the "), A( - listOf(Text(body = "link text itself")), + listOf(Text("link text itself")), mapOf("href" to "http://www.reddit.com") ), - Text(body = ".") + Text(".") )))) ) ) @@ -819,12 +844,12 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf( - Text(body = "URLs and URLs in angle brackets will automatically get turned into links.\nhttp://www.example.com or "), + Text("URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com or "), A( - listOf(Text(body = "http://www.example.com")), + listOf(Text("http://www.example.com")), mapOf("href" to "http://www.example.com") ), - Text(body = " and sometimes\nexample.com (but not on Github, for example).") + Text(" and sometimes example.com (but not on Github, for example).") )) ) ) @@ -859,38 +884,38 @@ class ParserTest : KDocTest() { Description( P(listOf( P(listOf(A( - listOf(Text(body = "I'm an inline-style link")), + listOf(Text("I'm an inline-style link")), mapOf("href" to "https://www.google.com") ))), P(listOf(A( - listOf(Text(body = "I'm an inline-style link with title")), + listOf(Text("I'm an inline-style link with title")), mapOf("href" to "https://www.google.com", "title" to "Google's Homepage") ))), P(listOf(A( - listOf(Text(body = "I'm a reference-style link")), + listOf(Text("I'm a reference-style link")), mapOf("href" to "https://www.mozilla.org") ))), P(listOf(A( - listOf(Text(body = "You can use numbers for reference-style link definitions")), + listOf(Text("You can use numbers for reference-style link definitions")), mapOf("href" to "http://slashdot.org") ))), P(listOf( - Text(body = "Or leave it empty and use the "), + Text("Or leave it empty and use the "), A( - listOf(Text(body = "link text itself")), + listOf(Text("link text itself")), mapOf("href" to "http://www.reddit.com") ), - Text(body = ".") + Text(".") )), P(listOf( - Text(body = "URLs and URLs in angle brackets will automatically get turned into links.\nhttp://www.example.com or "), + Text("URLs and URLs in angle brackets will automatically get turned into links. http://www.example.com or "), A( - listOf(Text(body = "http://www.example.com")), + listOf(Text("http://www.example.com")), mapOf("href" to "http://www.example.com") ), - Text(body = " and sometimes\nexample.com (but not on Github, for example).") + Text(" and sometimes example.com (but not on Github, for example).") )), - P(listOf(Text(body = "Some text to show that the reference links can follow later."))) + P(listOf(Text("Some text to show that the reference links can follow later."))) )) ) ) @@ -904,7 +929,7 @@ class ParserTest : KDocTest() { listOf( Description( P(listOf( - Text(body = "text\ntext") + Text("text text") )) ) ) |