Commit de7b121198e402b391580433b43572a993304c49
Include bare feed name mentions, optionally
cel committed on 3/13/2017, 8:02:40 PMParent: c63e6a70ea157ec50f098e16f5601626830fd93b
Files changed
README.md | changed |
index.js | changed |
test/mentions.js | changed |
README.md | |||
---|---|---|---|
@@ -6,11 +6,19 @@ | |||
6 | 6 … | ||
7 | 7 … | ``` js | |
8 | 8 … | var mentions = require('ssb-mentions') | |
9 | 9 … | ||
10 | -var ary = mentions(markdown) | ||
10 … | +var ary = mentions(markdown, opts) | ||
11 | 11 … | ||
12 | 12 … | ``` | |
13 | 13 … | ||
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 … | + | ||
14 | 22 … | ## License | |
15 | 23 … | ||
16 | 24 … | MIT |
index.js | ||
---|---|---|
@@ -27,17 +27,20 @@ | ||
27 | 27 … | } |
28 | 28 … | onLink = noop |
29 | 29 … | } |
30 | 30 … | |
31 | -module.exports = function (text) { | |
31 … | +module.exports = function (text, opts) { | |
32 … | + var bareFeedNames = opts && opts.bareFeedNames | |
32 | 33 … | var a = [] |
33 | 34 … | links(text, function (link) { |
34 | 35 … | if(ref.isFeed(link.target)) |
35 | 36 … | a.push({link: link.target, name: link.label && link.label.replace(/^@/, '')}) |
36 | 37 … | else if(ref.isBlob(link.target)) |
37 | 38 … | a.push({link: link.target, name: link.label}) |
38 | 39 … | else if(ref.isMsg(link.target)) |
39 | 40 … | 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)}) | |
40 | 43 … | }) |
41 | 44 … | return a |
42 | 45 … | } |
43 | 46 … |
Built with git-ssb-web