git ssb

0+

cel / ssb-mentions



Commit 808af6d34ddbb7634927905842529fa9905d0ed2

Detect emoji

cel committed on 5/30/2017, 7:46:01 AM
Parent: c6df90952add83c8bb601a42ca76c10a21ded936

Files changed

README.mdchanged
index.jschanged
test/mentions.jschanged
README.mdView
@@ -17,8 +17,10 @@
1717 objects for bare feed name mentions, in the format
1818 `{name: "NAME", link: "@"}`. these can then have the `link` filled in with a
1919 feed id, to make a "patchwork-style mention", or be removed from the mentions
2020 array before publishing.
21 +- `emoji` (boolean, default false): if true, include emoji in the mentions
22 + array, in the form `{name: "NAME", emoji: true}`.
2123
2224 ## License
2325
2426 MIT
index.jsView
@@ -30,8 +30,12 @@
3030 extractor.mention = function (_, id) {
3131 onLink({target: id})
3232 }
3333
34 +extractor.emoji = function (name) {
35 + onLink({label: name, emoji: true})
36 +}
37 +
3438 extractor.hashtag = function (_, hashtag) {
3539 onLink({target: hashtag})
3640 }
3741
@@ -46,9 +50,9 @@
4650 function links (s, _onLink) {
4751 if('string' !== typeof s) return
4852 onLink = _onLink
4953 try {
50- marked(s, {renderer: extractor})
54 + marked(s, {renderer: extractor, emoji: extractor.emoji})
5155 } catch(err) {
5256 console.log(JSON.stringify(s))
5357 throw err
5458 }
@@ -56,8 +60,9 @@
5660 }
5761
5862 module.exports = function (text, opts) {
5963 var bareFeedNames = opts && opts.bareFeedNames
64 + var emoji = opts && opts.emoji
6065 var a = []
6166 links(text, function (link) {
6267 if(ref.isFeed(link.target))
6368 a.push({link: link.target, name: link.label && link.label.replace(/^@/, '')})
@@ -68,8 +73,10 @@
6873 else if(bareFeedNames && link.target && link.target[0] === '@')
6974 a.push({link: link.target[0], name: link.target.substr(1)})
7075 else if(link.target && link.target[0] === '#')
7176 a.push({link: link.target})
77 + else if(emoji && link.emoji)
78 + a.push({emoji: true, name: link.label})
7279 })
7380 return a
7481 }
7582
test/mentions.jsView
@@ -78,4 +78,12 @@
7878 }
7979 ], 'no tags')
8080 t.end()
8181 })
82 +
83 +test('detect emoji', function (t) {
84 + t.deepEquals(mentions('some nice :+1: :emoji: here', {emoji: true}), [
85 + {name: '+1', emoji: true},
86 + {name: 'emoji', emoji: true},
87 + ], 'emoji')
88 + t.end()
89 +})

Built with git-ssb-web