-
Notifications
You must be signed in to change notification settings - Fork 5
/
emojify.js
42 lines (35 loc) · 881 Bytes
/
emojify.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
/* jshint node:true */
var setEmojis = require('./setEmoji.js');
module.exports = function (md) {
return emoji.bind(null, md);
};
function get(state, line) {
var pos = state.bMarks[line];
var max = state.eMarks[line];
return state.src.substr(pos, max - pos);
}
function emoji(md, state, start, end) {
if (start !== 0 || state.blkIndent !== 0) {
return false;
}
if (state.tShift[start] < 0) {
return false;
}
var data = [];
for (var line = start; line < end; line++) {
var str = get(state, line);
if (str.match(/^---$/)) {
break;
}
if (state.tShift[line] < 0) {
break;
}
data.push(setEmojis(str));
}
state.src = data.join('\n') || {};
if (line >= end) {
return false;
}
state.line = line + 1;
return true;
}