git ssb

16+

Dominic / patchbay



Tree: 80807add560dfbbd3fe40aa17eac62b859624063

Files: 80807add560dfbbd3fe40aa17eac62b859624063 / modules_basic / markdown.js

1114 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: (id) => {
37 if(ref.isBlob(id)) return api.blob_url(id)
38 return '#'+(mentions[id]?mentions[id]:id)
39 },
40 imageLink: (id) => '#' + id
41 })
42
43 return md
44
45 }
46}
47
48

Built with git-ssb-web