From 581d064dc1fba01fd27f560e158df48498c7e776 Mon Sep 17 00:00:00 2001 From: Marcin Aman Date: Wed, 2 Sep 2020 17:40:21 +0200 Subject: Let markdown display img like resources correctly --- plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt | 6 ++++++ plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt | 4 ++-- plugins/gfm/src/main/kotlin/GfmPlugin.kt | 6 +++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt index 3d0ced06..47180042 100644 --- a/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt @@ -15,6 +15,7 @@ import org.jetbrains.dokka.plugability.plugin import org.jetbrains.dokka.plugability.querySingle import org.jetbrains.dokka.renderers.Renderer import org.jetbrains.dokka.transformers.pages.PageTransformer +import java.io.File abstract class DefaultRenderer( protected val context: DokkaContext @@ -223,3 +224,8 @@ internal typealias SerializedBeforeAndAfter = Pair internal typealias InstanceWithSource = Pair fun ContentPage.sourceSets() = this.content.sourceSets + +fun ContentEmbeddedResource.isImage(): Boolean { + val imageExtensions = setOf("png", "jpg", "jpeg", "gif", "bmp", "tif", "webp", "svg") + return File(address).extension.toLowerCase() in imageExtensions +} \ No newline at end of file diff --git a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt index 83af968d..e10672a6 100644 --- a/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt +++ b/plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt @@ -9,6 +9,7 @@ import org.jetbrains.dokka.DokkaSourceSetID import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.renderers.DefaultRenderer import org.jetbrains.dokka.base.renderers.TabSortingStrategy +import org.jetbrains.dokka.base.renderers.isImage import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.DisplaySourceSet import org.jetbrains.dokka.model.properties.PropertyContainer @@ -346,8 +347,7 @@ open class HtmlRenderer( node: ContentEmbeddedResource, pageContext: ContentPage ) { // TODO: extension point there - val imageExtensions = setOf("png", "jpg", "jpeg", "gif", "bmp", "tif", "webp", "svg") - return if (File(node.address).extension.toLowerCase() in imageExtensions) { + return if (node.isImage()) { //TODO: add imgAttrs parsing val imgAttrs = node.extra.allOfType().joinAttr() img(src = node.address, alt = node.altText) diff --git a/plugins/gfm/src/main/kotlin/GfmPlugin.kt b/plugins/gfm/src/main/kotlin/GfmPlugin.kt index 65723a0c..0376b32e 100644 --- a/plugins/gfm/src/main/kotlin/GfmPlugin.kt +++ b/plugins/gfm/src/main/kotlin/GfmPlugin.kt @@ -7,6 +7,7 @@ import org.jetbrains.dokka.base.DokkaBase import org.jetbrains.dokka.base.renderers.DefaultRenderer import org.jetbrains.dokka.base.renderers.PackageListCreator import org.jetbrains.dokka.base.renderers.RootCreator +import org.jetbrains.dokka.base.renderers.isImage import org.jetbrains.dokka.base.resolvers.local.DokkaLocationProvider import org.jetbrains.dokka.base.resolvers.local.LocationProviderFactory import org.jetbrains.dokka.model.DisplaySourceSet @@ -155,7 +156,10 @@ open class CommonmarkRenderer( } override fun StringBuilder.buildResource(node: ContentEmbeddedResource, pageContext: ContentPage) { - append("Resource") + if(node.isImage()){ + append("!") + } + append("[${node.altText}](${node.address})") } override fun StringBuilder.buildTable( -- cgit