@kobalab/liulian 0.8.0 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ChangeLog.md CHANGED
@@ -1,3 +1,18 @@
1
+ ### v0.9.1 / 2022-04-06
2
+
3
+ - paiga モジュールに空文字列を指定した場合に異常終了するバグを修正
4
+
5
+ ## v0.9.0 / 2022-04-03
6
+
7
+ - import モジュールで外部モジュールをインポートできるようにした
8
+ - pinyin モジュール(中国語のピンインを表示する)を追加
9
+ - paiga モジュール(麻雀の牌画像を表示する)を追加
10
+ - 脆弱性警告に対処(minimist 1.2.5 → 1.2.6)
11
+
12
+ ### v0.8.1 / 2022-01-24
13
+
14
+ - 脆弱性警告に対処(mocha 9.1.3 → 9.2.0)
15
+
1
16
  ## v0.8.0 / 2021-12-30
2
17
 
3
18
  - #4 自動バックアップの機能を追加
@@ -15,16 +15,16 @@ module.exports = class Module {
15
15
  this.import('core');
16
16
  }
17
17
 
18
- require(path) {
19
- try { return require(path) }
20
- catch(err) { console.log(err) }
21
- }
22
-
23
18
  import(module) {
24
- if (! modules[module]) modules[module] = this.require('./' + module);
25
- if (modules[module]) this._modules.push(
26
- new modules[module](this._parser));
27
- return modules[module];
19
+ try {
20
+ if (! modules[module]) modules[module] = require('./' + module);
21
+ this._modules.push(new modules[module](this._parser));
22
+ return modules[module];
23
+ }
24
+ catch(err) {
25
+ if (err.code) console.log(module, err.code);
26
+ else console.log(err);
27
+ }
28
28
  }
29
29
 
