git ssb

16+

Dominic / patchbay



Tree: 931ac024cad9b0e63311dd1a76de77d0490f8391

Files: 931ac024cad9b0e63311dd1a76de77d0490f8391 / modules_basic / markdown.js

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

Built with git-ssb-web