git ssb

16+

Dominic / patchbay



Tree: 5e399826faea89305f911f9f2fb8a9509f9a0319

Files: 5e399826faea89305f911f9f2fb8a9509f9a0319 / 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