Commit db0a3916eb340dff39619cfcf00210ef871afffe
Linkify ssb refs in JSON view
Charles Lehner committed on 7/26/2016, 1:40:47 AMParent: 300a5135afd10610eb907dbdf31614142d3025ae
Files changed
modules/raw.js | changed |
modules/raw.js | ||
---|---|---|
@@ -6,8 +6,19 @@ | ||
6 | 6 | var plugs = require('../plugs') |
7 | 7 | var message_render = plugs.first(exports.message_render = []) |
8 | 8 | var message_compose = plugs.first(exports.message_compose = []) |
9 | 9 | |
10 | +// from ssb-ref | |
11 | +var refRegex = /((?:@|%|&)[A-Za-z0-9\/+]{43}=\.[\w\d]+)/g | |
12 | + | |
13 | +function linkify(text) { | |
14 | + var arr = text.split(refRegex) | |
15 | + for (var i = 1; i < arr.length; i += 2) { | |
16 | + arr[i] = h('a', {href: '#' + arr[i]}, arr[i]) | |
17 | + } | |
18 | + return arr | |
19 | +} | |
20 | + | |
10 | 21 | exports.message_meta = function (msg) { |
11 | 22 | var tmp = h('div') |
12 | 23 | var el |
13 | 24 | var pre |
@@ -21,10 +32,12 @@ | ||
21 | 32 | // move away the content |
22 | 33 | while (el = msgContentEl.firstChild) |
23 | 34 | tmp.appendChild(el) |
24 | 35 | // show the raw stuff |
25 | - var json = JSON.stringify({key: msg.key, value: msg.value}, 0, 2) | |
26 | - pre = h('pre', json) | |
36 | + if (!pre) pre = h('pre', linkify(JSON.stringify({ | |
37 | + key: msg.key, | |
38 | + value: msg.value | |
39 | + }, 0, 2))) | |
27 | 40 | msgContentEl.appendChild(pre) |
28 | 41 | } else { |
29 | 42 | // hide the raw stuff |
30 | 43 | msgContentEl.removeChild(pre) |
Built with git-ssb-web