As soon as I use one or more emojis in HTML or Markdown (I usually write posts in HTML rather than MD), I’d like to add a <span class="emoji"> around the the emoji (or emojis, if used in succession).
I’d like to do this because I want to be able to style all emojis without manually having to add a class to the emojis. I’d prefer if Hugo did this while rendering the site so I don’t have to use JS.
There should be unicode ranges for emojis that could be targeted.
Doing this via output in Hugo will result in 27bytes per emoji extra. Not saying that is much, but it adds up for people that are very, ehm, expressive with emojis.
Some notes:
CSS: I don’t think there is a way to target specific character codes per CSS, that would have been my first approach. You could do a search for [however_characters_are_found=1234] and then use :before and :after to style them. I had a very quick check, but it does not appear this is possible currently.
JavaScript: It is possible to target character codes via for instance charAt in (I know you don’t want that) Javascript. You could parse your output and dynamically add the spans.
Hugo: You could use findRe to create a regular expression to find and replace all characters of a certain unicode character class or each emoji manually before outputting the content/description. That might be the Hugo way to do it. It will be resource intense though.
Hugo 2: Shortcode. {{< emoji name=":alert:" >}} and in layouts/shortcodes/emoji.htmlthe logic to parse the name into an emoji inside of a span. Caveat (someone else will jump in and have the knowledge): I don’t know if you need to use {{< or {{% for the shortcode call in the markdown so that the HTML is not double-parsed or removed.
If this is for your personal site, and you don’t intend to include mathematical markup in your pages, you can use the passthrough render hook for this.
Regarding the regex approach… Unlike Rust, Go does not recognize/support the Unicode “Emoji_Presentation” character class.
I am unsure if you need to name the src of the emoji ranges. If in doubt add src: local("Apple Color Emoji"), local("Segoe UI Emoji"), local("Segoe UI Symbol"), local("Noto Color Emoji"); which should match with most these days.
Cool! Would rather write with my OS emoji picker, because I have some trouble memorizing all the :emojicodes:. It would also make it more portable to another SSG or CMS later. But :emojicode: is better than nothing.
This is now offtopic but I would assume that given that these emojis now are selected via a name they can be styled separately from others. Naming with the mentioned method, then applying styles in a class, then using on the container element of the text containing the emojis (for instance, the <main> element).
does not „name“ an emoji, it names a font subset. There’s no way (yet?) to select (and then style) characters or character ranges in CSS without wrapping them in a HTML element. That’s what I tried to say, and yes, it was OT.