30
30
  callInlineModule(str, name, param, value) {
@@ -0,0 +1,124 @@
1
+ /*
2
+ * module/paiga
3
+ */
4
+ "use strict";
5
+
6
+ const imgbase = '//kobalab.github.io/paiga/';
7
+ const img = {
8
+ _: 'ura.gif',
9
+
10
+ m0: 'man5red.gif',
11
+ m1: 'man1.gif', m2: 'man2.gif', m3: 'man3.gif',
12
+ m4: 'man4.gif', m5: 'man5.gif', m6: 'man6.gif',
13
+ m7: 'man7.gif', m8: 'man8.gif', m9: 'man9.gif',
14
+
15
+ p0: 'pin5red.gif',
16
+ p1: 'pin1.gif', p2: 'pin2.gif', p3: 'pin3.gif',
17
+ p4: 'pin4.gif', p5: 'pin5.gif', p6: 'pin6.gif',
18
+ p7: 'pin7.gif', p8: 'pin8.gif', p9: 'pin9.gif',
19
+
20
+ s0: 'sou5red.gif',
21
+ s1: 'sou1.gif', s2: 'sou2.gif', s3: 'sou3.gif',
22
+ s4: 'sou4.gif', s5: 'sou5.gif', s6: 'sou6.gif',
23
+ s7: 'sou7.gif', s8: 'sou8.gif', s9: 'sou9.gif',
24
+
25
+ z1: 'ton.gif', z2: 'nan.gif', z3: 'sha.gif', z4: 'pei.gif',
26
+ z5: 'haku.gif', z6: 'hatu.gif', z7: 'tyun.gif',
27
+
28
+ m0_: 'yman5red.gif',
29
+ m1_: 'yman1.gif', m2_: 'yman2.gif', m3_: 'yman3.gif',
30
+ m4_: 'yman4.gif', m5_: 'yman5.gif', m6_: 'yman6.gif',
31
+ m7_: 'yman7.gif', m8_: 'yman8.gif', m9_: 'yman9.gif',
32
+
33
+ p0_: 'ypin5red.gif',
34
+ p1_: 'ypin1.gif', p2_: 'ypin2.gif', p3_: 'ypin3.gif',
35
+ p4_: 'ypin4.gif', p5_: 'ypin5.gif', p6_: 'ypin6.gif',
36
+ p7_: 'ypin7.gif', p8_: 'ypin8.gif', p9_: 'ypin9.gif',
37
+
38
+ s0_: 'ysou5red.gif',
39
+ s1_: 'ysou1.gif', s2_: 'ysou2.gif', s3_: 'ysou3.gif',
40
+ s4_: 'ysou4.gif', s5_: 'ysou5.gif', s6_: 'ysou6.gif',
41
+ s7_: 'ysou7.gif', s8_: 'ysou8.gif', s9_: 'ysou9.gif',
42
+
43
+ z1_: 'yton.gif', z2_: 'ynan.gif', z3_: 'ysha.gif', z4_: 'ypei.gif',
44
+ z5_: 'yhaku.gif', z6_: 'yhatu.gif', z7_: 'ytyun.gif'
45
+ };
46
+
47
+ function markup(paistr, w, h) {
48
+
49
+ let url, v = 0;
50
+ let html = '<span class="l-mod-paiga" style="white-space:pre;">';
51
+
52
+ for (let pai of paistr.match(/[mpsz](?:\d+[\-\=]?)+|[ _]|.+/g)||[]) {
53
+
54
+ if (pai == ' ') {
55
+ html += ' ';
56
+ }
57
+ else if (pai == '_') {
58
+ url = imgbase + img._;
59
+ html += `<img src="${url}" width="${w}" height="${h}"`
60
+ + ` alt="${pai}">`;
61
+ }
62
+ else if (pai.match(/^[mpsz](?:\d+[\-\=]?)+/)) {
63
+ let s = pai[0];
64
+ for (let n of pai.match(/\d[\-\=]?/g)) {
65
+ let d = n[1]||''; n = n[0];
66
+ if (d == '=' && ! v) {
67
+ html += `<span style="display:inline-block;width:${h}px">`;
68
+ v = 1;
69
+ }
70
+ if (d || v) {
71
+ url = imgbase + img[s+n+'_'];
72
+ if (d == '=') {
73
+ html += `<img src="${url}" width="${h}" height="${w}"`
74
+ + ` style="vertical-align:bottom;display:block"`
75
+ + ` alt="${s+n+'='}">`;
76
+ }
77
+ else {
78
+ html += `<img src="${url}" width="${h}" height="${w}"`
79
+ + ` alt="${s+n+'-'}">`;
80
+ }
81
+ }
82
+ else {
83
+ url = imgbase + img[s+n];
84
+ html += `<img src="${url}" width="${w}" height="${h}"`
85
+ + ` alt="${s+n}">`;
86
+ }
87
+ if (d != '=') {
88
+ if (v) html += '</span>';
89
+ v = 0;
90
+ }
91
+ }
92
+ }
93
+ else {
94
+ html += `<span style="color:red;">${pai}</span>`;
95
+ }
96
+ }
97
+ if (v) html += '</span>';
98
+ html += '</span>';
99
+ return html;
100
+ }
101
+
102
+ module.exports = class Paiga {
103
+
104
+ constructor(parser) {
105
+ this._parser = parser;
106
+ this._r = parser._r;
107
+ this._req = parser._r._req;
108
+ this._inline = ['paiga'];
109
+ this._block = [];
110
+ this._np = [];
111
+ }
112
+
113
+ paiga(type, param, value) {
114
+ let w = 24, h = 34;
115
+ if (! param) { w = 24; h = 34 }
116
+ else if (param == 'L') { w = 24; h = 34 }
117
+ else if (param == 'M') { w = 19; h = 24 }
118
+ else if (param == 'S') { w = 16; h = 23 }
119
+ else if (param.match(/^\d+x\d+$/)) {
120
+ [ w, h ] = param.split(/x/);
121
+ }
122
+ return markup(value, w, h);
123
+ }
124
+ }
@@ -0,0 +1,51 @@
1
+ /*
2
+ * module/pinyin
3
+ */
4
+ "use strict";
5
+
6
+ const tone_letter = {
7
+ a: ['ā','á','ǎ','à'],
8
+ e: ['ē','é','ě','è'],
9
+ o: ['ō','ó','ǒ','ò'],
10
+ i: ['ī','í','ǐ','ì'],
11
+ u: ['ū','ú','ǔ','ù'],
12
+ v: ['ǖ','ǘ','ǚ','ǜ'],
13
+ n: ['n̄','ń','ň','ǹ'],
14
+ A: ['Ā','Á','Ǎ','À'],
15
+ E: ['Ē','É','Ě','È'],
16
+ O: ['Ō','Ó','Ǒ','Ò'],
17
+ I: ['Ī','Í','Ǐ','Ì'],
18
+ U: ['Ū','Ú','Ǔ','Ù'],
19
+ V: ['Ǖ','Ǘ','Ǚ','Ǜ'],
20
+ N: ['N̄','Ń','Ň','Ǹ'],
21
+ };
22
+
23
+ function mark(str) {
24
+ const code = (c)=>tone_letter[c][n-1];
25
+ let [ , s, n ] = str.match(/^(.*?)(\d)$/);
26
+ if (s.match(/[aeo]/i)) return s.replace(/[aeo]/i, code);
27
+ if (s.match(/[iu]$/i)) return s.replace(/[iu]$/i, code);
28
+ if (s.match(/^[iuv]/i)) return s.replace(/^[iuv]/i, code);
29
+ else return s.replace(/n/i, code);
30
+ }
31
+
32
+ module.exports = class Pinyin {
33
+
34
+ constructor(parser) {
35
+ this._parser = parser;
36
+ this._r = parser._r;
37
+ this._req = parser._r._req;
38
+ this._inline = ['pinyin'];
39
+ this._block = ['pinyin'];
40
+ this._np = [];
41
+ }
42
+
43
+ pinyin(type, param, value) {
44
+ value = value.replace(/([aeouiv][1234])([aeo])/ig, '$1-$2');
45
+ value = value.replace(/[iuv]?[aeo]?(?:i|u|o|n|ng)?[1234]/ig, mark);
46
+ value = value.replace(/v/g, 'ü').replace(/V/g, 'Ü');
47
+ return type == '#'
48
+ ? `<div class="l-mod-pinyin">${value}</div>`
49
+ : `<span class="l-mod-pinyin">${value}</span>`;
50
+ }
51
+ }
@@ -381,6 +381,7 @@ class LiuLian {
381
381
  let [ , name, param, eod ]
382
382
  = line.match(/^#(\w+)(?:\((.*?)\))?(?:<<(\S+))?$/);
383
383
  if (name == '_') return await this.tag(line, param, eod);
384
+ if (name == 'import') return this.import(line, param);
384
385
 
385
386
  return await this._module.callBlockModule(line, name, param, eod);
386
387
  }
@@ -402,6 +403,11 @@ class LiuLian {
402
403
  }
403
404
  }
404
405
 
406
+ import(line, param) {
407
+ if (this._module.import(param)) return '';
408
+ return '<div style="color:red">' + cdata(line) + '</div>\n\n';
409
+ }
410
+
405
411
  inlineModule(str, name, param, value) {
406
412
  return this._module.callInlineModule(str, name, param, value);
407
413
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kobalab/liulian",
3
- "version": "0.8.0",
3
+ "version": "0.9.1",
4
4
  "description": "Node.jsで動作するWebサイト作成ツール",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "homepage": "https://kobalab.net/liulian/",
29
29
  "devDependencies": {
30
- "mocha": "^9.1.3",
30
+ "mocha": "^9.2.0",
31
31
  "nyc": "^15.1.0"
32
32
  },
33
33
  "dependencies": {