-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
mention.js
93 lines (71 loc) · 1.69 KB
/
mention.js
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
'use strict';
var locator = require('../locator/mention');
var gh = require('../util/gh');
var usernameEnd = require('../util/username-end');
exports = mention;
module.exports = exports;
exports.locator = locator;
exports.notInLink = true;
var own = {}.hasOwnProperty;
var C_SLASH = '/';
var C_AT = '@';
var CC_SLASH = C_SLASH.charCodeAt(0);
var CC_AT = C_AT.charCodeAt(0);
/* Map of overwrites for at-mentions.
* GitHub does some fancy stuff with `@mention`, by linking
* it to their blog-post introducing the feature.
* To my knowledge, there are no other magical usernames. */
var OVERWRITES = {
mention: 'blog/821',
mentions: 'blog/821'
};
/* Tokenise a mention. */
function mention(eat, value, silent) {
var self = this;
var index;
var subvalue;
var handle;
var href;
var node;
var exit;
var now;
if (value.charCodeAt(0) !== CC_AT) {
return;
}
index = usernameEnd(value, 1);
if (index === -1) {
return;
}
/* Support teams. */
if (value.charCodeAt(index) === CC_SLASH) {
index = usernameEnd(value, index + 1);
if (index === -1) {
return;
}
}
/* istanbul ignore if - maybe used by plug-ins */
if (silent) {
return true;
}
now = eat.now();
handle = value.slice(1, index);
subvalue = C_AT + handle;
href = gh();
href += own.call(OVERWRITES, handle) ? OVERWRITES[handle] : handle;
now.column++;
exit = self.enterLink();
node = eat(subvalue)({
type: 'link',
title: null,
url: href,
children: self.tokenizeInline(subvalue, now)
});
exit();
if (self.githubOptions.mentionStrong !== false) {
node.children = [{
type: 'strong',
children: node.children
}];
}
return node;
}