Commit 8c06e4692a32f06062d681b6f1940f721073119a
Render custom emoji
cel committed on 6/2/2017, 8:49:51 AMParent: 654a3bef4ca321c95c33b7ec9447d1df0bcf3753
Files changed
message/html/markdown.js | changed |
message/html/markdown.js | ||
---|---|---|
@@ -14,31 +14,35 @@ | ||
14 | 14 … | return nest('message.html.markdown', markdown) |
15 | 15 … | |
16 | 16 … | function markdown (content) { |
17 | 17 … | if (typeof content === 'string') { content = {text: content} } |
18 | - // handle patchwork style mentions. | |
18 … | + // handle patchwork style mentions and custom emoji. | |
19 | 19 … | var mentions = {} |
20 | 20 … | if (Array.isArray(content.mentions)) { |
21 | 21 … | content.mentions.forEach(function (link) { |
22 | - if (link.name) mentions['@' + link.name] = link.link | |
22 … | + if (link && link.name) mentions[link.name] = link.link | |
23 | 23 … | }) |
24 | 24 … | } |
25 | 25 … | |
26 | 26 … | var md = h('div', {className: 'Markdown'}) |
27 | 27 … | 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 … | + }, | |
29 | 34 … | toUrl: (id) => { |
30 | 35 … | if (ref.isBlob(id)) return api.blob.sync.url(id) |
31 | - return (mentions[id] ? mentions[id] : id) | |
36 … | + return mentions[id.substr(1)] || id | |
32 | 37 … | }, |
33 | 38 … | imageLink: (id) => id |
34 | 39 … | }) |
35 | 40 … | |
36 | 41 … | return md |
37 | 42 … | } |
38 | 43 … | |
39 | - function renderEmoji (emoji) { | |
40 | - var url = api.emoji.sync.url(emoji) | |
44 … | + function renderEmoji (emoji, url) { | |
41 | 45 … | if (!url) return ':' + emoji + ':' |
42 | 46 … | return ` |
43 | 47 … | <img |
44 | 48 … | src="${encodeURI(url)}" |
Built with git-ssb-web