Files: f87cf52b80cde6f8bec32cfd25ce0f2fce489fcb / modules / markdown.js
705 bytesRaw
1 | var markdown = require('ssb-markdown') |
2 | var h = require('hyperscript') |
3 | var ref = require('ssb-ref') |
4 | // |
5 | |
6 | var blob_url = require('../plugs').first(exports.blob_url = []) |
7 | |
8 | exports.markdown = function (content) { |
9 | if('string' === typeof content) |
10 | content = {text: content} |
11 | //handle patchwork style mentions. |
12 | var mentions = {} |
13 | if(Array.isArray(content.mentions)) |
14 | content.mentions.forEach(function (link) { |
15 | if(link.name) mentions["@"+link.name] = link.link |
16 | }) |
17 | |
18 | var md = h('div.markdown') |
19 | md.innerHTML = markdown.block(content.text, { |
20 | toUrl: function (id) { |
21 | if(ref.isBlob(id)) return blob_url(id) |
22 | return '#'+(mentions[id]?mentions[id]:id) |
23 | } |
24 | }) |
25 | |
26 | return md |
27 | |
28 | } |
29 | |
30 | |
31 | |
32 |
Built with git-ssb-web