git ssb

0+

cel / ssb-mentions



Commit 431bd6c69ad30eff72db53f2434c8e11a1a7ecfe

Detect mentions

Close #2
Charles Lehner committed on 3/29/2016, 8:01:18 PM
Parent: 3557c736edb5dd3f5283b94eec65b5c002ebb2d8

Files changed

index.jschanged
test/mentions.jschanged
index.jsView
@@ -3,8 +3,12 @@
33 function noop(){}
44 var onLink = noop
55 var extractor = new marked.Renderer()
66
7 +extractor.mention = function (_, id) {
8 + onLink({target: id})
9 +}
10 +
711 extractor.link = function (href, _, text) {
812 onLink({label: text, target: href, embed: false})
913 }
1014
@@ -27,9 +31,9 @@
2731 module.exports = function (text) {
2832 var a = []
2933 links(text, function (link) {
3034 if(ref.isFeed(link.target))
31- a.push({link: link.target, rel: 'mentions', name: link.label.replace(/^@/, '')})
35 + a.push({link: link.target, rel: 'mentions', name: link.label && link.label.replace(/^@/, '')})
3236 else if(ref.isBlob(link.target))
3337 a.push({link: link.target, rel: 'mentions', name: link.label})
3438 else if(ref.isMsg(link.target))
3539 a.push({link: link.target, rel: 'mentions', name: link.label})
test/mentions.jsView
@@ -28,4 +28,19 @@
2828 t.deepEquals(mentions(text.blob), linkMention.blob, 'blob link')
2929 t.deepEquals(mentions(text.all), linkMention.all, 'all links')
3030 t.end()
3131 })
32 +
33 +var refMention = {
34 + feed: [ { link: id.feed, name: undefined, rel: 'mentions' } ],
35 + msg: [ { link: id.msg, name: undefined, rel: 'mentions' } ],
36 + blob: [ { link: id.blob, name: undefined, rel: 'mentions' } ]
37 +}
38 +refMention.all = refMention.feed.concat(refMention.msg, refMention.blob)
39 +
40 +test('ref mentions are detected', function (t) {
41 + t.deepEquals(mentions(id.feed), refMention.feed, 'feed link')
42 + t.deepEquals(mentions(id.blob), refMention.blob, 'blob link')
43 + t.deepEquals(mentions(id.msg), refMention.msg, 'msg link')
44 + t.deepEquals(mentions(id.all), refMention.all, 'all link')
45 + t.end()
46 +})

Built with git-ssb-web