
CommonMark-compliant Markdown parser and renderer offering AST access for inspection and manipulation, extensible with GFM-style extensions (tables, strikethrough, autolink), outputs HTML, Markdown, or plain text.
A Kotlin Multiplatform library for parsing and rendering Markdown text according to the CommonMark specification.
This project is a Kotlin Multiplatform port of commonmark-java. Thanks to the commonmark-java team for creating such an excellent library — commonmark-kotlin would not exist without their work.
| Platform | Targets |
|---|---|
| Android |
androidTarget (min SDK 24) |
| JVM |
jvm (Java 11+) |
| JS |
js (browser, Node.js) |
| Wasm |
wasmJs (browser) |
| iOS |
iosX64, iosArm64, iosSimulatorArm64
|
| macOS |
macosX64, macosArm64
|
| Linux | linuxX64 |
| Windows | mingwX64 |
Add the dependency to your project. The core module:
// build.gradle.kts
dependencies {
implementation("io.github.feiyin0719:commonmark:<version>")
}For extensions, add the corresponding artifact:
dependencies {
implementation("io.github.feiyin0719:commonmark-ext-gfm-tables:<version>")
}import org.commonmark.parser.Parser
import org.commonmark.renderer.html.HtmlRenderer
val parser = Parser.builder().build()
val document = parser.parse("This is *Markdown*")
val renderer = HtmlRenderer.builder().build()
val html = renderer.render(document)
// "<p>This is <em>Markdown</em></p>\n"import org.commonmark.renderer.markdown.MarkdownRenderer
val renderer = MarkdownRenderer.builder().build()
val markdown = renderer.render(document)import org.commonmark.renderer.text.TextContentRenderer
val renderer = TextContentRenderer.builder().build()
val text = renderer.render(document)import org.commonmark.ext.gfm.tables.TablesExtension
val extensions = listOf(TablesExtension.create())
val parser = Parser.builder().extensions(extensions).build()
val renderer = HtmlRenderer.builder().extensions(extensions).build()import org.commonmark.node.AbstractVisitor
import org.commonmark.node.Text
val visitor = object : AbstractVisitor() {
override fun visit(text: Text) {
println(text.literal)
}
}
document.accept(visitor)| Extension | Artifact | Description |
|---|---|---|
| Autolink | commonmark-ext-autolink |
Automatically turns URLs into links |
| Strikethrough | commonmark-ext-gfm-strikethrough |
GFM strikethrough (~~text~~) |
| Tables | commonmark-ext-gfm-tables |
GFM tables |
| Footnotes | commonmark-ext-footnotes |
Footnote references and definitions |
| Heading Anchor | commonmark-ext-heading-anchor |
Generates id attributes for headings |
| Ins | commonmark-ext-ins |
Inserted/underlined text (++text++) |
| Image Attributes | commonmark-ext-image-attributes |
Custom attributes on images |
| Task List Items | commonmark-ext-task-list-items |
Task lists (- [x] done) |
| YAML Front Matter | commonmark-ext-yaml-front-matter |
YAML metadata at the top of documents |
This project is a Kotlin Multiplatform port of commonmark-java. Huge thanks to the commonmark-java contributors for building a well-designed, spec-compliant Markdown parsing library that made this port possible.
MIT License - see LICENSE for details.
A Kotlin Multiplatform library for parsing and rendering Markdown text according to the CommonMark specification.
This project is a Kotlin Multiplatform port of commonmark-java. Thanks to the commonmark-java team for creating such an excellent library — commonmark-kotlin would not exist without their work.
| Platform | Targets |
|---|---|
| Android |
androidTarget (min SDK 24) |
| JVM |
jvm (Java 11+) |
| JS |
js (browser, Node.js) |
| Wasm |
wasmJs (browser) |
| iOS |
iosX64, iosArm64, iosSimulatorArm64
|
| macOS |
macosX64, macosArm64
|
| Linux | linuxX64 |
| Windows | mingwX64 |
Add the dependency to your project. The core module:
// build.gradle.kts
dependencies {
implementation("io.github.feiyin0719:commonmark:<version>")
}For extensions, add the corresponding artifact:
dependencies {
implementation("io.github.feiyin0719:commonmark-ext-gfm-tables:<version>")
}import org.commonmark.parser.Parser
import org.commonmark.renderer.html.HtmlRenderer
val parser = Parser.builder().build()
val document = parser.parse("This is *Markdown*")
val renderer = HtmlRenderer.builder().build()
val html = renderer.render(document)
// "<p>This is <em>Markdown</em></p>\n"import org.commonmark.renderer.markdown.MarkdownRenderer
val renderer = MarkdownRenderer.builder().build()
val markdown = renderer.render(document)import org.commonmark.renderer.text.TextContentRenderer
val renderer = TextContentRenderer.builder().build()
val text = renderer.render(document)import org.commonmark.ext.gfm.tables.TablesExtension
val extensions = listOf(TablesExtension.create())
val parser = Parser.builder().extensions(extensions).build()
val renderer = HtmlRenderer.builder().extensions(extensions).build()import org.commonmark.node.AbstractVisitor
import org.commonmark.node.Text
val visitor = object : AbstractVisitor() {
override fun visit(text: Text) {
println(text.literal)
}
}
document.accept(visitor)| Extension | Artifact | Description |
|---|---|---|
| Autolink | commonmark-ext-autolink |
Automatically turns URLs into links |
| Strikethrough | commonmark-ext-gfm-strikethrough |
GFM strikethrough (~~text~~) |
| Tables | commonmark-ext-gfm-tables |
GFM tables |
| Footnotes | commonmark-ext-footnotes |
Footnote references and definitions |
| Heading Anchor | commonmark-ext-heading-anchor |
Generates id attributes for headings |
| Ins | commonmark-ext-ins |
Inserted/underlined text (++text++) |
| Image Attributes | commonmark-ext-image-attributes |
Custom attributes on images |
| Task List Items | commonmark-ext-task-list-items |
Task lists (- [x] done) |
| YAML Front Matter | commonmark-ext-yaml-front-matter |
YAML metadata at the top of documents |
This project is a Kotlin Multiplatform port of commonmark-java. Huge thanks to the commonmark-java contributors for building a well-designed, spec-compliant Markdown parsing library that made this port possible.
MIT License - see LICENSE for details.