git ssb

7+

dinoworm 🐛 / patchcore



Commit e88968184cc1392c4b3b1ebb85d0a3b0e0523b13

Render custom emoji

cel committed on 6/2/2017, 10:19:17 PM
Parent: 654a3bef4ca321c95c33b7ec9447d1df0bcf3753

Files changed

message/html/markdown.jschanged
message/html/markdown.jsView
@@ -14,31 +14,39 @@
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 = {}
20 + var emojiMentions = {}
2021 if (Array.isArray(content.mentions)) {
2122 content.mentions.forEach(function (link) {
22- if (link.name) mentions['@' + link.name] = link.link
23 + if (link && link.name && link.link) {
24 + if (link.emoji) emojiMentions[link.name] = link.link
25 + else mentions['@' + link.name] = link.link
26 + }
2327 })
2428 }
2529
2630 var md = h('div', {className: 'Markdown'})
2731 md.innerHTML = renderer.block(content.text, {
28- emoji: renderEmoji,
32 + emoji: (emoji) => {
33 + var url = emojiMentions[emoji]
34 + ? api.blob.sync.url(emojiMentions[emoji])
35 + : api.emoji.sync.url(emoji)
36 + return renderEmoji(emoji, url)
37 + },
2938 toUrl: (id) => {
3039 if (ref.isBlob(id)) return api.blob.sync.url(id)
31- return (mentions[id] ? mentions[id] : id)
40 + return mentions[id] || id
3241 },
3342 imageLink: (id) => id
3443 })
3544
3645 return md
3746 }
3847
39- function renderEmoji (emoji) {
40- var url = api.emoji.sync.url(emoji)
48 + function renderEmoji (emoji, url) {
4149 if (!url) return ':' + emoji + ':'
4250 return `
4351 <img
4452 src="${encodeURI(url)}"

Built with git-ssb-web