-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
36 lines (28 loc) · 892 Bytes
/
index.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
var patternRegex = /(((?:\{|\{)[^\}\}]+(?:\}|\})(?:\(|\()[^\}\}]+(?:\)|\)))+)/g;
var kanjiRegex = /(?:\{|\{)([^\}\}]+)(?:\}|\})(?:\(|\()([^\}\}]+)(?:\)|\))/g;
var KanjiExtension = function(converter) {
return [
{
type: 'lang',
filter: function(text) {
var match;
while (match = patternRegex.exec(text)) {
var html = ["<ruby>"];
var phrase = match[0];
while (secondMatch = kanjiRegex.exec(phrase)) {
var kanji = secondMatch[1];
var reading = secondMatch[2];
html.push(kanji);
html.push("<rt>");
html.push(reading);
html.push("</rt>");
}
html.push("</ruby>");
text = match.input.replace(phrase, html.join(""));
}
return text;
}
}
];
}
module.exports = KanjiExtension;