diff options
author | Andrzej Ratajczak <andrzej.ratajczak98@gmail.com> | 2020-02-10 17:05:11 +0100 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-02-12 14:29:06 +0100 |
commit | 2d9f0753bb925f6a6d08ab7e67d5676c196de7d0 (patch) | |
tree | 5d7dea95cd58c4755ed74d6e9b8170f9d028a4b2 | |
parent | 18e28d080792d3f805d8e3c787675712d6b9b7ce (diff) | |
download | dokka-2d9f0753bb925f6a6d08ab7e67d5676c196de7d0.tar.gz dokka-2d9f0753bb925f6a6d08ab7e67d5676c196de7d0.tar.bz2 dokka-2d9f0753bb925f6a6d08ab7e67d5676c196de7d0.zip |
Adds requested changes
-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 | ||||
-rw-r--r-- | testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt | 42 |
4 files changed, 81 insertions, 58 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) + } } diff --git a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt index f906755a..edeedf10 100644 --- a/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt +++ b/testApi/src/main/kotlin/testApi/testRunner/TestRunner.kt @@ -203,48 +203,6 @@ abstract class AbstractCoreTest { } } -abstract class AbstractKDocTest : 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) - ) - } - } - } -} - - data class TestMethods( val analysisSetupStage: (Map<PlatformData, EnvironmentAndFacade>) -> Unit, val pluginsSetupStage: (DokkaContext) -> Unit, |