land.sungbin.gfm.markdown.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gfm-dsl Show documentation
Show all versions of gfm-dsl Show documentation
GitHub Flavored Markdown builder with Kotlin DSL
The newest version!
/*
* Designed and developed by Martin Macheiner and Ji Sungbin, 2022
*
* Licensed under the MIT.
* Please see full license: https://github.com/duckie-team/GfmDsl/blob/master/LICENSE
*/
package land.sungbin.gfm
import land.sungbin.gfm.tag.text
public class Markdown @PublishedApi internal constructor() {
private val contents = mutableListOf()
public operator fun MarkdownTag.unaryPlus() {
contents.add(this)
}
public operator fun String.unaryPlus() {
contents.add(text(this))
}
public override fun toString(): String = contents.joinToString(
separator = "\n",
) { tag ->
"${tag.content()}\n"
}
}
public inline fun markdown(@GfmDsl block: Markdown.() -> Unit): Markdown {
return Markdown().apply(block)
}