mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-23 22:26:16 +03:00
32 lines
985 B
Elm
32 lines
985 B
Elm
module HtmlPrinter exposing (htmlToString)
|
|
|
|
import Html exposing (Html)
|
|
import Json.Decode as Decode
|
|
import Json.Encode
|
|
import Test.Html.Internal.ElmHtml.InternalTypes exposing (decodeElmHtml)
|
|
import Test.Html.Internal.ElmHtml.ToString exposing (defaultFormatOptions, nodeToStringWithOptions)
|
|
import VirtualDom
|
|
|
|
|
|
htmlToString : Maybe { indent : Int, newLines : Bool } -> Html msg -> String
|
|
htmlToString formatOptions viewHtml =
|
|
case
|
|
Decode.decodeValue
|
|
(decodeElmHtml (\_ _ -> VirtualDom.Normal (Decode.succeed ())))
|
|
(asJsonView viewHtml)
|
|
of
|
|
Ok str ->
|
|
nodeToStringWithOptions
|
|
(formatOptions
|
|
|> Maybe.withDefault defaultFormatOptions
|
|
)
|
|
str
|
|
|
|
Err err ->
|
|
"Error pre-rendering HTML in HtmlPrinter.elm: " ++ Decode.errorToString err
|
|
|
|
|
|
asJsonView : Html msg -> Decode.Value
|
|
asJsonView x =
|
|
Json.Encode.string "REPLACE_ME_WITH_JSON_STRINGIFY"
|