diff options
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/kotlin/parsers/MarkdownParser.kt | 31 | ||||
-rw-r--r-- | core/src/test/kotlin/markdown/KDocTest.kt | 48 | ||||
-rw-r--r-- | core/src/test/kotlin/markdown/ParserTest.kt | 18 |
3 files changed, 81 insertions, 16 deletions
diff --git a/core/src/main/kotlin/parsers/MarkdownParser.kt b/core/src/main/kotlin/parsers/MarkdownParser.kt index ff27dc2e..4f4a7e18 100644 --- a/core/src/main/kotlin/parsers/MarkdownParser.kt +++ b/core/src/main/kotlin/parsers/MarkdownParser.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag import org.jetbrains.kotlin.kdoc.psi.impl.KDocImpl import org.jetbrains.kotlin.kdoc.psi.impl.KDocSection import org.jetbrains.kotlin.kdoc.psi.impl.KDocTag +import java.net.MalformedURLException import org.intellij.markdown.parser.MarkdownParser as IntellijMarkdownParser class MarkdownParser ( @@ -85,18 +86,20 @@ class MarkdownParser ( ) } - private fun resolveDRI(link: String): DRI? = if (link.startsWith("http") || link.startsWith("www")) { - null - } else { - resolveKDocLink( - resolutionFacade.resolveSession.bindingContext, - resolutionFacade, - declarationDescriptor, - null, - link.split('.') - ).also { if (it.size > 1) throw Error("Markdown link resolved more than one element: $it") }.firstOrNull()//.single() - ?.let { DRI.from(it) } - } + private fun resolveDRI(link: String): DRI? = + try { + java.net.URL(link) + null + } catch(e: MalformedURLException) { + resolveKDocLink( + resolutionFacade.resolveSession.bindingContext, + resolutionFacade, + declarationDescriptor, + null, + link.split('.') + ).also { if (it.size > 1) throw Error("Markdown link resolved more than one element: $it") }.firstOrNull()//.single() + ?.let { DRI.from(it) } + } private fun referenceLinksHandler(node: ASTNode): DocTag { val linkLabel = node.children.find { it.type == MarkdownElementTypes.LINK_LABEL } ?: @@ -266,8 +269,8 @@ class MarkdownParser ( } private fun String.transform() = this - .replace(Regex("\n\n+"), "") - .replace(Regex("\n>+ "), "\n") + .replace(Regex("\n\n+"), "") // Squashing new lines between paragraphs + .replace(Regex("\n>+ "), "\n") // Replacement used in blockquotes, get rid of garbage } diff --git a/core/src/test/kotlin/markdown/KDocTest.kt b/core/src/test/kotlin/markdown/KDocTest.kt new file mode 100644 index 00000000..c084154b --- /dev/null +++ b/core/src/test/kotlin/markdown/KDocTest.kt @@ -0,0 +1,48 @@ +package markdown + +import org.jetbrains.dokka.model.Package +import org.jetbrains.dokka.model.doc.DocumentationNode +import org.jetbrains.dokka.pages.ModulePageNode +import org.junit.Assert +import testApi.testRunner.AbstractCoreTest + +open class KDocTest : AbstractCoreTest() { + + private val configuration = dokkaConfiguration { + passes { + pass { + sourceRoots = listOf("src/main/kotlin/example/Test.kt") + } + } + } + + private fun interpolateKdoc(kdoc: String) = """ + |/src/main/kotlin/example/Test.kt + |package example + | /** + ${kdoc.split("\n").joinToString("") { "| * $it\n" } } + | */ + |class Test + """.trimMargin() + + private fun actualDocumentationNode(modulePageNode: ModulePageNode) = + (modulePageNode.documentable?.children?.first() as Package) + .classlikes.first() + .platformInfo.first() + .documentationNode + + + protected fun executeTest(kdoc: String, expectedDocumentationNode: DocumentationNode) { + testInline( + interpolateKdoc(kdoc), + configuration + ) { + pagesGenerationStage = { + Assert.assertEquals( + expectedDocumentationNode, + actualDocumentationNode(it) + ) + } + } + } +}
\ No newline at end of file diff --git a/core/src/test/kotlin/markdown/ParserTest.kt b/core/src/test/kotlin/markdown/ParserTest.kt index 77ccd769..107940f6 100644 --- a/core/src/test/kotlin/markdown/ParserTest.kt +++ b/core/src/test/kotlin/markdown/ParserTest.kt @@ -1,12 +1,12 @@ package org.jetbrains.dokka.tests +import markdown.KDocTest import org.jetbrains.dokka.model.doc.* import org.junit.Ignore import org.junit.Test -import testApi.testRunner.AbstractKDocTest -class ParserTest : AbstractKDocTest() { +class ParserTest : KDocTest() { @Test fun `Simple text`() { val kdoc = """ @@ -897,5 +897,19 @@ class ParserTest : AbstractKDocTest() { ) executeTest(kdoc, expectedDocumentationNode) } + + @Test fun `Windows Carriage Return Line Feed`() { + val kdoc = "text\r\ntext" + val expectedDocumentationNode = DocumentationNode( + listOf( + Description( + P(listOf( + Text(body = "text\ntext") + )) + ) + ) + ) + executeTest(kdoc, expectedDocumentationNode) + } } |