diff --git a/elm.json b/elm.json index 245387b..dcae2b6 100644 --- a/elm.json +++ b/elm.json @@ -12,6 +12,7 @@ "dependencies": { "elm/core": "1.0.0 <= v < 2.0.0", "elm/html": "1.0.0 <= v < 2.0.0", + "elm/json": "1.1.3 <= v < 2.0.0", "elm/parser": "1.0.0 <= v < 2.0.0", "elm/virtual-dom": "1.0.2 <= v < 2.0.0", "rtfeldman/elm-hex": "1.0.0 <= v < 2.0.0" diff --git a/src/Html/Parser/Util.elm b/src/Html/Parser/Util.elm index 2fd3d18..b698ca0 100644 --- a/src/Html/Parser/Util.elm +++ b/src/Html/Parser/Util.elm @@ -9,10 +9,10 @@ module Html.Parser.Util exposing (toVirtualDom) -} -import Html exposing (..) -import Html.Attributes exposing (..) +import Html exposing (Attribute, Html, text) +import Html.Attributes exposing (attribute, property) import Html.Parser exposing (Node(..)) -import VirtualDom +import Json.Encode as Encode {-| Converts nodes to virtual dom nodes. @@ -26,7 +26,18 @@ toVirtualDomEach : Node -> Html msg toVirtualDomEach node = case node of Element name attrs children -> - Html.node name (List.map toAttribute attrs) (toVirtualDom children) + Html.node name + (List.map + (case name of + "video" -> + toVideoAttribute + + _ -> + toAttribute + ) + attrs + ) + (toVirtualDom children) Text s -> text s @@ -38,3 +49,28 @@ toVirtualDomEach node = toAttribute : ( String, String ) -> Attribute msg toAttribute ( name, value ) = attribute name value + + +toVideoAttribute : ( String, String ) -> Attribute msg +toVideoAttribute ( name, value ) = + case name of + "muted" -> + stringToBool value + |> Encode.bool + |> property name + + _ -> + attribute name value + + +stringToBool : String -> Bool +stringToBool str = + case (String.trim >> String.toLower) str of + "false" -> + False + + "no" -> + False + + _ -> + True