kotmark

A Markdown engine
Kotlin Multiplatform

Extension 11 / kotmark-ext-task-list-items

Task list items

Task states are represented in the AST and rendered as disabled checkbox inputs by the HTML renderer.

Artifact
io.heapy.kotmark:kotmark-ext-task-list-items:0.1.0
Package
io.heapy.kotmark.ext.task.list.items

Usage

Enable task-list items
import io.heapy.kotmark.ext.task.list.items.taskListItems
import io.heapy.kotmark.extensions
import io.heapy.kotmark.parser.parser
import io.heapy.kotmark.renderer.html.htmlRenderer

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

Example

INPUT · Markdown
- [x] Parse
- [ ] Render
OUTPUT · HTML
<ul>
<li><input type="checkbox" disabled="" checked=""> Parse</li>
<li><input type="checkbox" disabled=""> Render</li>
</ul>

Output

The renderer marks the checkbox as checked or unchecked and disables it by default, keeping the checklist display-only.