This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.

ElmHtml.Markdown

Markdown helpers

type alias MarkdownOptions = { githubFlavored : Maybe { tables : Bool, breaks : Bool } , defaultHighlighting : Maybe String , sanitize : Bool , smartypants : Bool }

options markdown expects

type alias MarkdownModel = { options : MarkdownOptions , markdown : String }

An internal markdown model. Options are the things you give markdown, markdown is the string

baseMarkdownModel : MarkdownModel

Just a default markdown model

encodeOptions : MarkdownOptions -> Json.Decode.Value

We don't really care about encoding options right now TODO: we will if we want to represent things as we do for elm-html

encodeMarkdownModel : MarkdownModel -> Json.Decode.Value

encode markdown model

decodeMarkdownModel : Json.Decode.Decoder MarkdownModel

decode a markdown model

module ElmHtml.Markdown exposing (..)

{-| Markdown helpers

@docs MarkdownOptions, MarkdownModel, baseMarkdownModel

@docs encodeOptions, encodeMarkdownModel, decodeMarkdownModel

-}

import Json.Encode
import Json.Decode exposing (field)


{-| Just a default markdown model
-}
baseMarkdownModel : MarkdownModel
baseMarkdownModel =
    { options =
        { githubFlavored = Just { tables = False, breaks = False }
        , defaultHighlighting = Nothing
        , sanitize = False
        , smartypants = False
        }
    , markdown = ""
    }


{-| options markdown expects
-}
type alias MarkdownOptions =
    { githubFlavored : Maybe { tables : Bool, breaks : Bool }
    , defaultHighlighting : Maybe String
    , sanitize : Bool
    , smartypants : Bool
    }


{-| An internal markdown model. Options are the things you give markdown, markdown is the string
-}
type alias MarkdownModel =
    { options : MarkdownOptions
    , markdown : String
    }


{-| We don't really care about encoding options right now
TODO: we will if we want to represent things as we do for elm-html
-}
encodeOptions : MarkdownOptions -> Json.Decode.Value
encodeOptions options =
    Json.Encode.null


{-| encode markdown model
-}
encodeMarkdownModel : MarkdownModel -> Json.Decode.Value
encodeMarkdownModel model =
    Json.Encode.object
        [ ( "options", encodeOptions model.options )
        , ( "markdown", Json.Encode.string model.markdown )
        ]


{-| decode a markdown model
-}
decodeMarkdownModel : Json.Decode.Decoder MarkdownModel
decodeMarkdownModel =
    field "markdown" Json.Decode.string
        |> Json.Decode.map (MarkdownModel baseMarkdownModel.options)