Simple library to generate markdown from kotlin.
The design on generator bases on two building blocks:
- Markdown document is a sequence of independent paragraphs
- Each paragraph consists of a sequence of lines (also called items)
The standard way of generating something in Kotlin is usage of builder pattern and the library is trying to follow this idea.
It allows transform code like:
val doc = Md.generate {
title { +"My Markdown Document" }
h(2) { +"Introduction" }
p { +"This is a small test of how it looks like."; br(); +"Text on a new line." }
itemize {
item {
+"Just an item " + link("link 1", "url1")
}
}
enumerate {
item {
+"Just an enumerated item " + image("link 2", "url2", "link 2")
}
}
blockquote {
item {
+"Blockquote line " + link("link 3", "url2", "link 2")
}
item {
+"Another Blockquote line"
}
}
code("kotlin") {
"""
fun someCode(): String {
Just an example of code
}
""".trimIndent()
}
}
return doc.asString()
into
This is a small test of how it looks like. Text on a new line.
- Just an item link 1
Blockquote line link 3 Another Blockquote line
fun someCode(): String {
Just an example of code
}
dependencies {
implementation("com.github.kokorins:markdown-generator:<version>")
}