git ssb

0+

cel / ssb-mentions



Commit de7b121198e402b391580433b43572a993304c49

Include bare feed name mentions, optionally

cel committed on 3/13/2017, 8:02:40 PM
Parent: c63e6a70ea157ec50f098e16f5601626830fd93b

Files changed

README.mdchanged
index.jschanged
test/mentions.jschanged
README.mdView
@@ -6,11 +6,19 @@
66
77 ``` js
88 var mentions = require('ssb-mentions')
99
10-var ary = mentions(markdown)
10 +var ary = mentions(markdown, opts)
1111
1212 ```
1313
14 +## options
15 +
16 +- `bareFeedNames` (boolean, default false): if true, include stub mention
17 + objects for bare feed name mentions, in the format
18 + `{name: "NAME", link: "@"}`. these can then have the `link` filled in with a
19 + feed id, to make a "patchwork-style mention", or be removed from the mentions
20 + array before publishing.
21 +
1422 ## License
1523
1624 MIT
index.jsView
@@ -27,17 +27,20 @@
2727 }
2828 onLink = noop
2929 }
3030
31-module.exports = function (text) {
31 +module.exports = function (text, opts) {
32 + var bareFeedNames = opts && opts.bareFeedNames
3233 var a = []
3334 links(text, function (link) {
3435 if(ref.isFeed(link.target))
3536 a.push({link: link.target, name: link.label && link.label.replace(/^@/, '')})
3637 else if(ref.isBlob(link.target))
3738 a.push({link: link.target, name: link.label})
3839 else if(ref.isMsg(link.target))
3940 a.push({link: link.target, name: link.label})
41 + else if(bareFeedNames && link.target && link.target[0] === '@')
42 + a.push({link: link.target[0], name: link.target.substr(1)})
4043 })
4144 return a
4245 }
4346
test/mentions.jsView
@@ -55,4 +55,10 @@
5555 ], 'blob link')
5656
5757 t.end()
5858 })
59 +
60 +test('bare feed name mentions can be detected', function (t) {
61 + t.deepEquals(mentions('a @feed mention', {bareFeedNames: true}),
62 + [{name: 'feed', link: '@'}], 'feed link')
63 + t.end()
64 +})

Built with git-ssb-web