Last active
September 18, 2015 13:22
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
export default Ember.Component.extend({ | |
// .. | |
showdownExtensions: ["emoji"] | |
// .. | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
}]; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment