From b072356193b98bd34c688c21611180ea68c7f32c Mon Sep 17 00:00:00 2001 From: Kamil Doległo Date: Wed, 29 Jul 2020 11:27:07 +0200 Subject: Wrap unresolved links in `span` with `data-unresolved-link` --- .../src/main/kotlin/renderers/DefaultRenderer.kt | 33 ++++++++++++++++------ .../src/main/kotlin/renderers/html/HtmlRenderer.kt | 14 +++++++++ 2 files changed, 38 insertions(+), 9 deletions(-) (limited to 'plugins') diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt index fe2913a4..d9ff924b 100644 --- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt @@ -108,15 +108,8 @@ abstract class DefaultRenderer( is ContentHeader -> buildHeader(node, pageContext, sourceSetRestriction) is ContentCodeBlock -> buildCodeBlock(node, pageContext) is ContentCodeInline -> buildCodeInline(node, pageContext) - is ContentDRILink -> - locationProvider.resolve(node.address, node.sourceSets, pageContext)?.let { address -> - buildLink(address) { - buildText(node.children, pageContext, sourceSetRestriction) - } - } ?: buildText(node.children, pageContext, sourceSetRestriction) - is ContentResolvedLink -> buildLink(node.address) { - buildText(node.children, pageContext, sourceSetRestriction) - } + is ContentDRILink -> buildDRILink(node, pageContext, sourceSetRestriction) + is ContentResolvedLink -> buildResolvedLink(node, pageContext, sourceSetRestriction) is ContentEmbeddedResource -> buildResource(node, pageContext) is ContentList -> buildList(node, pageContext, sourceSetRestriction) is ContentTable -> buildTable(node, pageContext, sourceSetRestriction) @@ -130,6 +123,28 @@ abstract class DefaultRenderer( } } + open fun T.buildDRILink( + node: ContentDRILink, + pageContext: ContentPage, + sourceSetRestriction: Set? + ) { + locationProvider.resolve(node.address, node.sourceSets, pageContext)?.let { address -> + buildLink(address) { + buildText(node.children, pageContext, sourceSetRestriction) + } + } ?: buildText(node.children, pageContext, sourceSetRestriction) + } + + open fun T.buildResolvedLink( + node: ContentResolvedLink, + pageContext: ContentPage, + sourceSetRestriction: Set? + ) { + buildLink(node.address) { + buildText(node.children, pageContext, sourceSetRestriction) + } + } + open fun T.buildDivergentInstance(node: ContentDivergentInstance, pageContext: ContentPage) { node.before?.build(this, pageContext) node.divergent.build(this, pageContext) diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 1a2a98b3..e3d54e49 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -563,6 +563,20 @@ open class HtmlRenderer( override fun FlowContent.buildLink(address: String, content: FlowContent.() -> Unit) = a(href = address, block = content) + + override fun FlowContent.buildDRILink( + node: ContentDRILink, + pageContext: ContentPage, + sourceSetRestriction: Set? + ) = locationProvider.resolve(node.address, node.sourceSets, pageContext)?.let { address -> + buildLink(address) { + buildText(node.children, pageContext, sourceSetRestriction) + } + } ?: span { + attributes["data-unresolved-link"] = "true" + buildText(node.children, pageContext, sourceSetRestriction) + } + override fun FlowContent.buildCodeBlock( code: ContentCodeBlock, pageContext: ContentPage -- cgit