From 590764adc4d54676d4d809accbbe4ac329ce5048 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 20 Dec 2018 22:59:31 -0800 Subject: [PATCH] Add markdown rendering for messages that have it. --- elm.json | 7 +++++-- src/Scylla/Views.elm | 10 +++++++++- static/scss/style.scss | 6 ++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/elm.json b/elm.json index 5e7c3b3..4a3eb06 100644 --- a/elm.json +++ b/elm.json @@ -15,11 +15,14 @@ "elm/json": "1.1.2", "elm/svg": "1.0.1", "elm/time": "1.0.0", - "elm/url": "1.0.0" + "elm/url": "1.0.0", + "hecrj/html-parser": "2.0.0" }, "indirect": { "elm/bytes": "1.0.7", - "elm/virtual-dom": "1.0.2" + "elm/parser": "1.1.0", + "elm/virtual-dom": "1.0.2", + "rtfeldman/elm-hex": "1.0.0" } }, "test-dependencies": { diff --git a/src/Scylla/Views.elm b/src/Scylla/Views.elm index 2649ca9..f3d48ce 100644 --- a/src/Scylla/Views.elm +++ b/src/Scylla/Views.elm @@ -6,6 +6,8 @@ import Scylla.Fnv as Fnv import Scylla.Login exposing (Username) import Scylla.Http exposing (fullMediaUrl) import Scylla.Api exposing (ApiUrl) +import Html.Parser +import Html.Parser.Util import Svg import Svg.Attributes import Url.Builder @@ -195,9 +197,15 @@ messageTextView : Model -> RoomEvent -> Maybe (Html Msg) messageTextView m re = let body = Decode.decodeValue (Decode.field "body" Decode.string) re.content + customHtml = Maybe.map Html.Parser.Util.toVirtualDom + <| Maybe.andThen (Result.toMaybe << Html.Parser.run ) + <| Result.toMaybe + <| Decode.decodeValue (Decode.field "formatted_body" Decode.string) re.content wrap mtext = span [] [ text mtext ] in - Maybe.map wrap <| Result.toMaybe body + case customHtml of + Just c -> Just <| div [ class "markdown-wrapper" ] c + Nothing -> Maybe.map wrap <| Result.toMaybe body messageImageView : Model -> RoomEvent -> Maybe (Html Msg) messageImageView m re = diff --git a/static/scss/style.scss b/static/scss/style.scss index 5d9f203..a4a47b1 100644 --- a/static/scss/style.scss +++ b/static/scss/style.scss @@ -184,6 +184,12 @@ table.events-table { } } +div.markdown-wrapper { + p { + margin: 0px; + } +} + span.sender-wrapper { border-radius: 2px; padding-left: 5px;