kotmark

A Markdown engine
Kotlin Multiplatform

Guide / HTML destinations

URL resolution

URL resolution runs while rendering HTML, after parsing, and never mutates the AST.

Resolve against a base URL

The base URI resolver follows RFC 3986 path resolution and leaves destinations with a scheme unchanged.

Base URL resolution
import io.heapy.kotmark.renderer.html.BaseUriUrlResolver
import io.heapy.kotmark.renderer.html.htmlRenderer

val baseUrlRenderer = htmlRenderer {
    urlResolver = BaseUriUrlResolver(
        baseUri = "https://example.org/docs/guide/",
        resolveLocalAnchors = false,
    )
    sanitizeUrls = true
    percentEncodeUrls = true
}
// ../images/example.png -> https://example.org/docs/images/example.png
INPUT · Markdown
![Example](../images/example.png) [Top](#top)
OUTPUT · HTML
<p><img src="https://example.org/docs/images/example.png" alt="Example" /> <a rel="nofollow" href="#top">Top</a></p>

Processing order

Core links, reference links, autolinks, and images go through resolve, optional sanitize, optional percent-encode, then HTML attribute escaping.

  • Raw HTML is not affected.
  • A fragment-only destination remains local by default.
  • With urlResolver = null, rendering is unchanged.