git ssb

7+

dinoworm 🐛 / patchcore



Commit 8c06e4692a32f06062d681b6f1940f721073119a

Render custom emoji

cel committed on 6/2/2017, 8:49:51 AM
Parent: 654a3bef4ca321c95c33b7ec9447d1df0bcf3753

Files changed

message/html/markdown.jschanged
message/html/markdown.jsView
@@ -14,31 +14,35 @@
1414 return nest('message.html.markdown', markdown)
1515
1616 function markdown (content) {
1717 if (typeof content === 'string') { content = {text: content} }
18- // handle patchwork style mentions.
18 + // handle patchwork style mentions and custom emoji.
1919 var mentions = {}
2020 if (Array.isArray(content.mentions)) {
2121 content.mentions.forEach(function (link) {
22- if (link.name) mentions['@' + link.name] = link.link
22 + if (link && link.name) mentions[link.name] = link.link
2323 })
2424 }
2525
2626 var md = h('div', {className: 'Markdown'})
2727 md.innerHTML = renderer.block(content.text, {
28- emoji: renderEmoji,
28 + emoji: (emoji) => {
29 + var url = mentions[emoji]
30 + ? api.blob.sync.url(mentions[emoji])
31 + : api.emoji.sync.url(emoji)
32 + return renderEmoji(emoji, url)
33 + },
2934 toUrl: (id) => {
3035 if (ref.isBlob(id)) return api.blob.sync.url(id)
31- return (mentions[id] ? mentions[id] : id)
36 + return mentions[id.substr(1)] || id
3237 },
3338 imageLink: (id) => id
3439 })
3540
3641 return md
3742 }
3843
39- function renderEmoji (emoji) {
40- var url = api.emoji.sync.url(emoji)
44 + function renderEmoji (emoji, url) {
4145 if (!url) return ':' + emoji + ':'
4246 return `
4347 <img
4448 src="${encodeURI(url)}"

Built with git-ssb-web