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