-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
26 lines (24 loc) · 953 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
'use strict';
/**
* The ruby element allows one or more spans of phrasing content to be marked with ruby annotations.
* Ruby annotations are short runs of text presented alongside base text, primarily used in East Asian
* typography as a guide for pronunciation or to include other annotations. In Japanese, this form
* of typography is also known as furigana.
*
* Usage: {% ruby 汉<hàn>语<yǔ> %}
*/
function handleRuby(args) {
const rubys = args.join(' ').match(/.+?<.+?>/g);
if (rubys == null) return "";
let element = '';
rubys.forEach(arg => {
const groups = /(.+?)<(.+?)>/g.exec(arg);
if (groups.length === 3) {
const origin = groups[1].trim();
const ruby = groups[2].trim();
element += origin + '<rp>(</rp><rt>' + ruby + '</rt><rp>)</rp>';
}
});
return '<strong><ruby>' + element + '</ruby></strong>';
}
hexo.extend.tag.register('ruby', handleRuby);