kotmark

A Markdown engine
Kotlin Multiplatform

Extension 08 / kotmark-ext-image-attributes

Image attributes

The extension recognizes a constrained attribute list so image sizing can be expressed next to the destination.

Artifact
io.heapy.kotmark:kotmark-ext-image-attributes:0.1.0
Package
io.heapy.kotmark.ext.image.attributes

Usage

Enable image attributes
import io.heapy.kotmark.ext.image.attributes.imageAttributes
import io.heapy.kotmark.extensions
import io.heapy.kotmark.parser.parser
import io.heapy.kotmark.renderer.html.htmlRenderer

fun renderWithImageAttributes(markdown: String): String {
    val extensions = extensions { imageAttributes() }
    val document = parser { extensions(extensions) }.parse(markdown)
    return htmlRenderer { extensions(extensions) }.render(document)
}

Example

INPUT · Markdown
![Logo](logo.svg){width=120 height=40}
OUTPUT · HTML
<p><img src="logo.svg" alt="Logo" width="120" height="40" /></p>

Supported values

The extension supports width, height, and class attributes. Renderers should apply these values as escaped attributes rather than interpolating them into markup.