Skip to content

Latest commit

 

History

History
90 lines (66 loc) · 1.91 KB

README.md

File metadata and controls

90 lines (66 loc) · 1.91 KB

Markdown Generator in Kotlin

Java CI with Gradle

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


My Markdown Document

Introduction

This is a small test of how it looks like. Text on a new line.

  1. Just an enumerated item link 2

Blockquote line link 3 Another Blockquote line

fun someCode(): String {
    Just an example of code
}

Installation

dependencies {
    implementation("com.github.kokorins:markdown-generator:<version>")
}