From 657132814d4e3adfe803e92f424ccdd43acbc257 Mon Sep 17 00:00:00 2001
From: "Bill St. Clair" "
- |> String.split "\n"
- |> String.join " " ++ String.join " " strings ++ " " html then
+ html
+
+ else
+ (" " ++ html ++ "
"
+ |> wrapPs
+
+
+wrapPs : List String -> String
+wrapPs strings =
+ newlinesToBrs <|
+ case strings of
+ [] ->
+ ""
+
+ _ ->
+ "
"
htmlBodyElements : Style -> Float -> String -> List (Element Msg)
htmlBodyElements style baseFontSize html =
+ case HP.run <| fixBareHtml html of
+ Ok res ->
+ List.map (nodeToElements style baseFontSize) res
+ |> List.concat
+
+ Err _ ->
+ oldHtmlBodyElements style baseFontSize (Debug.log "oldHtmlBodyElements" html)
+
+
+{-| The Popular feed currently doesn't really ship Html in body\_html.
+-}
+fixBareHtml : String -> String
+fixBareHtml html =
+ if String.startsWith "
" + |> Debug.log "fixBareHtml" + + +nodeToElements : Style -> Float -> HP.Node -> List (Element msg) +nodeToElements style baseFontSize theNode = + let + recurse node = + case node of + HP.Text string -> + -- Shouldn't get these from the parser + if string == "\n" then + [ text "" ] + + else + Parsers.parseElements style string + + HP.Element element attributes nodes -> + let + mappedNodes = + List.map recurse nodes + |> List.concat + in + case element of + "p" -> + [ paragraph + [ --paragraphPadding + paragraphLineSpacing baseFontSize + ] + mappedNodes + ] + + "br" -> + -- probably wrong + [ row [] mappedNodes ] + + "blockquote" -> + -- Needs a background color + [ row + [ paddingEach { zeroes | left = 10, right = 10 } + , Border.width 2 + , Border.color colors.black + ] + mappedNodes + ] + + "strong" -> + List.map (\n -> el [ Font.bold ] n) mappedNodes + + "em" -> + List.map (\n -> el [ Font.italic ] n) mappedNodes + + "u" -> + List.map (\n -> el [ Font.underline ] n) mappedNodes + + _ -> + -- Shouldn't happen + mappedNodes + + _ -> + [] + in + recurse theNode + + +oldHtmlBodyElements : Style -> Float -> String -> List (Element Msg) +oldHtmlBodyElements style baseFontSize html = let par : List (Element Msg) -> Element Msg par elements =