How to prevent emojify from rendering emoji shortcodes in code blocks?

My page rendering statement is:

{{ .Content | emojify | replaceRE "<a\\s+([^>]*href=\"https?://[^\"]+\"[^>]*)>" "<a $1 target=\"_blank\" rel=\"noopener noreferrer\">" | safeHTML }}

When my code is part of /etc/passwd, for example:

debian:x:820:1010::/etc/debian:/bin/bash

debian:x:820:1010::/etc/debian:/bin/bash
It is rendered as:

debian❌820:1010::/etc/debian:/bin/bash

debian❌820:1010::/etc/debian:/bin/bash

My current idea is to create a JS script that replaces all emojis within code blocks back, but this would cause even the needed emojis to be replaced, such as git commit -m "✨ Add new feature"
How should I proceed? To prevent it from rendering emoji shortcodes within the code.

Why are you passing .Content through the emojify function?’

Typically, when using the Markdown content format, you would just set enableEmoji to true in your site configuration.

1 Like

Thank you, it’s my lack of expertise. I didn’t realize that Hugo itself handles emoji rendering, so I manually implemented it in the theme

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.