Skip to content

Instantly share code, notes, and snippets.

@pathawks
Last active January 2, 2016 11:09
Show Gist options
  • Select an option

  • Save pathawks/8294644 to your computer and use it in GitHub Desktop.

Select an option

Save pathawks/8294644 to your computer and use it in GitHub Desktop.
Jekyll include to replace ASCII smileys with emoji

content-emoji.html

Jekyll include to replace ASCII smileys with emoji

How To Use

  • Copy content-emoji.html to the _includes/ folder of your Jekyll site
  • Instead of calling {{ content }} directly from your post layout, call {% include content-emoji.html %}
  • In your posts, wrap ASCII smileys in a span tag: <span>:)</span>
  • Smileys will be replaced with emoji smiley

You will also need to do some sort of feature detection to see if the browser is capable of displaying Emoji. If not, you should hide the emoji and replace it with the .noemoji fallback. There is almost certianly a better way to do this.

{{ content | replace:'<span>:p</span>','<span class="emoji">&#128541;</span><span class="noemoji">:p</span>' | replace:'<span>;p</span>','<span class="emoji">&#128540;</span><span class="noemoji">:p</span>' | replace:'<span>;)</span>','<span class="emoji">&#128521;</span><span class="noemoji">;)</span>' | replace:'<span>:D</span>','<span class="emoji">&#128515;</span><span class="noemoji">:D</span>' | replace:'<span>:)</span>','<span class="emoji">&#128512;</span><span class="noemoji">:)</span>' | replace:'<span>(:</span>','<span class="emoji">&#128512;</span><span class="noemoji">(:</span>' | replace:'<span>X(</span>','<span class="emoji" title="Persevering Face">&#128547;</span><span class="noemoji">X(</span>' | replace:'<span>:(</span>','<span class="emoji" title="Disappointed Face">😞</span><span class="noemoji">:(</span>' }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment