arowM/elm-markdown-builder/3.1.0

NOTE: the latest version is 3.1.2

MarkdownBuilder

This library helps your library or application to generate valid markdown document programmatically.

Builder

type Builder parent elem

Markdown builder. You can build a valid markdown structure programmatically in your program:

import MarkdownAst as Ast


myMarkdown : Ast.Section
myMarkdown =
    root
        { title = "Markdown Builder"
        }
        |> editBody
        |> appendParagraph
            [ Ast.PlainText "Markdown Builder builds "
            , Ast.Emphasis "Markdown"
            , Ast.PlainText " programmatically."
            ]
        |> endAppendMode
        |> appendChildSection
            { title = "Builder"
            }
        |> editBody
        |> appendUnorderedList
        |> appendListItem
            [ Ast.PlainText "List Item 1"
            ]
        |> appendOrderedList
        |> appendListItem
            [ Ast.PlainText "Child item"
            ]
        |> break
        |> break
        |> break
        |> appendListItem
            [ Ast.PlainText "List Item 2"
            ]
        |> appendParagraph
            [ Ast.PlainText "Child paragraph."
            ]
        |> appendCodeBlock
            """elm
            type Builder parent elem =
                ...
                ...
            """
        |> break
        |> appendListItem
            [ Ast.PlainText "List Item 3"
            ]
        |> run


Ast.render myMarkdown
    |> String.lines
--> [ "# Markdown Builder"
--> , ""
--> , "Markdown Builder builds *Markdown* programmatically."
--> , ""
--> , "## Builder"
--> , ""
--> , "* List Item 1"
--> , "    1. Child item"
--> , "* List Item 2"
--> , ""
--> , "    Child paragraph."
--> , ""
--> , "    ```elm"
--> , "    type Builder parent elem ="
--> , "        ..."
--> , "        ..."
--> , "    ```"
--> , "* List Item 3"
--> ]
break : Builder (Builder parent child) a -> Builder parent child

Quit editing current child, and return to edit its parent.

Root

type Root

Represents markdown root.

root : { title : String } -> Builder Root Section

Entry point for building markdown.

run : Builder parent a -> Section

Quit modifying markdown, and compile it to the valid markdown structure.

Section

type Section

Builder for section.

Start Append Mode for editing section body.

Append new child section to the current section, and change focus to the new one.

List Block

Builder for a list block.

Builder for items in a list block.

Append a list item, and change focus to it.

General Modifiers

Append Mode

type AppendMode a

Represents that a is in the Append Mode, which enalbes you to append some blocks to it.

endAppendMode : Builder parent (AppendMode a) -> Builder parent a

End append mode.

List InlineElement
-> Builder parent (AppendMode a)
-> Builder parent (AppendMode a)

Append a paragraph block.

Append a quote block, and focus it.

Append an ordered list block, and change focus to it.

Append an unordered list block, and change focus to it.

String
-> Builder parent (AppendMode a)
-> Builder parent (AppendMode a)

Append a code block.

Elm code:

appendCodeBlock
    """elm
    appendCodeBlock
        = Debug.todo ""
    """

Generated markdown:

```elm
appendCodeBlock
    = Debug.todo ""
```
List BlockElement
-> Builder parent (AppendMode a)
-> Builder parent (AppendMode a)

Lower level API to append BlockElement.