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