Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/hlaueriksson/GEmojiSharp

:octocat: GitHub Emoji for C#, ASP.NET Core and Blazor, dotnet tool for the terminal and PowerToys Run plugin
https://github.com/hlaueriksson/GEmojiSharp

asp-net-core blazor csharp dotnet dotnet-tool emoji gemoji github powertoys-run

Last synced: 3 months ago
JSON representation

:octocat: GitHub Emoji for C#, ASP.NET Core and Blazor, dotnet tool for the terminal and PowerToys Run plugin

Lists

README

        

# GEmojiSharp :octocat:

[![Build status](https://github.com/hlaueriksson/GEmojiSharp/workflows/build/badge.svg)](https://github.com/hlaueriksson/GEmojiSharp/actions?query=workflow%3Abuild)
[![CodeFactor](https://www.codefactor.io/repository/github/hlaueriksson/gemojisharp/badge)](https://www.codefactor.io/repository/github/hlaueriksson/gemojisharp)

[![GEmojiSharp](https://img.shields.io/nuget/v/GEmojiSharp.svg?label=GEmojiSharp)](https://www.nuget.org/packages/GEmojiSharp)
[![GEmojiSharp.AspNetCore](https://img.shields.io/nuget/v/GEmojiSharp.AspNetCore.svg?label=GEmojiSharp.AspNetCore)](https://www.nuget.org/packages/GEmojiSharp.AspNetCore)
[![GEmojiSharp.Blazor](https://img.shields.io/nuget/v/GEmojiSharp.Blazor.svg?label=GEmojiSharp.Blazor)](https://www.nuget.org/packages/GEmojiSharp.Blazor)
[![GEmojiSharp.DotnetTool](https://img.shields.io/nuget/v/GEmojiSharp.DotnetTool.svg?label=GEmojiSharp.DotnetTool)](https://www.nuget.org/packages/GEmojiSharp.DotnetTool)

> GitHub Emoji for C# and .NET:
> - `netstandard2.0`
> - ASP.NET Core
> - Blazor
> - `dotnet` tool
> - PowerToys Run plugin

```txt
πŸ™ :octopus:
βž• :heavy_plus_sign:
🐈 :cat2:
β©΅
❀️ :heart:
```

## Content

- [Introduction](#introduction)
- [`GEmojiSharp`](#gemojisharp)
- [`GEmojiSharp.AspNetCore`](#gemojisharpaspnetcore)
- [TagHelpers](#taghelpers)
- [HtmlHelpers](#htmlhelpers)
- [`GEmojiSharp.Blazor`](#gemojisharpblazor)
- [`GEmojiSharp.DotnetTool`](#gemojisharpdotnettool)
- [Installation](#installation)
- [Usage](#usage)
- [`GEmojiSharp.PowerToysRun`](#gemojisharppowertoysrun)
- [Installation](#installation-1)
- [Usage](#usage-1)
- [Configuration](#configuration)
- [Samples](#samples)
- [Upgrading](#upgrading)
- [Attribution](#attribution)

## Introduction

[Using emoji](https://help.github.com/en/articles/basic-writing-and-formatting-syntax#using-emoji) on GitHub is accomplish with emoji aliases enclosed by colons:

`:+1: This PR looks great - it's ready to merge! :shipit:`

:+1: This PR looks great - it's ready to merge! :shipit:

`GEmojiSharp` make this possible in C#. The library contains a static array of all valid emoji in GitHub Flavored Markdown.
That is the intersection of the [emoji.json](https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json) database and the API with [available emojis](https://api.github.com/emojis).

A visual referense of all GitHub Emoji:

- https://github.com/hlaueriksson/github-emoji

## `GEmojiSharp`

[![NuGet](https://buildstats.info/nuget/GEmojiSharp)](https://www.nuget.org/packages/GEmojiSharp/)

> GitHub Emoji for C# and .NET πŸ“¦

Static methods:

```csharp
Emoji.Get(":tada:").Raw; // πŸŽ‰
Emoji.Get("πŸŽ‰").Alias(); // :tada:
Emoji.Raw(":tada:"); // πŸŽ‰
Emoji.Alias("πŸŽ‰"); // :tada:
Emoji.Emojify(":tada: initial commit"); // πŸŽ‰ initial commit
Emoji.Demojify("πŸŽ‰ initial commit"); // :tada: initial commit
Emoji.Find("party popper").First().Raw; // πŸŽ‰
Emoji.Get("✌️").RawSkinToneVariants(); // ✌🏻, ✌🏼, ✌🏽, ✌🏾, ✌🏿
```

Extension methods:

```csharp
":tada:".GetEmoji().Raw; // πŸŽ‰
"πŸŽ‰".GetEmoji().Alias(); // :tada:
":tada:".RawEmoji(); // πŸŽ‰
"πŸŽ‰".EmojiAlias(); // :tada:
":tada: initial commit".Emojify(); // πŸŽ‰ initial commit
"πŸŽ‰ initial commit".Demojify(); // :tada: initial commit
"party popper".FindEmojis().First().Raw; // πŸŽ‰
```

Regular expression pattern to match all emojis:

```csharp
var text = "Lorem πŸ˜‚πŸ˜‚ ipsum";

var matches = Regex.Matches(text, Emoji.RegexPattern);
string.Join(string.Empty, matches.Select(x => x.Value)); // πŸ˜‚πŸ˜‚

Regex.Replace(text, Emoji.RegexPattern, string.Empty); // Lorem ipsum
```

## `GEmojiSharp.AspNetCore`

[![NuGet](https://buildstats.info/nuget/GEmojiSharp.AspNetCore)](https://www.nuget.org/packages/GEmojiSharp.AspNetCore/)

> GitHub Emoji for ASP.NET Core πŸ“¦

The package includes:

- TagHelpers
- HtmlHelpers

### TagHelpers

Update the `_ViewImports.cshtml` file, to enable tag helpers in all Razor views:

```cshtml
@addTagHelper *, GEmojiSharp.AspNetCore
```

Use the `` tag or `emoji` attribute to render emojis:

```html

:tada: initial commit
```

Standard emoji characters are rendered like this:

```html
πŸŽ‰
```

Custom GitHub emojis are rendered as images:

```html
:octocat:
```

Use CSS to properly position the custom GitHub emojis images:

```css
.emoji {
background-color: transparent;
max-width: none;
vertical-align: text-top;
}
```

Use the JavaScript from [`g-emoji-element`](https://github.com/github/g-emoji-element) to support old browsers.

> Backports native emoji characters to browsers that don't support them by replacing the characters with fallback images.

Add a [`libman.json`](https://docs.microsoft.com/en-us/aspnet/core/client-side/libman/libman-vs?view=aspnetcore-6.0) file:

```json
{
"version": "1.0",
"defaultProvider": "cdnjs",
"libraries": [
{
"provider": "unpkg",
"library": "@github/[email protected]",
"destination": "wwwroot/lib/g-emoji-element/"
}
]
}
```

And add the script to the `_Layout.cshtml` file:

```html

```

Do you want to use emoji anywhere, on any tag, in the `body`? Then you can use the `BodyTagHelperComponent`.

Use any tag to render emojis:

```html

Hello, :earth_africa:


```

[Registration](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/th-components?view=aspnetcore-6.0#registration-via-services-container) via services container:

```cs
using GEmojiSharp.AspNetCore;
using Microsoft.AspNetCore.Razor.TagHelpers;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRazorPages();
builder.Services.AddTransient();
```

[Registration](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/th-components?view=aspnetcore-6.0#registration-via-razor-file) via Razor file:

```cshtml
@page
@model GEmojiSharp.Sample.Web.Pages.ComponentModel
@using Microsoft.AspNetCore.Mvc.Razor.TagHelpers
@using GEmojiSharp.AspNetCore
@inject ITagHelperComponentManager manager;
@{
ViewData["Title"] = "Component";
manager.Components.Add(new BodyTagHelperComponent());
}
```

[Registration](https://docs.microsoft.com/en-us/aspnet/core/mvc/views/tag-helpers/th-components?view=aspnetcore-6.0#registration-via-page-model-or-controller) via Page Model or controller:

```cs
using GEmojiSharp.AspNetCore;
using Microsoft.AspNetCore.Mvc.Razor.TagHelpers;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace GEmojiSharp.Sample.Web.Pages
{
public class ComponentModel : PageModel
{
private readonly ITagHelperComponentManager _tagHelperComponentManager;

public IndexModel(ITagHelperComponentManager tagHelperComponentManager)
{
_tagHelperComponentManager = tagHelperComponentManager;
}

public void OnGet()
{
_tagHelperComponentManager.Components.Add(new BodyTagHelperComponent());
}
}
}
```

### HtmlHelpers

Update the `_ViewImports.cshtml` file, to enable HTML helpers in all Razor views:

```cshtml
@using GEmojiSharp.AspNetCore
```

Use the `Emoji` extension methods to render emojis:

```cshtml
@Html.Emoji(":tada: initial commit")
@Html.Emoji(x => x.Text)
```

## `GEmojiSharp.Blazor`

[![NuGet](https://buildstats.info/nuget/GEmojiSharp.Blazor)](https://www.nuget.org/packages/GEmojiSharp.Blazor/)

> GitHub Emoji for Blazor πŸ“¦

The package is a Razor class library (RCL) with a Razor component.

Update the `_Imports.razor` file, to enable the component in all Razor views:

```cshtml
@using GEmojiSharp.Blazor
```

Use the `` component to render emojis:

```html
:tada: initial commit
```

Standard emoji characters are rendered like this:

```html
πŸŽ‰
```

Custom GitHub emojis are rendered as images:

```html
:octocat:
```

## `GEmojiSharp.DotnetTool`

[![NuGet](https://buildstats.info/nuget/GEmojiSharp.DotnetTool)](https://www.nuget.org/packages/GEmojiSharp.DotnetTool/)

> GitHub Emoji `dotnet` tool 🧰

![GEmojiSharp.DotnetTool](GEmojiSharp.DotnetTool.gif)

### Installation

Install:

```cmd
dotnet tool install -g GEmojiSharp.DotnetTool
```

Update:

```cmd
dotnet tool update -g GEmojiSharp.DotnetTool
```

Uninstall:

```cmd
dotnet tool uninstall -g GEmojiSharp.DotnetTool
```

### Usage

```cmd
emoji --help
```

```cmd
Description:
GitHub Emoji dotnet tool

Usage:
emoji [command] [options]

Options:
--version Show version information
-?, -h, --help Show help and usage information

Commands:
r, raw Get raw emojis
a, alias Get emoji aliases
e, emojify Replace aliases in text with raw emojis
d, demojify Replace raw emojis in text with aliases
export Export emoji data to
```

#### Raw

```cmd
emoji raw --help
```

```cmd
Description:
Get raw emojis

Usage:
emoji raw [...] [options]

Arguments:
Find emojis via description, category, alias or tag

Options:
-st, --skin-tones Include skin tone variants
-c, --copy Copy to clipboard
-?, -h, --help Show help and usage information
```

Examples πŸ’

Get raw emojis:

```cmd
emoji raw "grinning cat"
emoji raw grinning cat
emoji r grinning cat
```

```cmd
😺
😸
```

Copy to clipboard:

```cmd
emoji raw "grinning cat" --copy
emoji r grinning cat -c
```

```txt
😺😸
```

Skin tone variants:

```cmd
emoji raw "victory" --skin-tones
emoji r victory -st
```

```txt
✌️
✌🏻
✌🏼
✌🏽
✌🏾
✌🏿
```

#### Alias

```cmd
emoji alias --help
```

```cmd
Description:
Get emoji aliases

Usage:
emoji alias [...] [options]

Arguments:
Find emojis via description, category, alias or tag

Options:
-c, --copy Copy to clipboard
-?, -h, --help Show help and usage information
```

Examples πŸ’

Get emoji aliases:

```cmd
emoji alias "grinning cat"
emoji alias grinning cat
emoji a grinning cat
```

```cmd
:smiley_cat:
:smile_cat:
```

Copy to clipboard:

```cmd
emoji alias "grinning cat" --copy
emoji a grinning cat -c
```

```txt
:smiley_cat::smile_cat:
```

#### Emojify

```cmd
emoji emojify --help
```

```cmd
Description:
Replace aliases in text with raw emojis

Usage:
emoji emojify [...] [options]

Arguments:
A text with emoji aliases

Options:
-c, --copy Copy to clipboard
-?, -h, --help Show help and usage information
```

Examples πŸ’

Replace aliases in text with raw emojis:

```cmd
emoji emojify ":tada: initial commit"
emoji emojify :tada: initial commit
emoji e :tada: initial commit
```

```cmd
πŸŽ‰ initial commit
```

Copy to clipboard:

```cmd
emoji emojify ":tada: initial commit" --copy
emoji e :tada: initial commit -c
```

#### Demojify

```cmd
emoji demojify --help
```

```cmd
Description:
Replace raw emojis in text with aliases

Usage:
emoji demojify [...] [options]

Arguments:
A text with raw emojis

Options:
-c, --copy Copy to clipboard
-?, -h, --help Show help and usage information
```

Examples πŸ’

Replace raw emojis in text with aliases:

```cmd
emoji demojify "πŸŽ‰ initial commit"
emoji demojify πŸŽ‰ initial commit
emoji d πŸŽ‰ initial commit
```

```cmd
:tada: initial commit
```

Copy to clipboard:

```cmd
emoji demojify "πŸŽ‰ initial commit" --copy
emoji d πŸŽ‰ initial commit -c
```

#### Export

```cmd
emoji export --help
```

```cmd
Description:
Export emoji data to

Usage:
emoji export [...] [options]

Arguments:
Find emojis via description, category, alias or tag

Options:
-f, --format Format the data as
-c, --copy Copy to clipboard
-?, -h, --help Show help and usage information
```

Formats:

- `json`
- `toml`
- `xml`
- `yaml`

Examples πŸ’

Export emoji data to `json`:

```cmd
emoji export "grinning cat" --format json
emoji export grinning cat --format json
emoji export grinning cat -f json
emoji export grinning cat
```

```json
[
{
"Raw": "😺",
"Description": "grinning cat",
"Category": "Smileys & Emotion",
"Aliases": [
"smiley_cat"
],
"Tags": null,
"UnicodeVersion": "6.0",
"IosVersion": "6.0",
"Filename": "1f63a",
"IsCustom": false
},
{
"Raw": "😸",
"Description": "grinning cat with smiling eyes",
"Category": "Smileys & Emotion",
"Aliases": [
"smile_cat"
],
"Tags": null,
"UnicodeVersion": "6.0",
"IosVersion": "6.0",
"Filename": "1f638",
"IsCustom": false
}
]
```

Copy to clipboard:

```cmd
emoji export "grinning cat" --format json --copy
emoji export "grinning cat" -c
```

## `GEmojiSharp.PowerToysRun`

[![GitHub](https://img.shields.io/github/downloads/hlaueriksson/GEmojiSharp/v3.1.3/GEmojiSharp.PowerToysRun.3.1.3.zip)](https://github.com/hlaueriksson/GEmojiSharp/releases/download/v3.1.3/GEmojiSharp.PowerToysRun.3.1.3.zip)

> GitHub Emoji [PowerToys Run](https://docs.microsoft.com/en-us/windows/powertoys/run) plugin πŸ—‚οΈπŸ”ŽπŸ”Œ

![GEmojiSharp.PowerToysRun](GEmojiSharp.PowerToysRun.gif)

### Installation

The plugin is developed and tested with `PowerToys` `v0.77.0`.

Install:

0. [Install PowerToys](https://docs.microsoft.com/en-us/windows/powertoys/install)
1. Exit PowerToys
2. Download [GEmojiSharp.PowerToysRun.3.1.3.zip](https://github.com/hlaueriksson/GEmojiSharp/releases/download/v3.1.3/GEmojiSharp.PowerToysRun.3.1.3.zip) and extract it to:
- `%LocalAppData%\Microsoft\PowerToys\PowerToys Run\Plugins`
3. Start PowerToys

![GEmojiSharp.PowerToysRun](GEmojiSharp.PowerToysRun.png)

### Usage

1. Open PowerToys Run with `alt + space`
2. Type `emoji`
- A list of all emojis will be displayed
3. Continue to type to find emojis via description, category, alias or tag
4. Use ⬆️ and ⬇️ keys to select an emoji
5. Press `Enter` to copy the selected raw emoji to clipboard
6. Press `ctrl + c` to copy the selected emoji aliases to clipboard
7. Press `ctrl + Enter` to copy the selected raw emoji skin tone variants to clipboard
- For emoji that supports skin tone modifiers

Emojify:

- You can paste a text containing emoji aliases to replace them with raw emojis

Demojify:

- You can paste a text containing raw emojis to replace them with aliases

### Configuration

Change action keyword:

1. Open PowerToys
2. Select PowerToys Run
3. Scroll down to Plugins
4. Expand `GEmojiSharp`
5. Change *Direct activation command*

![GEmojiSharp.PowerToysRun](GEmojiSharp.PowerToysRun-Configuration.png)

## Samples

The [`samples`](/samples) folder contains...

- `GEmojiSharp.Sample.BlazorServer`, a Blazor Server app
- `GEmojiSharp.Sample.BlazorWebAssembly`, a Blazor WebAssembly app
- `GEmojiSharp.Sample.Web`, a ASP.NET Core web site

The Blazor WebAssembly app is showcased here:

- https://hlaueriksson.github.io/GEmojiSharp/ (GitHub Pages)
- https://purple-mushroom-05c6bad10.azurestaticapps.net (Azure Static Web Apps)

[![GEmojiSharp.Sample.BlazorWebAssembly](GEmojiSharp.Sample.BlazorWebAssembly.png)](https://hlaueriksson.github.io/GEmojiSharp/)

## Upgrading

> ⬆️ Upgrading from version `1.5.0` to `2.0.0`

Upgrade `GEmojiSharp.TagHelpers`:

- Uninstall `GEmojiSharp.TagHelpers`
- Install `GEmojiSharp.AspNetCore`
- Replace references to ~~`GEmojiSharp.TagHelpers`~~ with `GEmojiSharp.AspNetCore`:

```diff
- @addTagHelper *, GEmojiSharp.TagHelpers
+ @addTagHelper *, GEmojiSharp.AspNetCore
```

```diff
- @using GEmojiSharp.TagHelpers
+ @using GEmojiSharp.AspNetCore
```

```diff
- using GEmojiSharp.TagHelpers;
+ using GEmojiSharp.AspNetCore;
```

Upgrade `GEmojiSharp.Blazor`:

- Remove reference to the `css` file:

```diff
-
```

- Remove reference to the `js` file:

```diff
-
```

## Attribution

Repositories consulted when building this:

- https://github.com/github/gemoji
- https://github.com/github/g-emoji-element
- https://github.com/dotnet/command-line-api
- https://github.com/microsoft/PowerToys