From 9753efe7e8d573a66e5b26ff7ba7688c0582672b Mon Sep 17 00:00:00 2001 From: Nicolas Perriault Date: Sat, 13 May 2017 11:21:29 +0200 Subject: [PATCH] Fix #27: Render universal emojis. --- elm-package.json | 1 + public/style.css | 8 ++++++++ src/View/Formatter.elm | 37 +++++++++++++++++-------------------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/elm-package.json b/elm-package.json index 7ddb9db..1855ba5 100644 --- a/elm-package.json +++ b/elm-package.json @@ -22,6 +22,7 @@ "jinjor/elm-html-parser": "1.1.5 <= v < 2.0.0", "lukewestby/elm-http-builder": "5.1.0 <= v < 6.0.0", "rluiten/elm-date-extra": "8.5.0 <= v < 9.0.0", + "teepark/elmoji": "2.0.2 <= v < 3.0.0", "thebritican/elm-autocomplete": "4.0.3 <= v < 5.0.0" }, "elm-version": "0.18.0 <= v < 0.19.0" diff --git a/public/style.css b/public/style.css index 12b6c36..d484732 100644 --- a/public/style.css +++ b/public/style.css @@ -810,3 +810,11 @@ input.form-control[type=file] { .modal-content { flex: 1 1 auto; } + +/* Emojis */ + +.elmoji-img { + width: 18px; + height: 18px; + margin-right: 1px; +} diff --git a/src/View/Formatter.elm b/src/View/Formatter.elm index 3234554..bf0613d 100644 --- a/src/View/Formatter.elm +++ b/src/View/Formatter.elm @@ -1,5 +1,6 @@ module View.Formatter exposing (formatContent) +import Elmoji import Html exposing (..) import Html.Attributes exposing (..) import HtmlParser @@ -32,31 +33,27 @@ toVirtualDom mentions nodes = createLinkNode : List ( String, String ) -> List HtmlParser.Node -> List Mention -> Html Msg createLinkNode attrs children mentions = - let - maybeMention = - getMentionForLink attrs mentions - in - case maybeMention of - Just mention -> - Html.node "a" - ((List.map toAttribute attrs) - ++ [ onClickWithPreventAndStop (LoadAccount mention.id) ] - ) - (toVirtualDom mentions children) + case (getMentionForLink attrs mentions) of + Just mention -> + Html.node "a" + ((List.map toAttribute attrs) + ++ [ onClickWithPreventAndStop (LoadAccount mention.id) ] + ) + (toVirtualDom mentions children) - Nothing -> - Html.node "a" - ((List.map toAttribute attrs) - ++ [ onClickWithStop NoOp, target "_blank" ] - ) - (toVirtualDom mentions children) + Nothing -> + Html.node "a" + ((List.map toAttribute attrs) + ++ [ onClickWithStop NoOp, target "_blank" ] + ) + (toVirtualDom mentions children) getHrefLink : List ( String, String ) -> Maybe String getHrefLink attrs = attrs - |> List.filter (\( name, value ) -> (name == "href")) - |> List.map (\( name, value ) -> value) + |> List.filter (\( name, _ ) -> name == "href") + |> List.map (\( _, value ) -> value) |> List.head @@ -82,7 +79,7 @@ toVirtualDomEach mentions node = Html.node name (List.map toAttribute attrs) (toVirtualDom mentions children) HtmlParser.Text s -> - text s + Elmoji.text_ s HtmlParser.Comment _ -> text ""