aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/base/src')
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt24
-rw-r--r--plugins/base/src/test/kotlin/renderers/html/BasicTest.kt20
-rw-r--r--plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt23
3 files changed, 32 insertions, 35 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
index 2a24a959..1584df02 100644
--- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
+++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt
@@ -1,8 +1,5 @@
package org.jetbrains.dokka.base.renderers.html
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.runBlocking
import kotlinx.html.*
import kotlinx.html.stream.createHTML
import org.jetbrains.dokka.DokkaSourceSetID
@@ -644,18 +641,13 @@ open class HtmlRenderer(
) = locationProvider.resolve(to, platforms.toSet(), from)?.let { buildLink(it, block) }
?: run { context.logger.error("Cannot resolve path for `$to` from `$from`"); block() }
- override fun buildError(node: ContentNode) {
- context.logger.error("Unknown ContentNode type: $node")
- }
+ override fun buildError(node: ContentNode) = context.logger.error("Unknown ContentNode type: $node")
- override fun FlowContent.buildNewLine() {
- br()
- }
+ override fun FlowContent.buildNewLine() = br()
override fun FlowContent.buildLink(address: String, content: FlowContent.() -> Unit) =
a(href = address, block = content)
-
override fun FlowContent.buildDRILink(
node: ContentDRILink,
pageContext: ContentPage,
@@ -664,8 +656,15 @@ open class HtmlRenderer(
buildLink(address) {
buildText(node.children, pageContext, sourceSetRestriction)
}
- } ?: templateCommand(ResolveLinkCommand(node.address)) {
- buildText(node.children, pageContext, sourceSetRestriction)
+ } ?: if (isPartial) {
+ templateCommand(ResolveLinkCommand(node.address)) {
+ buildText(node.children, pageContext, sourceSetRestriction)
+ }
+ } else {
+ span {
+ attributes["data-unresolved-link"] = node.address.toString().htmlEscape()
+ buildText(node.children, pageContext, sourceSetRestriction)
+ }
}
override fun FlowContent.buildCodeBlock(
@@ -823,6 +822,7 @@ open class HtmlRenderer(
(locationProvider as DokkaBaseLocationProvider).anchorForDCI(DCI(dci.dri, contentKind), sourceSets)
}
+ private val isPartial = context.configuration.delayTemplateSubstitution
}
fun List<SimpleAttr>.joinAttr() = joinToString(" ") { it.extraKey + "=" + it.extraValue }
diff --git a/plugins/base/src/test/kotlin/renderers/html/BasicTest.kt b/plugins/base/src/test/kotlin/renderers/html/BasicTest.kt
new file mode 100644
index 00000000..fbcdf70e
--- /dev/null
+++ b/plugins/base/src/test/kotlin/renderers/html/BasicTest.kt
@@ -0,0 +1,20 @@
+package renderers.html
+
+import org.jetbrains.dokka.base.renderers.html.HtmlRenderer
+import org.jetbrains.dokka.links.DRI
+import org.junit.jupiter.api.Test
+import renderers.testPage
+import utils.Span
+import utils.match
+
+class BasicTest : HtmlRenderingOnlyTestBase() {
+ @Test
+ fun `unresolved DRI link should render as text`() {
+ val page = testPage {
+ link("linkText", DRI("nonexistentPackage", "nonexistentClass"))
+ }
+
+ HtmlRenderer(context).render(page)
+ renderedContent.match(Span("linkText"))
+ }
+}
diff --git a/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt b/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt
index 0d3763ee..71d141e2 100644
--- a/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt
+++ b/plugins/base/src/test/kotlin/renderers/html/HtmlRenderingOnlyTestBase.kt
@@ -62,26 +62,3 @@ abstract class HtmlRenderingOnlyTestBase : RenderingOnlyTestBase<Element>() {
.dropWhile { !it.contains("""<div id="content">""") }
.joinToString(separator = "") { it.trim() }
}
-
-fun Element.match(vararg matchers: Any): Unit =
- childNodes()
- .filter { it !is TextNode || it.text().isNotBlank() }
- .let { it.drop(it.size - matchers.size) }
- .zip(matchers)
- .forEach { (n, m) -> m.accepts(n) }
-
-open class Tag(val name: String, vararg val matchers: Any)
-class Div(vararg matchers: Any) : Tag("div", *matchers)
-class P(vararg matchers: Any) : Tag("p", *matchers)
-class Span(vararg matchers: Any) : Tag("span", *matchers)
-
-private fun Any.accepts(n: Node) {
- when (this) {
- is String -> assert(n is TextNode && n.text().trim() == this.trim()) { "\"$this\" expected but found: $n" }
- is Tag -> {
- assert(n is Element && n.tagName() == name) { "Tag $name expected but found: $n" }
- if (n is Element && matchers.isNotEmpty()) n.match(*matchers)
- }
- else -> throw IllegalArgumentException("$this is not proper matcher")
- }
-}