@kobalab/liulian 1.1.0 → 1.1.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 +6 -0
- package/css/liulian.css +4 -2
- package/lib/module/core.js +38 -3
- package/package.json +1 -1
package/ChangeLog.md
CHANGED
package/css/liulian.css
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
@charset "UTF-8";
|
|
2
2
|
|
|
3
3
|
html {
|
|
4
|
-
margin: 0 10px
|
|
4
|
+
margin: 0 10px;
|
|
5
5
|
}
|
|
6
6
|
body {
|
|
7
7
|
font-family: "Century Gothic", sans-serif;
|
|
8
8
|
font-size: 14px;
|
|
9
9
|
color: #333;
|
|
10
10
|
-webkit-text-size-adjust: 100%;
|
|
11
|
-
margin: 0 auto;
|
|
11
|
+
margin: 0 auto 10px;
|
|
12
12
|
overflow-wrap: break-word;
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -55,9 +55,11 @@ h4 {
|
|
|
55
55
|
}
|
|
56
56
|
h5 {
|
|
57
57
|
font-size: 110%;
|
|
58
|
+
margin: 1em auto;
|
|
58
59
|
}
|
|
59
60
|
h6 {
|
|
60
61
|
font-size: 100%;
|
|
62
|
+
margin: 1em auto;
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
@media screen and (max-width: 480px) {
|
package/lib/module/core.js
CHANGED
|
@@ -5,6 +5,23 @@
|
|
|
5
5
|
|
|
6
6
|
const { cdata, cref, fixpath } = require('../util/html-escape');
|
|
7
7
|
|
|
8
|
+
function stripComment(text) {
|
|
9
|
+
let rv = '', comment;
|
|
10
|
+
for (let line of text.replace(/\r?\n$/,'').split(/\r?\n/)) {
|
|
11
|
+
if (comment) {
|
|
12
|
+
if (line == '*/') comment = false;
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
if (line.match(/^\/\//)) continue;
|
|
16
|
+
if (line.match(/^\/\*/)) {
|
|
17
|
+
comment = true;
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
rv += line + '\n';
|
|
21
|
+
}
|
|
22
|
+
return rv;
|
|
23
|
+
}
|
|
24
|
+
|
|
8
25
|
module.exports = class Core {
|
|
9
26
|
|
|
10
27
|
constructor(parser) {
|
|
@@ -25,13 +42,30 @@ module.exports = class Core {
|
|
|
25
42
|
return value;
|
|
26
43
|
}
|
|
27
44
|
|
|
28
|
-
async contents(type, param) {
|
|
45
|
+
async contents(type, param = '') {
|
|
46
|
+
let [ s, e, c ] = param.split(/,\s*/);
|
|
47
|
+
s = s || 1;
|
|
48
|
+
let style;
|
|
49
|
+
if (c && e) {
|
|
50
|
+
c = c.replace(/\\/g,'\\\\');
|
|
51
|
+
style = '.l-contents' + ' li'.repeat(e-s+1)
|
|
52
|
+
+ ' { display: inline-block; }\n'
|
|
53
|
+
+ '.l-contents' + ' li'.repeat(e-s+1) + ' + li:before'
|
|
54
|
+
+ ` { content: ' ${c} '; }\n`;
|
|
55
|
+
}
|
|
56
|
+
s = new RegExp(`^\-{${+s-1}}`);
|
|
57
|
+
e = new RegExp(`^\-{${+e+1}}`);
|
|
29
58
|
const base = this._parser.get('toc').length;
|
|
30
59
|
const value = await this._parser.block();
|
|
31
60
|
this._parser.insertText(
|
|
32
|
-
this._parser.get('toc').slice(base)
|
|
61
|
+
this._parser.get('toc').slice(base)
|
|
62
|
+
.filter(line=>! line.match(e))
|
|
63
|
+
.map(line=>line.replace(s,''))
|
|
64
|
+
.filter(line=>line.match(/^\-/))
|
|
65
|
+
.join('\n'),
|
|
33
66
|
true
|
|
34
67
|
);
|
|
68
|
+
if (style) this._r.style(style);
|
|
35
69
|
return '<div class="l-contents">\n'
|
|
36
70
|
+ (await this._parser.block()).replace(/\n$/,'')
|
|
37
71
|
+ '</div>\n\n'
|
|
@@ -47,13 +81,14 @@ module.exports = class Core {
|
|
|
47
81
|
}
|
|
48
82
|
catch(code) { return '' }
|
|
49
83
|
};
|
|
84
|
+
if (! param) return '<div style="color:red">#nav()</div>\n\n';
|
|
50
85
|
const err = `<div style="color:red">#nav(${cdata(param)})</div>\n\n`;
|
|
51
86
|
let [ url, title, top ] = param.split(/,\s*/);
|
|
52
87
|
try {
|
|
53
88
|
let r = await this._r.openFile(this._req, url);
|
|
54
89
|
r = await r.open();
|
|
55
90
|
if (r.type != 'text/x-liulian') return err;
|
|
56
|
-
let toc = r.text.match(/\[\[.*?\]\]/g) || [];
|
|
91
|
+
let toc = stripComment(r.text).match(/\[\[.*?\]\]/g) || [];
|
|
57
92
|
let index = -1;
|
|
58
93
|
for (let i = 0; i < toc.length; i++) {
|
|
59
94
|
let loc = await location(
|