diff options
Diffstat (limited to 'plugins/gfm/src/main')
-rw-r--r-- | plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/gfmTemplating.kt | 19 | ||||
-rw-r--r-- | plugins/gfm/src/main/kotlin/org/jetbrains/dokka/gfm/renderer/CommonmarkRenderer.kt | 15 |
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})") |