1
0
Fork 0

Compare commits

...

2 Commits

Author SHA1 Message Date
Ryan Fox 16eef14e04
Add support for custom emoji 2022-03-29 21:48:56 -07:00
Ryan Fox 291e0a8d75
Bump dependencies, I think
I absolutely plan to scrap this stupid NPM dependency. :-/
2022-03-29 21:47:22 -07:00
4 changed files with 38 additions and 6 deletions

View File

@ -27,9 +27,9 @@
"devDependencies": { "devDependencies": {
"elm": "^0.18.0", "elm": "^0.18.0",
"elm-live": "^2.7.4", "elm-live": "^2.7.4",
"elm-test": "^0.18.3", "elm-test": "^0.18.13",
"gh-pages": "^0.12.0", "gh-pages": "^0.12.0",
"rimraf": "^2.6.1", "rimraf": "^2.6.1",
"uglify-js": "^3.0.1" "uglify-js": "^3.15.3"
} }
} }

View File

@ -212,6 +212,8 @@ span.applink {
display: block; display: block;
float: left; float: left;
width: 50px; width: 50px;
height: 50px;
object-fit: cover;
border-radius: 50%; border-radius: 50%;
margin-top: 2px; margin-top: 2px;
} }
@ -1162,3 +1164,9 @@ audio.viewer-content {
height: 18px; height: 18px;
margin: 0 1px; margin: 0 1px;
} }
.emoji-custom {
width: 24px;
height: 24px;
vertical-align: bottom;
}

View File

@ -396,7 +396,7 @@ accountView subView currentUser accountInfo =
else else
text "" text ""
] ]
, span [ class "account-note" ] (formatContent account.note [] []) , span [ class "account-note" ] (formatContent account.note [] account.emojis)
] ]
] ]
, fields subView account , fields subView account

View File

@ -1,7 +1,6 @@
module View.Formatter exposing (formatContent, textContent) module View.Formatter exposing (formatContent, textContent)
import Dict import Dict
import Elmoji
import Html exposing (..) import Html exposing (..)
import Html.Attributes exposing (..) import Html.Attributes exposing (..)
import HtmlParser import HtmlParser
@ -11,6 +10,8 @@ import Mastodon.Model exposing (..)
import String.Extra exposing (replace, rightOf) import String.Extra exposing (replace, rightOf)
import Types exposing (..) import Types exposing (..)
import View.Events exposing (..) import View.Events exposing (..)
import Regex
import Json.Encode
formatContent : String -> List Mention -> List Emoji -> List (Html Msg) formatContent : String -> List Mention -> List Emoji -> List (Html Msg)
@ -119,9 +120,32 @@ toVirtualDomEach mentions emoji node =
text "" text ""
-- VERY janky.
handleEmoji : String -> List Emoji -> Html Msg handleEmoji : String -> List Emoji -> Html Msg
handleEmoji s emoji = handleEmoji s emojis =
Elmoji.text_ s -- todo span [ property "innerHTML" <| Json.Encode.string <| Regex.replace Regex.All shortcodeRegex (\{match} -> displayEmoji match emojis) <| s ] []
displayEmoji : String -> List Emoji -> String
displayEmoji s emojis =
case (lookupEmoji (String.slice 1 -1 s) emojis) of
Just emoji ->
"<img src=\""++emoji.url++"\" title=\""++s++"\" class=\"emoji-custom\">"
Nothing ->
s
lookupEmoji : String -> List Emoji -> Maybe Emoji
lookupEmoji shortcode emojis =
emojis
|> List.filter (\m -> m.shortcode == shortcode)
|> List.head
shortcodeRegex : Regex.Regex
shortcodeRegex =
Regex.regex ":[^:]*(?:::]*)*:"
toAttribute : ( String, String ) -> Attribute msg toAttribute : ( String, String ) -> Attribute msg