Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/martouta/elm-emojis-converter
Elm package for converting text to HTML with emojis as Unicode or images.
https://github.com/martouta/elm-emojis-converter
Last synced: 4 days ago
JSON representation
Elm package for converting text to HTML with emojis as Unicode or images.
- Host: GitHub
- URL: https://github.com/martouta/elm-emojis-converter
- Owner: Martouta
- License: bsd-3-clause
- Created: 2022-12-15T17:53:59.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-15T23:53:46.000Z (about 2 years ago)
- Last Synced: 2024-04-21T07:15:50.713Z (9 months ago)
- Language: Elm
- Homepage: https://package.elm-lang.org/packages/martouta/elm-emojis-converter/1.0.0/
- Size: 29.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# elm-emojis-converter
📗 `elm-emojis-converter` is an [Elm](https://elm-lang.org/) package that converts text into HTML, replacing any emojis in the text with their corresponding Unicode characters (or HTML images for custom emojis). This allows you to easily include emojis in your Elm apps and have them display correctly in the browser.
⚠️ The main branch is used for development. It is not a stable branch for usage. Please, use a release instead. Preferably, the latest.
## Installation
To use `elm-emojis-converter` in your Elm project, add it to your `elm.json` dependencies:
```json
{
"dependencies": {
"martouta/elm-emojis-converter": "1.0.0"
}
}
```Then run `elm install` to download the package and its dependencies.
## Usage
Import the package and the necessary modules in your Elm code:
```elm
import EmojisConverter
```You could then use the exposed functions in your code by calling them with the appropriate arguments. For example, you could use the `textWithEmojis` function like this:
```elm
EmojisConverter.textWithEmojis "I'm feeling :smile: today!"
--> "I'm feeling 😄 today!"
```The `textWithEmojis` function converts the input `String` into a new `String` where common emoji shortcodes, such as :smile:, are replaced with their corresponding Unicode characters, such as 😄.
Similarly, you could use the `textWithUnicodesToHtmlNodes` function like this:
```elm
EmojisConverter.textWithUnicodesToHtmlNodes "Hello :orca:!"
--> [ Html.text "Hello ", Html.img [ src "https://openmoji.org/data/color/svg/E005.svg" ], Html.text "!" ]
```The `textWithUnicodesToHtmlNodes` function converts the input `String` into a list of HTML nodes where custom emoji shortcodes are replaced with the corresponding HTML image nodes. For example, the input string "Hello :orca:!" would be converted into a list containing the HTML nodes for the text "Hello ", the HTML image node for the orca emoji, and the HTML node for the exclamation mark "!".