diff options
author | Błażej Kardyś <bkardys@virtuslab.com> | 2021-01-05 17:59:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-05 17:59:38 +0100 |
commit | 1618e552c136e25d86bf0708e0d760841c77c139 (patch) | |
tree | c608ce91b020bb0ecbfe75d0f456a0eae84b4c51 /plugins/all-modules-page/src/main/kotlin/ResolveLinkCommandHandler.kt | |
parent | ef98e4b6505c3fdd192b1d5057c718079d27b972 (diff) | |
download | dokka-1618e552c136e25d86bf0708e0d760841c77c139.tar.gz dokka-1618e552c136e25d86bf0708e0d760841c77c139.tar.bz2 dokka-1618e552c136e25d86bf0708e0d760841c77c139.zip |
Versioning (#1654)
* Adding versioning mechanism for multimodule
* Versioning improvement
* Refactor configuration, add ordering
* Fix integration tests
* Change packages, unignore test
Co-authored-by: Marcin Aman <marcin.aman@gmail.com>
Diffstat (limited to 'plugins/all-modules-page/src/main/kotlin/ResolveLinkCommandHandler.kt')
-rw-r--r-- | plugins/all-modules-page/src/main/kotlin/ResolveLinkCommandHandler.kt | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/plugins/all-modules-page/src/main/kotlin/ResolveLinkCommandHandler.kt b/plugins/all-modules-page/src/main/kotlin/ResolveLinkCommandHandler.kt new file mode 100644 index 00000000..e881a5ab --- /dev/null +++ b/plugins/all-modules-page/src/main/kotlin/ResolveLinkCommandHandler.kt @@ -0,0 +1,45 @@ +package org.jetbrains.dokka.allModulesPage + +import org.jetbrains.dokka.base.templating.Command +import org.jetbrains.dokka.base.templating.ResolveLinkCommand +import org.jetbrains.dokka.plugability.DokkaContext +import org.jetbrains.dokka.plugability.plugin +import org.jetbrains.dokka.plugability.querySingle +import org.jetbrains.dokka.templates.CommandHandler +import org.jsoup.nodes.Attributes +import org.jsoup.nodes.Element +import org.jsoup.parser.Tag +import java.io.File + +class ResolveLinkCommandHandler(context: DokkaContext) : CommandHandler { + + private val externalModuleLinkResolver = + context.plugin<AllModulesPagePlugin>().querySingle { externalModuleLinkResolver } + + override fun handleCommand(element: Element, command: Command, input: File, output: File) { + command as ResolveLinkCommand + val link = externalModuleLinkResolver.resolve(command.dri, output) + if (link == null) { + val children = element.childNodes().toList() + val attributes = Attributes().apply { + put("data-unresolved-link", command.dri.toString()) + } + val el = Element(Tag.valueOf("span"), "", attributes).apply { + children.forEach { ch -> appendChild(ch) } + } + element.replaceWith(el) + return + } + + val attributes = Attributes().apply { + put("href", link) + } + val children = element.childNodes().toList() + val el = Element(Tag.valueOf("a"), "", attributes).apply { + children.forEach { ch -> appendChild(ch) } + } + element.replaceWith(el) + } + + override fun canHandle(command: Command): Boolean = command is ResolveLinkCommand +}
\ No newline at end of file |