kotmark

A Markdown engine
Kotlin Multiplatform

Extension 04 / kotmark-ext-gfm-strikethrough

GFM strikethrough

The extension can require paired tildes so a single tilde remains ordinary text.

Artifact
io.heapy.kotmark:kotmark-ext-gfm-strikethrough:0.1.0
Package
io.heapy.kotmark.ext.gfm.strikethrough

Usage

Set requireTwoTildes to require ~~text~~ instead of accepting single tildes.

Require two tildes
import io.heapy.kotmark.ext.gfm.strikethrough.strikethrough
import io.heapy.kotmark.extensions
import io.heapy.kotmark.parser.parser
import io.heapy.kotmark.renderer.html.htmlRenderer

fun renderWithStrikethrough(markdown: String): String {
    // With requireTwoTildes, a single ~ stays literal text.
    val extensions = extensions {
        strikethrough { requireTwoTildes = true }
    }
    val document = parser { extensions(extensions) }.parse(markdown)
    return htmlRenderer { extensions(extensions) }.render(document)
}

Example

INPUT · Markdown
~~Old~~ new, and ~one tilde~ stays.
OUTPUT · HTML
<p><del>Old</del> new, and ~one tilde~ stays.</p>

Output

The HTML renderer writes deleted text as <del>. The Markdown renderer retains the strikethrough delimiters.