Commit 431bd6c69ad30eff72db53f2434c8e11a1a7ecfe
Detect mentions
Close #2Charles Lehner committed on 3/29/2016, 8:01:18 PM
Parent: 3557c736edb5dd3f5283b94eec65b5c002ebb2d8
Files changed
index.js | changed |
test/mentions.js | changed |
index.js | ||
---|---|---|
@@ -3,8 +3,12 @@ | ||
3 | 3 … | function noop(){} |
4 | 4 … | var onLink = noop |
5 | 5 … | var extractor = new marked.Renderer() |
6 | 6 … | |
7 … | +extractor.mention = function (_, id) { | |
8 … | + onLink({target: id}) | |
9 … | +} | |
10 … | + | |
7 | 11 … | extractor.link = function (href, _, text) { |
8 | 12 … | onLink({label: text, target: href, embed: false}) |
9 | 13 … | } |
10 | 14 … | |
@@ -27,9 +31,9 @@ | ||
27 | 31 … | module.exports = function (text) { |
28 | 32 … | var a = [] |
29 | 33 … | links(text, function (link) { |
30 | 34 … | 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(/^@/, '')}) | |
32 | 36 … | else if(ref.isBlob(link.target)) |
33 | 37 … | a.push({link: link.target, rel: 'mentions', name: link.label}) |
34 | 38 … | else if(ref.isMsg(link.target)) |
35 | 39 … | a.push({link: link.target, rel: 'mentions', name: link.label}) |
test/mentions.js | ||
---|---|---|
@@ -28,4 +28,19 @@ | ||
28 | 28 … | t.deepEquals(mentions(text.blob), linkMention.blob, 'blob link') |
29 | 29 … | t.deepEquals(mentions(text.all), linkMention.all, 'all links') |
30 | 30 … | t.end() |
31 | 31 … | }) |
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