Skip to content

Instantly share code, notes, and snippets.

@nikz
Last active September 18, 2015 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikz/d19f086660b4f741394b to your computer and use it in GitHub Desktop.
Save nikz/d19f086660b4f741394b to your computer and use it in GitHub Desktop.
Example of how to create a Showdown extension to use with ember-cli-showdown for rendering Emoji images.
// ...
export default Ember.Component.extend({
// ..
showdownExtensions: ["emoji"]
// ..
})
const emojiData = {
"smile": "/assets/images/emoji/smile.png",
// ...
}
showdown.extension("emoji", function() {
return [{
type: "lang",
regex: ":([A-z0-9_-]+):",
replace: function(original, emojiName) {
if (emojiData.hasOwnProperty(emojiName)) {
let url = emojiData[emojiName];
return `<img src="${url}" alt="${emojiName}" class="emoji" />`;
} else {
// we don't know that emoji...
return original;
}
}
}];
});
{{markdown-to-html markdown=someContentWithEmoji extensions=showdownExtensions}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment