git ssb

16+

Dominic / patchbay



Tree: 038a737d7b268452a2d1ca1cd1e3ade9b5e966ff

Files: 038a737d7b268452a2d1ca1cd1e3ade9b5e966ff / modules_basic / markdown.js

1085 bytesRaw
1var markdown = require('ssb-markdown')
2var h = require('hyperscript')
3var ref = require('ssb-ref')
4
5exports.needs = {
6 blob_url: 'first',
7 emoji_url: 'first'
8}
9
10exports.gives = 'markdown'
11
12exports.create = function (api) {
13
14 function renderEmoji(emoji) {
15 var url = api.emoji_url(emoji)
16 if (!url) return ':' + emoji + ':'
17 return '<img src="' + encodeURI(url) + '"'
18 + ' alt=":' + escape(emoji) + ':"'
19 + ' title=":' + escape(emoji) + ':"'
20 + ' class="emoji">'
21 }
22
23 return function (content) {
24 if('string' === typeof content)
25 content = {text: content}
26 //handle patchwork style mentions.
27 var mentions = {}
28 if(Array.isArray(content.mentions))
29 content.mentions.forEach(function (link) {
30 if(link.name) mentions["@"+link.name] = link.link
31 })
32
33 var md = h('div.markdown')
34 md.innerHTML = markdown.block(content.text, {
35 emoji: renderEmoji,
36 toUrl: function (id) {
37 if(ref.isBlob(id)) return api.blob_url(id)
38 return '#'+(mentions[id]?mentions[id]:id)
39 }
40 })
41
42 return md
43
44 }
45}
46
47

Built with git-ssb-web