git ssb

0+

ev / microbay



forked from Dominic / patchbay

Commit db0a3916eb340dff39619cfcf00210ef871afffe

Linkify ssb refs in JSON view

Charles Lehner committed on 7/26/2016, 1:40:47 AM
Parent: 300a5135afd10610eb907dbdf31614142d3025ae

Files changed

modules/raw.jschanged
modules/raw.jsView
@@ -6,8 +6,19 @@
66 var plugs = require('../plugs')
77 var message_render = plugs.first(exports.message_render = [])
88 var message_compose = plugs.first(exports.message_compose = [])
99
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+
1021 exports.message_meta = function (msg) {
1122 var tmp = h('div')
1223 var el
1324 var pre
@@ -21,10 +32,12 @@
2132 // move away the content
2233 while (el = msgContentEl.firstChild)
2334 tmp.appendChild(el)
2435 // 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)))
2740 msgContentEl.appendChild(pre)
2841 } else {
2942 // hide the raw stuff
3043 msgContentEl.removeChild(pre)

Built with git-ssb-web