Files: 08e1fc42a3722f8f133fdcb3a7460462d599f889 / modules / post.js
954 bytesRaw
1 | var markdown = require('ssb-markdown') |
2 | var h = require('hyperscript') |
3 | var u = require('../util') |
4 | var ref = require('ssb-ref') |
5 | |
6 | //render a message |
7 | |
8 | exports.message_content = function (data, sbot) { |
9 | if(!data.value.content || !data.value.content.text) return |
10 | |
11 | var root = data.value.content.root |
12 | var re = !root ? null : h('span', 're:', |
13 | u.decorate(exports.message_link, root, function (d, e, v) { return d(e, v, sbot) }) |
14 | ) |
15 | |
16 | var content = h('div') |
17 | var d = h('div', re, content) |
18 | |
19 | var mentions = {} |
20 | if(Array.isArray(data.value.content.mentions)) |
21 | data.value.content.mentions.forEach(function (link) { |
22 | if(link.name) mentions["@"+link.name] = link.link |
23 | }) |
24 | |
25 | content.innerHTML = |
26 | markdown.block(data.value.content.text, {toUrl: function (id) { |
27 | if(ref.isBlob(id)) |
28 | return 'http://localhost:7777/'+encodeURIComponent(id) |
29 | return '#'+(mentions[id]?mentions[id]:id) |
30 | }}) |
31 | return d |
32 | } |
33 | |
34 | exports.message_link = [] |
35 | |
36 | |
37 | |
38 | |
39 | |
40 |
Built with git-ssb-web