aboutsummaryrefslogtreecommitdiff
path: root/plugins/gfm/src/main/kotlin
diff options
context:
space:
mode:
authorBłażej Kardyś <bkardys@virtuslab.com>2020-11-16 19:46:31 +0100
committerBłażej Kardyś <bkardys@virtuslab.com>2020-11-27 03:15:02 +0100
commit076a5f421c5e4621539efd814be612f43fef33f5 (patch)
tree90b399c459cccbd1e3010778320d49b7b806b1fb /plugins/gfm/src/main/kotlin
parentc203be9fb65ee221875b4e1c865bcd289a85e69c (diff)
downloaddokka-076a5f421c5e4621539efd814be612f43fef33f5.tar.gz
dokka-076a5f421c5e4621539efd814be612f43fef33f5.tar.bz2
dokka-076a5f421c5e4621539efd814be612f43fef33f5.zip
Adding inter-module link resolving template strategy for Gfm
Diffstat (limited to 'plugins/gfm/src/main/kotlin')
-rw-r--r--plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/gfmTemplating.kt19
-rw-r--r--plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/renderer/CommonmarkRenderer.kt15
2 files changed, 33 insertions, 1 deletions
diff --git a/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/gfmTemplating.kt b/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/gfmTemplating.kt
new file mode 100644
index 00000000..1473ceee
--- /dev/null
+++ b/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/gfmTemplating.kt
@@ -0,0 +1,19 @@
+package org.jetbrains.dokka.gfm
+
+import org.jetbrains.dokka.base.templating.toJsonString
+import org.jetbrains.dokka.links.DRI
+import com.fasterxml.jackson.annotation.JsonTypeInfo
+import com.fasterxml.jackson.annotation.JsonTypeInfo.Id.CLASS
+
+@JsonTypeInfo(use = CLASS)
+sealed class GfmCommand {
+ companion object {
+ private const val delimiter = "\u1680"
+ fun templateCommand(command: GfmCommand): String = "$delimiter GfmCommand ${toJsonString(command)}$delimiter"
+ val templateCommandRegex: Regex = Regex("$delimiter GfmCommand ([^$delimiter ]*)$delimiter")
+ }
+}
+
+class ResolveLinkGfmCommand(val dri: DRI): GfmCommand()
+
+
diff --git a/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/renderer/CommonmarkRenderer.kt b/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/renderer/CommonmarkRenderer.kt
index 0655ce20..25b24f0c 100644
--- a/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/renderer/CommonmarkRenderer.kt
+++ b/plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/renderer/CommonmarkRenderer.kt
@@ -3,7 +3,9 @@ package org.jetbrains.dokka.gfm.renderer
import org.jetbrains.dokka.DokkaException
import org.jetbrains.dokka.base.renderers.DefaultRenderer
import org.jetbrains.dokka.base.renderers.isImage
+import org.jetbrains.dokka.gfm.GfmCommand.Companion.templateCommand
import org.jetbrains.dokka.gfm.GfmPlugin
+import org.jetbrains.dokka.gfm.ResolveLinkGfmCommand
import org.jetbrains.dokka.model.DisplaySourceSet
import org.jetbrains.dokka.pages.*
import org.jetbrains.dokka.plugability.DokkaContext
@@ -80,6 +82,17 @@ open class CommonmarkRenderer(
}
}
+ override fun StringBuilder.buildDRILink(
+ node: ContentDRILink,
+ pageContext: ContentPage,
+ sourceSetRestriction: Set<DisplaySourceSet>?
+ ) {
+ val address = locationProvider.resolve(node.address, node.sourceSets, pageContext)
+ buildLink(address ?: templateCommand(ResolveLinkGfmCommand(node.address))) {
+ buildText(node.children, pageContext, sourceSetRestriction)
+ }
+ }
+
override fun StringBuilder.buildNewLine() {
append(" \n")
}
@@ -118,7 +131,7 @@ open class CommonmarkRenderer(
}
override fun StringBuilder.buildResource(node: ContentEmbeddedResource, pageContext: ContentPage) {
- if(node.isImage()){
+ if (node.isImage()) {
append("!")
}
append("[${node.altText}](${node.address})")