Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/paulschuberth/mdgen
A Kotlin DSL to generate basic Markdown files
https://github.com/paulschuberth/mdgen
dsl kotlin markdown
Last synced: 3 days ago
JSON representation
A Kotlin DSL to generate basic Markdown files
- Host: GitHub
- URL: https://github.com/paulschuberth/mdgen
- Owner: paulschuberth
- License: mit
- Created: 2022-11-19T20:23:40.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-21T02:40:15.000Z (10 days ago)
- Last Synced: 2024-12-23T06:14:55.595Z (8 days ago)
- Topics: dsl, kotlin, markdown
- Language: Kotlin
- Homepage: https://paulschuberth.github.io/mdgen/
- Size: 421 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# About
This is a tiny Kotlin DSL for creating Markdown files.
## Features
The DSL currently supports
- Headings
- Lists
- Code Blocks
### HeadingsHeadings can be created like by using the `section()` method
```kotlin
val md = Md(FileOutputStream(File("README.md")))md.start {
section {
+"This is a heading with one #"
}
}
```
Nesting `section()` methods automatically increases the number of # used for the heading
The following results in a # Heading and a ## Sub-Heading```kotlin
val md = Md(FileOutputStream(File("README.md")))md.start {
section {
+"Heading"
section {
+"Sub-Heading"
}
}
}
```
Headings will be put on the same level if their `section()` methods are called after one-another.```kotlin
val md = Md(FileOutputStream(File("README.md")))md.start {
section {
+"Heading"
}
section {
+"Another Heading"
}
}
```
### ListsLists can be created using the `list()` method. By default, ordered lists start at
index 1 and their elements are added with the unary plus operator.
Unordered list elements are added using the unaryMinus operator and use the asterisk (*).```kotlin
val md = Md(FileOutputStream(File("README.md")))md.start {
list {
+"First element"
+"Second element"
+"Third element"
}
list {
-"Foo"
-"Bar"
-"Baz"
}
}
```
Running the code above results in the following Markdown.1. First element
2. Second element
3. Third element
- Foo
- Bar
- Baz
### Code BlocksAt the moment this DSL only supports code fenced code blocks using three
backticks. An optional parameter can be used to specify the language of the code block.```kotlin
println("Hello World")
```
The listing above is created by this code.```kotlin
code("kotlin") {
"""
println("Hello World")
""".trimIndent()
}
```
Other languages can be specified by passing them in the first parameter.```rust
fn main() {
println!("Hello World!");
}
```
The listing above is created by this code.```kotlin
code("rust") {
"""
fn main() {
println!("Hello World!");
}
""".trimIndent()
}
```
### TablesTables can be created using the `table()` methods, which takes a variable amount of Strings for the headers of the table and as last parameter a lambda describing the table contents. Alternatively the table headers can be provided as Pairs of String to `MdTableHeader.Alignment` to configure the alignment of the content of a column.
This README.md is generated by the DSL as well. Take a look at
[ReadmeTest.kt](https://github.com/paulschuberth/mdgen/blob/main/src/test/kotlin/de/pschuberth/mdgen/ReadmeTest.kt) for details.| Hello | Beautiful | World |
|:------|:---------:|------:|
| Foo | Bar | Baz |The table above is created by the following code.
```kotlin
val md = Md(FileOutputStream(File("README.md")))
md.start {
table("Hello" to LEFT, "Beautiful" to CENTER, "World" to RIGHT) {
row {
+"Foo" + "Bar" + "Baz"
}
}
}
```