aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMarcin Aman <maman@virtuslab.com>2020-09-02 17:40:21 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-09-07 08:07:10 +0200
commit581d064dc1fba01fd27f560e158df48498c7e776 (patch)
treefd0babc209a7fe8af19c41a7b511a2a86d6d4440 /plugins
parent901343cc5c98dbf7f16f232c338487bfcea06790 (diff)
downloaddokka-581d064dc1fba01fd27f560e158df48498c7e776.tar.gz
dokka-581d064dc1fba01fd27f560e158df48498c7e776.tar.bz2
dokka-581d064dc1fba01fd27f560e158df48498c7e776.zip
Let markdown display img like resources correctly
Diffstat (limited to 'plugins')
-rw-r--r--plugins/base/src/main/kotlin/renderers/DefaultRenderer.kt6
-rw-r--r--plugins/base/src/main/kotlin/renderers/html/HtmlRenderer.kt4
-rw-r--r--plugins/gfm/src/main/kotlin/GfmPlugin.kt6
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<T>(
protected val context: DokkaContext
@@ -223,3 +224,8 @@ internal typealias SerializedBeforeAndAfter = Pair<String, String>
internal typealias InstanceWithSource = Pair<ContentDivergentInstance, DisplaySourceSet>
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<SimpleAttr>().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(