git ssb

0+

cel / ssb-mentions



Commit 00c2e8eca87eb680383f480cd9b2d7a7fcaa215c

initial

Dominic Tarr committed on 3/6/2016, 5:11:44 AM

Files changed

.travis.ymladded
LICENSEadded
README.mdadded
index.jsadded
package.jsonadded
.travis.ymlView
@@ -1,0 +1,4 @@
1 +language: node_js
2 +node_js:
3 + - 0.6
4 + - 0.8
LICENSEView
@@ -1,0 +1,22 @@
1 +Copyright (c) 2016 Dominic Tarr
2 +
3 +Permission is hereby granted, free of charge,
4 +to any person obtaining a copy of this software and
5 +associated documentation files (the "Software"), to
6 +deal in the Software without restriction, including
7 +without limitation the rights to use, copy, modify,
8 +merge, publish, distribute, sublicense, and/or sell
9 +copies of the Software, and to permit persons to whom
10 +the Software is furnished to do so,
11 +subject to the following conditions:
12 +
13 +The above copyright notice and this permission notice
14 +shall be included in all copies or substantial portions of the Software.
15 +
16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
20 +ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
README.mdView
@@ -1,0 +1,16 @@
1 +# ssb-mentions
2 +
3 +extract the mentions in a ssb message, just using the markdown.
4 +this is _mostly compatible_ with the way patchwork does it.
5 +but simpler, because it relies only on the markdown.
6 +
7 +``` js
8 +var mentions = require('ssb-mentions')
9 +
10 +var ary = mentions(markdown)
11 +
12 +```
13 +
14 +## License
15 +
16 +MIT
index.jsView
@@ -1,0 +1,39 @@
1 +var ref = require('ssb-ref')
2 +var marked = require('ssb-marked')
3 +function noop(){}
4 +var onLink = noop
5 +var extractor = new marked.Renderer()
6 +
7 +extractor.link = function (href, _, text) {
8 + onLink({label: text, target: href, embed: false})
9 +}
10 +
11 +extractor.image = function (href, _, text) {
12 + onLink({label: text, target: href, embed: true})
13 +}
14 +
15 +function links (s, _onLink) {
16 + if('string' !== typeof s) return
17 + onLink = _onLink
18 + try {
19 + marked(s, {renderer: extractor})
20 + } catch(err) {
21 + console.log(JSON.stringify(s))
22 + throw err
23 + }
24 + onLink = noop
25 +}
26 +
27 +module.exports = function (text) {
28 + var a = []
29 + links(text, function (link) {
30 + if(ref.isFeed(link.target))
31 + a.push({link: link.target, rel: 'mentions', name: link.label.replace(/^@/, '')})
32 + else if(ref.isBlob(link.target))
33 + a.push({link: link.target, rel: 'mentions', name: link.label})
34 + else if(ref.isMsg(link.target))
35 + a.push({link: link.target, rel: 'mentions', name: link.label})
36 + })
37 + return a
38 +}
39 +
package.jsonView
@@ -1,0 +1,19 @@
1 +{
2 + "name": "ssb-mentions",
3 + "description": "",
4 + "version": "0.0.0",
5 + "homepage": "https://github.com/dominictarr/ssb-mentions",
6 + "repository": {
7 + "type": "git",
8 + "url": "git://github.com/dominictarr/ssb-mentions.git"
9 + },
10 + "dependencies": {
11 + },
12 + "devDependencies": {
13 + },
14 + "scripts": {
15 + "test": "set -e; for t in test/*.js; do node $t; done"
16 + },
17 + "author": "Dominic Tarr <dominic.tarr@gmail.com> (http://dominictarr.com)",
18 + "license": "MIT"
19 +}

Built with git-ssb-web