Replace regular expression with HTML

I’m trying to replace Discord emoji codes with HTML, but I keep getting an invalid syntax error.

Rebuild failed:

Process: loading templates: “/home/ruby/Code/www/two.alliumvale.world/themes/alliumvale2/layouts/partials/announcements.html:10:1”: parse failed: template: partials/announcements.html:10: invalid syntax

<section id="announcements">
    <div class="container">
        <h1>Announcements</h1>
        {{ range $.Site.Data.announcements }}
        <article>
            <header>
                <div class="author">{{ .user }}</div>
                <div class="date">{{ .date }}</div>
            </header>
            <p>{{ .message | replaceRE "<:(\w+):(\d+)>" `<img src="https://cdn.discordapp.com/emojis/$2.webp?size=44&quality=lossless" alt=":$1:">` }}</p>
        </article>
        {{ end }}
    </div>
</section>

Please provide a data file example.

Here’s some of the data:

[
    {
        "user": "Ruby#0666",
        "user_id": "259889133936181253",
        "date": "Tue Dec 29 2020 12:39:28 GMT-0500",
        "message": "**New Emojis**"
    },
    {
        "user": "Ruby#0666",
        "user_id": "259889133936181253",
        "date": "Tue Dec 29 2020 12:39:49 GMT-0500",
        "message": "<:transupvote:793533594635206656> <:transdownvote:793533594580549642> <:translefts:793533594488143902> <:transrights:793533594257064033>"
    }
]
{{ .message | replaceRE `<:(\w+):(\d+)>` `<img src="https://cdn.discordapp.com/emojis/$2.webp?size=44&quality=lossless" alt=":$1:">` | safeHTML }}

Reference:

Thanks, that worked.

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