Files: a407ea75e9c86c40b52db83e092f821ca8ab84df / modules / post.js
951 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 | var plugs = require('../plugs') |
9 | var message_link = plugs.first(exports.message_link = []) |
10 | |
11 | exports.message_content = function (data, sbot) { |
12 | if(!data.value.content || !data.value.content.text) return |
13 | |
14 | var root = data.value.content.root |
15 | var re = !root ? null : h('span', 're:', message_link(root)) |
16 | |
17 | var content = h('div') |
18 | var d = h('div', re, content) |
19 | |
20 | var mentions = {} |
21 | if(Array.isArray(data.value.content.mentions)) |
22 | data.value.content.mentions.forEach(function (link) { |
23 | if(link.name) mentions["@"+link.name] = link.link |
24 | }) |
25 | |
26 | content.innerHTML = |
27 | markdown.block(data.value.content.text, {toUrl: function (id) { |
28 | if(ref.isBlob(id)) |
29 | return 'http://localhost:7777/'+encodeURIComponent(id) |
30 | return '#'+(mentions[id]?mentions[id]:id) |
31 | }}) |
32 | return d |
33 | } |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 |
Built with git-ssb-web