Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plugins/mention.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../lib/linkify/plugins/mention');
28 changes: 28 additions & 0 deletions src/linkify/plugins/mention.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
Quick Mention parser plugin for linkify
*/
function mention(linkify) {
let
TT = linkify.scanner.TOKENS, // Text tokens
MT = linkify.parser.TOKENS, // Multi tokens
MultiToken = MT.Base,
S_START = linkify.parser.start,
S_AT, S_MENTION;

class MENTION extends MultiToken {
constructor(value) {
super(value);
this.type = 'mention';
this.isLink = true;
}
}

S_AT = new linkify.parser.State();
S_MENTION = new linkify.parser.State(MENTION);

S_START.on(TT.AT, S_AT);
S_AT.on(TT.DOMAIN, S_MENTION);
S_AT.on(TT.TLD, S_MENTION);
}

export default mention;
4 changes: 4 additions & 0 deletions templates/linkify/plugins/mention.amd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<%= contents %>
require(['linkify', 'linkify/plugins/mention'], function (linkify, mention) {
mention(linkify);
});
4 changes: 4 additions & 0 deletions templates/linkify/plugins/mention.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
;(function (linkify) {
<%= contents %>
mention(linkify);
})(window.linkify);
34 changes: 34 additions & 0 deletions test/spec/linkify/plugins/mention-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*jshint -W030 */
var
linkify = require('../../../../lib/linkify'),
mention = require('../../../../lib/linkify/plugins/mention');

describe('linkify/plugins/mention', function () {

it('Cannot parse mentions before applying the plugin', function () {
expect(linkify.find('There is a @mention @YOLO2015 and @1234 and @%^&*( should not work'))
.to.be.eql([]);

expect(linkify.test('@wat', 'mention')).to.not.be.ok;
expect(linkify.test('@987', 'mention')).to.not.be.ok;
});

it ('Can parse mentions after applying the plugin', function () {

mention(linkify);

expect(linkify.find('There is a @mention @YOLO2015 and @1234 and @%^&*( should not work'))
.to.be.eql([{
type: 'mention',
value: '@mention',
href: '@mention'
}, {
type: 'mention',
value: '@YOLO2015',
href: '@YOLO2015'
}]);

expect(linkify.test('@wat', 'mention')).to.be.ok;
expect(linkify.test('@987', 'mention')).to.not.be.ok;
});
});