Skip to content

A platform for community discussion. Free, open, simple.

FIX: render emojis in cooked hashtag text for composer rich text mode (#33395)

David Battersbye91024a22174
diff --git a/app/assets/javascripts/discourse/app/static/prosemirror/extensions/hashtag.js b/app/assets/javascripts/discourse/app/static/prosemirror/extensions/hashtag.js
index 84bd684b956..e133ae79551 100644
--- a/app/assets/javascripts/discourse/app/static/prosemirror/extensions/hashtag.js
+++ b/app/assets/javascripts/discourse/app/static/prosemirror/extensions/hashtag.js
@@ -1,5 +1,6 @@
import { ajax } from "discourse/lib/ajax";
import { getHashtagTypeClasses } from "discourse/lib/hashtag-type-registry";
+import { emojiUnescape } from "discourse/lib/text";
import { isBoundary } from "discourse/static/prosemirror/lib/markdown-it";
const VALID_HASHTAGS = new Map();
@@ -161,7 +162,7 @@ const extension = {
}
// decorate valid hashtags based on their type
- const tagText = validHashtag?.text || name;
+ const tagText = emojiUnescape(validHashtag?.text || name);
const hashtagTypeClass =
getHashtagTypeClasses()[validHashtag.type];
const hashtagIconHTML = hashtagTypeClass
diff --git a/app/assets/javascripts/discourse/tests/integration/components/prosemirror-editor/hashtag-test.js b/app/assets/javascripts/discourse/tests/integration/components/prosemirror-editor/hashtag-test.js
index c9c711df339..1ecc536814e 100644
--- a/app/assets/javascripts/discourse/tests/integration/components/prosemirror-editor/hashtag-test.js
+++ b/app/assets/javascripts/discourse/tests/integration/components/prosemirror-editor/hashtag-test.js
@@ -32,6 +32,13 @@ module(
style_type: "icon",
id: 4,
},
+ {
+ type: "category",
+ ref: "welcome",
+ text: "hello :wave:",
+ style_type: "square",
+ id: 5,
+ },
],
tags: [
{
@@ -81,6 +88,11 @@ module(
'<p>Lets <a class="hashtag-cooked" data-name="discuss" data-processed="true" data-valid="true" contenteditable="false" draggable="true"><span class=\"hashtag-category-icon hashtag-color--category-4\"><svg class=\"fa d-icon d-icon-comment svg-icon svg-string\" aria-hidden=\"true\" xmlns=\"http://www.w3.org/2000/svg\"><use href=\"#comment\"></use></svg></span>discuss</a></p>',
"Lets #discuss",
],
+ "hashtag with emoji in text": [
+ "#welcome",
+ '<p><a class="hashtag-cooked" data-name="welcome" data-processed="true" data-valid="true" contenteditable="false" draggable="true"><span class=\"hashtag-category-square hashtag-color--category-5\"></span>hello <img width=\"20\" height=\"20\" src=\"/images/emoji/twitter/wave.png?v=14\" title=\"wave\" alt=\"wave\" class=\"emoji\"></a></p>',
+ "#welcome",
+ ],
};
Object.entries(testCases).forEach(