File size: 2,424 Bytes
3f268e5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
define('linkify/plugins/mention', ['module', 'exports'], function (module, exports) {
	'use strict';

	try { try { Object.defineProperty(exports, "__esModule", {
		value: true
	}); } catch (e) { exports['__esModule'] = true; } } catch (e) { exports['__esModule'] = true; }
	exports['default'] = mention;
	/**
 	Mention parser plugin for linkify
 */
	function mention(linkify) {
		var TT = linkify.scanner.TOKENS; // Text tokens
		var _linkify$parser = linkify.parser,
		    MT = _linkify$parser.TOKENS,
		    State = _linkify$parser.State;
		// Multi tokens, state
		var MultiToken = MT.Base;
		var S_START = linkify.parser.start;

		var TT_DOMAIN = TT.DOMAIN;
		var TT_LOCALHOST = TT.LOCALHOST;
		var TT_NUM = TT.NUM;
		var TT_SLASH = TT.SLASH;
		var TT_TLD = TT.TLD;
		var TT_UNDERSCORE = TT.UNDERSCORE;

		function MENTION(value) {
			this.v = value;
		}

		linkify.inherits(MultiToken, MENTION, {
			type: 'mention',
			isLink: true,
			toHref: function toHref() {
				return '/' + this.toString().substr(1);
			}
		});

		var S_AT = S_START.jump(TT.AT); // @
		var S_AT_SYMS = new State();
		var S_MENTION = new State(MENTION);
		var S_MENTION_SLASH = new State();
		var S_MENTION_SLASH_SYMS = new State();

		// @_,
		S_AT.on(TT_UNDERSCORE, S_AT_SYMS);

		//  @_*
		S_AT_SYMS.on(TT_UNDERSCORE, S_AT_SYMS);

		// Valid mention (not made up entirely of symbols)
		S_AT.on(TT_DOMAIN, S_MENTION).on(TT_LOCALHOST, S_MENTION).on(TT_TLD, S_MENTION).on(TT_NUM, S_MENTION);

		S_AT_SYMS.on(TT_DOMAIN, S_MENTION).on(TT_LOCALHOST, S_MENTION).on(TT_TLD, S_MENTION).on(TT_NUM, S_MENTION);

		// More valid mentions
		S_MENTION.on(TT_DOMAIN, S_MENTION).on(TT_LOCALHOST, S_MENTION).on(TT_TLD, S_MENTION).on(TT_NUM, S_MENTION).on(TT_UNDERSCORE, S_MENTION);

		// Mention with a slash
		S_MENTION.on(TT_SLASH, S_MENTION_SLASH);

		// Mention _ trailing stash plus syms
		S_MENTION_SLASH.on(TT_UNDERSCORE, S_MENTION_SLASH_SYMS);
		S_MENTION_SLASH_SYMS.on(TT_UNDERSCORE, S_MENTION_SLASH_SYMS);

		// Once we get a word token, mentions can start up again
		S_MENTION_SLASH.on(TT_DOMAIN, S_MENTION).on(TT_LOCALHOST, S_MENTION).on(TT_TLD, S_MENTION).on(TT_NUM, S_MENTION);

		S_MENTION_SLASH_SYMS.on(TT_DOMAIN, S_MENTION).on(TT_LOCALHOST, S_MENTION).on(TT_TLD, S_MENTION).on(TT_NUM, S_MENTION);
	}
	module.exports = exports['default'];
});
require(['linkify', 'linkify/plugins/mention'], function (linkify, mention) {
	mention(linkify);
});