total5 0.0.1-4 → 0.0.1-6
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/builders.js +12 -4
- package/bundles.js +2 -12
- package/controller.js +11 -1
- package/flow-flowstream.js +8 -4
- package/flow.js +17 -0
- package/flowstream.js +3 -2
- package/global.js +1 -0
- package/index.js +38 -11
- package/markdown.js +752 -0
- package/package.json +1 -1
- package/tms.js +1 -1
- package/utils.js +6 -0
package/builders.js
CHANGED
|
@@ -1159,13 +1159,17 @@ exports.newaction = function(name, obj) {
|
|
|
1159
1159
|
return obj;
|
|
1160
1160
|
};
|
|
1161
1161
|
|
|
1162
|
+
function ActionCallerExec(self) {
|
|
1163
|
+
self.exec();
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1162
1166
|
function ActionCaller() {
|
|
1163
1167
|
var self = this;
|
|
1164
1168
|
self.$ = new Options();
|
|
1165
1169
|
self.error = new ErrorBuilder();
|
|
1166
1170
|
self.options = {};
|
|
1167
1171
|
self.actions = [];
|
|
1168
|
-
setImmediate(
|
|
1172
|
+
setImmediate(ActionCallerExec, self);
|
|
1169
1173
|
}
|
|
1170
1174
|
|
|
1171
1175
|
ActionCaller.prototype.debug = function() {
|
|
@@ -1271,13 +1275,15 @@ ActionCaller.prototype.exec = function() {
|
|
|
1271
1275
|
if (action.jsquery) {
|
|
1272
1276
|
self.error.prefix = 'query.';
|
|
1273
1277
|
response = action.jsquery.transform(query, false, self.error);
|
|
1278
|
+
console.log(query, response, action);
|
|
1274
1279
|
self.error.prefix = '';
|
|
1275
1280
|
if (response.error) {
|
|
1276
1281
|
self.cancel();
|
|
1277
1282
|
return;
|
|
1278
1283
|
}
|
|
1279
1284
|
$.query = response.response;
|
|
1280
|
-
}
|
|
1285
|
+
} else
|
|
1286
|
+
$.query = query;
|
|
1281
1287
|
|
|
1282
1288
|
if (action.jsparams) {
|
|
1283
1289
|
self.error.prefix = 'params.';
|
|
@@ -1288,7 +1294,8 @@ ActionCaller.prototype.exec = function() {
|
|
|
1288
1294
|
return;
|
|
1289
1295
|
}
|
|
1290
1296
|
$.params = response.response;
|
|
1291
|
-
}
|
|
1297
|
+
} else
|
|
1298
|
+
$.params = params;
|
|
1292
1299
|
|
|
1293
1300
|
if (action.jsinput && type !== '-') {
|
|
1294
1301
|
response = action.jsinput.transform(payload, type === '%', self.error);
|
|
@@ -1297,7 +1304,8 @@ ActionCaller.prototype.exec = function() {
|
|
|
1297
1304
|
return;
|
|
1298
1305
|
}
|
|
1299
1306
|
$.payload = response.response;
|
|
1300
|
-
}
|
|
1307
|
+
} else
|
|
1308
|
+
$.payload = payload;
|
|
1301
1309
|
|
|
1302
1310
|
action.action($, $.payload);
|
|
1303
1311
|
};
|
package/bundles.js
CHANGED
|
@@ -400,7 +400,7 @@ exports.extract = function(callback, skip) {
|
|
|
400
400
|
try {
|
|
401
401
|
|
|
402
402
|
if (F.Fs.readFileSync('bundles.debug')) {
|
|
403
|
-
F.
|
|
403
|
+
F.isBundle = true;
|
|
404
404
|
F.dir(F.path.root('/.src/'));
|
|
405
405
|
callback();
|
|
406
406
|
return;
|
|
@@ -428,7 +428,7 @@ exports.extract = function(callback, skip) {
|
|
|
428
428
|
});
|
|
429
429
|
}, function() {
|
|
430
430
|
extract(function() {
|
|
431
|
-
F.
|
|
431
|
+
F.isBundle = true;
|
|
432
432
|
F.dir(F.path.root('/.src/'));
|
|
433
433
|
callback();
|
|
434
434
|
});
|
|
@@ -436,21 +436,11 @@ exports.extract = function(callback, skip) {
|
|
|
436
436
|
};
|
|
437
437
|
|
|
438
438
|
try {
|
|
439
|
-
|
|
440
439
|
var files = F.Fs.readdirSync(bundles);
|
|
441
440
|
if (files.length)
|
|
442
441
|
extractbundles();
|
|
443
442
|
else
|
|
444
443
|
callback();
|
|
445
|
-
|
|
446
|
-
/*
|
|
447
|
-
if (F.$bundling) {
|
|
448
|
-
makebundle();
|
|
449
|
-
return;
|
|
450
|
-
} else {
|
|
451
|
-
F.isbundle = true;
|
|
452
|
-
F.dir(F.path.root('/.src/'));
|
|
453
|
-
}*/
|
|
454
444
|
} catch(e) {
|
|
455
445
|
callback();
|
|
456
446
|
}
|
package/controller.js
CHANGED
|
@@ -11,7 +11,7 @@ const REG_MOBILE = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Min
|
|
|
11
11
|
const REG_ENCODINGCLEANER = /[;\s]charset=utf-8/g;
|
|
12
12
|
|
|
13
13
|
const CHECK_DATA = { POST: 1, PUT: 1, PATCH: 1, DELETE: 1 };
|
|
14
|
-
const CHECK_COMPRESSION = { 'text/plain': true, 'text/javascript': true, 'text/css': true, 'text/jsx': true, 'application/javascript': true, 'application/x-javascript': true, 'application/json': true, 'text/xml': true, 'image/svg+xml': true, 'text/x-markdown': true, 'text/html': true };
|
|
14
|
+
const CHECK_COMPRESSION = { 'text/plain': true, 'text/javascript': true, 'text/css': true, 'text/jsx': true, 'application/javascript': true, 'application/x-javascript': true, 'application/json': true, 'application/xml': true, 'text/xml': true, 'image/svg+xml': true, 'text/x-markdown': true, 'text/html': true };
|
|
15
15
|
const CHECK_CHARSET = { 'text/plain': true, 'text/javascript': true, 'text/css': true, 'text/jsx': true, 'application/javascript': true, 'application/x-javascript': true, 'application/json': true, 'text/xml': true, 'text/x-markdown': true, 'text/html': true };
|
|
16
16
|
const CHECK_NOCACHE = { zip: 1, rar: 1 };
|
|
17
17
|
|
|
@@ -998,6 +998,15 @@ function execute(ctrl) {
|
|
|
998
998
|
if (ctrl.route.api) {
|
|
999
999
|
let body = ctrl.body;
|
|
1000
1000
|
if (body && typeof(body) === 'object' && body.schema && typeof(body.schema) === 'string') {
|
|
1001
|
+
|
|
1002
|
+
let index = body.schema.indexOf('?');
|
|
1003
|
+
let query = null;
|
|
1004
|
+
|
|
1005
|
+
if (index !== -1) {
|
|
1006
|
+
query = body.schema.substring(index + 1);
|
|
1007
|
+
body.schema = body.schema.substring(0, index);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1001
1010
|
let schema = body.schema.split('/');
|
|
1002
1011
|
let endpoint = ctrl.route.api[schema[0]];
|
|
1003
1012
|
let params = {};
|
|
@@ -1009,6 +1018,7 @@ function execute(ctrl) {
|
|
|
1009
1018
|
body = body.data;
|
|
1010
1019
|
if (!body || typeof(body) === 'object') {
|
|
1011
1020
|
ctrl.params = params;
|
|
1021
|
+
ctrl.query = query ? query.parseEncoded() : {};
|
|
1012
1022
|
F.action(endpoint.actions, body || {}, ctrl).autorespond();
|
|
1013
1023
|
return;
|
|
1014
1024
|
}
|
package/flow-flowstream.js
CHANGED
|
@@ -586,12 +586,16 @@ Instance.prototype.reload = function(data, restart = false) {
|
|
|
586
586
|
else
|
|
587
587
|
flow.kill(9);
|
|
588
588
|
} else
|
|
589
|
-
flow.postMessage2({ TYPE: 'stream/
|
|
589
|
+
flow.postMessage2({ TYPE: 'stream/rewrite', data: data });
|
|
590
590
|
} else {
|
|
591
591
|
for (let key in data)
|
|
592
592
|
flow.$schema[key] = data[key];
|
|
593
593
|
flow.variables = data.variables;
|
|
594
|
-
|
|
594
|
+
|
|
595
|
+
if (data.variables2)
|
|
596
|
+
flow.variables2 = data.variables2;
|
|
597
|
+
|
|
598
|
+
flow.rewrite(data, () => flow.proxy.refreshmeta());
|
|
595
599
|
}
|
|
596
600
|
|
|
597
601
|
return self;
|
|
@@ -1065,11 +1069,11 @@ function init_current(meta, callback, nested) {
|
|
|
1065
1069
|
flow.save();
|
|
1066
1070
|
break;
|
|
1067
1071
|
|
|
1068
|
-
case 'stream/
|
|
1072
|
+
case 'stream/rewrite':
|
|
1069
1073
|
for (var key in msg.data)
|
|
1070
1074
|
flow.$schema[key] = msg.data[key];
|
|
1071
1075
|
|
|
1072
|
-
flow.
|
|
1076
|
+
flow.rewrite(msg.data, function() {
|
|
1073
1077
|
|
|
1074
1078
|
// @err {Error}
|
|
1075
1079
|
|
package/flow.js
CHANGED
|
@@ -214,6 +214,23 @@ FS.notify = function(controller, id) {
|
|
|
214
214
|
$.success();
|
|
215
215
|
};
|
|
216
216
|
|
|
217
|
+
FS.restart = function(id) {
|
|
218
|
+
let item = FS.instances[id];
|
|
219
|
+
if (item) {
|
|
220
|
+
if (item.flow) {
|
|
221
|
+
if (item.flow.terminate)
|
|
222
|
+
item.flow.terminate();
|
|
223
|
+
else
|
|
224
|
+
item.flow.kill(9);
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
FS.save = function(data) {
|
|
231
|
+
FS.onsave(data);
|
|
232
|
+
};
|
|
233
|
+
|
|
217
234
|
FS.ping = function() {
|
|
218
235
|
// ping all services
|
|
219
236
|
for (let key in FS.instances) {
|
package/flowstream.js
CHANGED
|
@@ -277,7 +277,7 @@ function variables(str, data, encoding) {
|
|
|
277
277
|
if (typeof(str) !== 'string' || str.indexOf('{') === -1)
|
|
278
278
|
return str;
|
|
279
279
|
|
|
280
|
-
var main = this.main;
|
|
280
|
+
var main = this.main ? this.main : this;
|
|
281
281
|
|
|
282
282
|
if (data == null || data == true)
|
|
283
283
|
data = this;
|
|
@@ -1276,7 +1276,8 @@ FP.load = function(data, callback) {
|
|
|
1276
1276
|
return self;
|
|
1277
1277
|
};
|
|
1278
1278
|
|
|
1279
|
-
FP.replace =
|
|
1279
|
+
FP.replace = variables;
|
|
1280
|
+
FP.rewrite = function(data, callback) {
|
|
1280
1281
|
|
|
1281
1282
|
var self = this;
|
|
1282
1283
|
if (self.loading) {
|
package/global.js
CHANGED
package/index.js
CHANGED
|
@@ -37,6 +37,7 @@ global.DEF = {};
|
|
|
37
37
|
F.id = '';
|
|
38
38
|
F.clusterid = '';
|
|
39
39
|
F.is5 = F.version = 5000;
|
|
40
|
+
F.isBundle = false;
|
|
40
41
|
F.version_header = '5';
|
|
41
42
|
F.version_node = process.version + '';
|
|
42
43
|
F.EMPTYOBJECT = EMPTYOBJECT;
|
|
@@ -343,7 +344,7 @@ function unlink(arr, callback) {
|
|
|
343
344
|
CONF.$httpmaxsize = 256; // 256 kB
|
|
344
345
|
CONF.$httprangebuffer = 5120; // 5 MB
|
|
345
346
|
CONF.$httptimeout = 5; // 5 seconds
|
|
346
|
-
CONF.$httpfiles = { flac: true, jpg: true, jpeg: true, png: true, gif: true, ico: true, wasm: true, js: true, mjs: true, css: true, txt: true, xml: true, woff: true, woff2: true, otf: true, ttf: true, eot: true, svg: true, zip: true, rar: true, pdf: true, docx: true, xlsx: true, doc: true, xls: true, html: true, htm: true, appcache: true, manifest: true, map: true, ogv: true, ogg: true, mp4: true, mp3: true, webp: true, webm: true, swf: true, package: true, json: true, ui: true, md: true, m4v: true, jsx: true, heif: true, heic: true, ics: true, ts: true, m3u8: true, wav: true };
|
|
347
|
+
CONF.$httpfiles = { flac: true, jpg: true, jpeg: true, png: true, gif: true, ico: true, wasm: true, js: true, mjs: true, css: true, txt: true, xml: true, woff: true, woff2: true, otf: true, ttf: true, eot: true, svg: true, zip: true, rar: true, pdf: true, docx: true, xlsx: true, doc: true, xls: true, html: true, htm: true, appcache: true, manifest: true, map: true, ogv: true, ogg: true, mp4: true, mp3: true, webp: true, webm: true, swf: true, package: true, json: true, ui: true, md: true, m4v: true, jsx: true, heif: true, heic: true, ics: true, ts: true, m3u8: true, wav: true, xsd: true, xsl: true, xslt: true };
|
|
347
348
|
CONF.$httpchecktypes = true; // for multipart data only
|
|
348
349
|
CONF.$blacklist = '';
|
|
349
350
|
CONF.$xpoweredby = 'Total.js';
|
|
@@ -489,7 +490,7 @@ function unlink(arr, callback) {
|
|
|
489
490
|
if (F.errors.push(obj) > 10)
|
|
490
491
|
F.errors.shift();
|
|
491
492
|
|
|
492
|
-
|
|
493
|
+
F.$events.error && F.emit('error', obj);
|
|
493
494
|
F.stats.error++;
|
|
494
495
|
};
|
|
495
496
|
|
|
@@ -730,21 +731,35 @@ F.load = async function(types, callback) {
|
|
|
730
731
|
}
|
|
731
732
|
|
|
732
733
|
if (!types.length || types.includes('env')) {
|
|
733
|
-
|
|
734
|
+
let env = await read(F.path.root('.env'));
|
|
734
735
|
env && F.loadenv(env);
|
|
735
736
|
}
|
|
736
737
|
|
|
737
738
|
if (!types.length || types.includes('config')) {
|
|
738
|
-
|
|
739
|
+
let config = await read(F.path.root('config'));
|
|
739
740
|
config && F.loadconfig(config);
|
|
740
741
|
}
|
|
741
742
|
|
|
742
743
|
if (!types.length || types.includes('resources')) {
|
|
743
|
-
|
|
744
|
+
let resources = await list(F.path.root('resources'), 'resource');
|
|
744
745
|
for (let resource of resources)
|
|
745
746
|
F.loadresource(F.TUtils.getName(resource).replace(/\.resource$/i, ''), await read(resource));
|
|
746
747
|
}
|
|
747
748
|
|
|
749
|
+
if (!types.length || types.includes('jsonschemas')) {
|
|
750
|
+
let jsonschemas = await list(F.path.root('jsonschemas'), 'json');
|
|
751
|
+
for (let jsonschema of jsonschemas) {
|
|
752
|
+
let json = await read(jsonschema);
|
|
753
|
+
json = json.parseJSON();
|
|
754
|
+
json && F.newjsonschema(F.TUtils.getName(jsonschema).replace(/\.json$/i, ''), json);
|
|
755
|
+
}
|
|
756
|
+
jsonschemas = await list(F.path.root('jsonschemas'), 'txt');
|
|
757
|
+
for (let jsonschema of jsonschemas) {
|
|
758
|
+
let txt = await read(jsonschema);
|
|
759
|
+
txt && F.newjsonschema(F.TUtils.getName(jsonschema).replace(/\.txt$/i, ''), txt);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
|
|
748
763
|
let loader = ['modules', 'controllers', 'actions', 'schemas', 'models', 'definitions', 'sources', 'middleware'];
|
|
749
764
|
var files = [];
|
|
750
765
|
var tmp;
|
|
@@ -2274,6 +2289,10 @@ F.backup = function(filename, files, callback, filter) {
|
|
|
2274
2289
|
});
|
|
2275
2290
|
};
|
|
2276
2291
|
|
|
2292
|
+
F.restart = function() {
|
|
2293
|
+
process.send && process.send('total:restart');
|
|
2294
|
+
};
|
|
2295
|
+
|
|
2277
2296
|
F.exit = function(signal) {
|
|
2278
2297
|
|
|
2279
2298
|
if (F.isexited)
|
|
@@ -2291,7 +2310,7 @@ F.exit = function(signal) {
|
|
|
2291
2310
|
} catch (e) {}
|
|
2292
2311
|
}
|
|
2293
2312
|
|
|
2294
|
-
let key = '
|
|
2313
|
+
let key = 'exit';
|
|
2295
2314
|
|
|
2296
2315
|
F.$events[key] && F.emit(key, signal);
|
|
2297
2316
|
|
|
@@ -2425,6 +2444,12 @@ F.mail = function(email, subject, name, model, language, callback) {
|
|
|
2425
2444
|
callback = tmp;
|
|
2426
2445
|
}
|
|
2427
2446
|
|
|
2447
|
+
// Localization
|
|
2448
|
+
if (typeof(language) === 'string') {
|
|
2449
|
+
if (subject.includes('@('))
|
|
2450
|
+
subject = TRANSLATE(language, subject);
|
|
2451
|
+
}
|
|
2452
|
+
|
|
2428
2453
|
let body = F.view(name, model, view => view.language = language || '');
|
|
2429
2454
|
return F.def.onMail(email, subject, body, callback);
|
|
2430
2455
|
};
|
|
@@ -2437,14 +2462,15 @@ F.htmlmail = function(email, subject, body, language, callback) {
|
|
|
2437
2462
|
callback = tmp;
|
|
2438
2463
|
}
|
|
2439
2464
|
|
|
2440
|
-
//
|
|
2465
|
+
// Localization
|
|
2441
2466
|
if (typeof(language) === 'string') {
|
|
2442
|
-
|
|
2443
|
-
|
|
2444
|
-
|
|
2467
|
+
if (subject.includes('@('))
|
|
2468
|
+
subject = TRANSLATE(language, subject);
|
|
2469
|
+
if (body.includes('@('))
|
|
2470
|
+
body = TRANSLATE(language, body);
|
|
2445
2471
|
}
|
|
2446
2472
|
|
|
2447
|
-
|
|
2473
|
+
body = body.indexOf('<body>') === -1 ? ('<!DOCTYPE html><html><head><title>' + subject + '</title><meta charset="utf-8" /></head><body style="padding:0;margin:0;font-family:Arial;font-size:14px;font-weight:normal">' + body + '</body></html>') : body;
|
|
2448
2474
|
return F.def.onMail(email, subject, body, callback);
|
|
2449
2475
|
};
|
|
2450
2476
|
|
|
@@ -2679,6 +2705,7 @@ process.connected && setTimeout(() => process.send('total:init'), 100);
|
|
|
2679
2705
|
|
|
2680
2706
|
require('./global');
|
|
2681
2707
|
require('./tangular');
|
|
2708
|
+
require('./markdown');
|
|
2682
2709
|
|
|
2683
2710
|
// Init directories
|
|
2684
2711
|
F.dir();
|
package/markdown.js
ADDED
|
@@ -0,0 +1,752 @@
|
|
|
1
|
+
const REG_DASH = /-{2,}/g;
|
|
2
|
+
const REG_TAGS = /<[^>]*>/g;
|
|
3
|
+
const REG_EMPTYCHAR = /\s|\W/;
|
|
4
|
+
const REG_ICONS = /(^|[^\w]):((fab|far|fas|fal|fad|fa|ti)\s(fa|ti)-)?[a-z-]+:([^\w]|$)/g;
|
|
5
|
+
const REG_KEYWORDS = /\{.*?\}\(.*?\)/g;
|
|
6
|
+
const REG_LINKEXTERNAL = /(https|http):\/\//;
|
|
7
|
+
const REG_FORMAT = /__.*?__|_.*?_|\*\*.*?\*\*|\*.*?\*|~~.*?~~|~.*?~/g;
|
|
8
|
+
const REG_ORDERED = /^[a-z|0-9]{1,3}\.\s|^-\s/i;
|
|
9
|
+
const REG_ORDEREDSIZE = /^(\s|\t)+/;
|
|
10
|
+
const REG_CODE = /`.*?`/g;
|
|
11
|
+
const REG_ENCODETAGS = /<|>/g;
|
|
12
|
+
const ENCODE = val => '&' + (val === '<' ? 'lt' : 'gt') + ';';
|
|
13
|
+
const REG_NIL = /\0/g;
|
|
14
|
+
|
|
15
|
+
function markdown_code(value) {
|
|
16
|
+
return value ? ('<code>' + value.substring(1, value.length - 1) + '</code>') : '';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function markdown_imagelinks(value) {
|
|
20
|
+
|
|
21
|
+
if (!value)
|
|
22
|
+
return '';
|
|
23
|
+
|
|
24
|
+
var end = value.lastIndexOf(')') + 1;
|
|
25
|
+
var img = value.substring(0, end);
|
|
26
|
+
var url = value.substring(end + 2, value.length - 1);
|
|
27
|
+
var label = markdown_links(img);
|
|
28
|
+
var footnote = label.substring(0, 13);
|
|
29
|
+
|
|
30
|
+
if (footnote === '<sup data-id=' || footnote === '<span data-id' || label.substring(0, 9) === '<a href="')
|
|
31
|
+
return label;
|
|
32
|
+
|
|
33
|
+
return '<a href="' + url + '"' + (REG_LINKEXTERNAL.test(url) ? ' target="_blank"' : '') + '>' + label + '</a>';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function markdown_table(value, align, ishead) {
|
|
37
|
+
|
|
38
|
+
var columns = value.substring(1, value.length - 1).split('|');
|
|
39
|
+
var builder = '';
|
|
40
|
+
|
|
41
|
+
for (var i = 0; i < columns.length; i++) {
|
|
42
|
+
var column = columns[i].trim();
|
|
43
|
+
if (column.charAt(0) != '-') {
|
|
44
|
+
var a = align[i];
|
|
45
|
+
builder += '<' + (ishead ? 'th' : 'td') + (a && a !== 'left' ? (' class="' + a + '"') : '') + '>' + column + '</' + (ishead ? 'th' : 'td') + '>';
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return '<tr>' + builder + '</tr>';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function markdown_links(value) {
|
|
53
|
+
|
|
54
|
+
if (!value)
|
|
55
|
+
return '';
|
|
56
|
+
|
|
57
|
+
var end = value.lastIndexOf(']');
|
|
58
|
+
var img = value.charAt(0) === '!';
|
|
59
|
+
var text = value.substring(img ? 2 : 1, end);
|
|
60
|
+
var link = value.substring(end + 2, value.length - 1);
|
|
61
|
+
|
|
62
|
+
// footnotes
|
|
63
|
+
if ((/^#\d+$/).test(link)) {
|
|
64
|
+
return (/^\d+$/).test(text) ? '<sup data-id="{0}" class="markdown-footnote">{1}</sup>'.format(link.substring(1), text) : '<span data-id="{0}" class="markdown-footnote">{1}</span>'.format(link.substring(1), text);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (link.substring(0, 4) === 'www.')
|
|
68
|
+
link = 'https://' + link;
|
|
69
|
+
|
|
70
|
+
var nofollow = link.charAt(0) === '@' ? ' rel="nofollow"' : REG_LINKEXTERNAL.test(link) ? ' target="_blank"' : '';
|
|
71
|
+
return '<a href="' + link + '"' + nofollow + '>' + text + '</a>';
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function markdown_image(value) {
|
|
75
|
+
|
|
76
|
+
var end = value.lastIndexOf(']');
|
|
77
|
+
var text = value.substring(2, end);
|
|
78
|
+
var link = value.substring(end + 2, value.length - 1);
|
|
79
|
+
var responsive = 1;
|
|
80
|
+
var f = text.charAt(0);
|
|
81
|
+
|
|
82
|
+
if (f === '+') {
|
|
83
|
+
responsive = 2;
|
|
84
|
+
text = text.substring(1);
|
|
85
|
+
} else if (f === '-') {
|
|
86
|
+
// gallery
|
|
87
|
+
responsive = 3;
|
|
88
|
+
text = text.substring(1);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return '<img src="' + link + '" alt="' + text + '"' + (responsive === 1 ? ' class="img-responsive"' : responsive === 3 ? ' class="markdown-gallery"' : '') + ' border="0" loading="lazy" />';
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function markdown_keywords(value) {
|
|
95
|
+
var keyword = value.substring(1, value.indexOf('}'));
|
|
96
|
+
var type = value.substring(value.lastIndexOf('(') + 1, value.lastIndexOf(')'));
|
|
97
|
+
return '<span class="markdown-keyword" data-type="{0}">{1}</span>'.format(type, keyword);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function markdown_links2(value) {
|
|
101
|
+
value = value.substring(4, value.length - 4);
|
|
102
|
+
return '<a href="' + (value.isEmail() ? 'mailto:' : REG_LINKEXTERNAL.test(value) ? '' : 'http://') + value + '" target="_blank">' + value + '</a>';
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function markdown_format(value, index, text) {
|
|
106
|
+
|
|
107
|
+
var p = text.charAt(index - 1);
|
|
108
|
+
var n = text.charAt(index + value.length);
|
|
109
|
+
|
|
110
|
+
if ((!p || REG_EMPTYCHAR.test(p)) && (!n || REG_EMPTYCHAR.test(n))) {
|
|
111
|
+
|
|
112
|
+
var beg = '';
|
|
113
|
+
var end = '';
|
|
114
|
+
var tag;
|
|
115
|
+
|
|
116
|
+
if (value.indexOf('*') !== -1) {
|
|
117
|
+
tag = value.indexOf('**') === -1 ? 'em' : 'strong';
|
|
118
|
+
beg += '<' + tag + '>';
|
|
119
|
+
end = '</' + tag + '>' + end;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (value.indexOf('_') !== -1) {
|
|
123
|
+
tag = value.indexOf('__') === -1 ? 'u' : 'b';
|
|
124
|
+
beg += '<' + tag + '>';
|
|
125
|
+
end = '</' + tag + '>' + end;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (value.indexOf('~') !== -1) {
|
|
129
|
+
beg += '<strike>';
|
|
130
|
+
end = '</strike>' + end;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
var count = value.charAt(1) === value.charAt(0) ? 2 : 1;
|
|
134
|
+
return beg + value.substring(count, value.length - count) + end;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return value;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function markdown_id(value) {
|
|
141
|
+
value = value.replace(REG_TAGS, '');
|
|
142
|
+
return value.slug().replace(REG_DASH, '-');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function markdown_icon(value) {
|
|
146
|
+
|
|
147
|
+
var beg = -1;
|
|
148
|
+
var end = -1;
|
|
149
|
+
|
|
150
|
+
for (var i = 0; i < value.length; i++) {
|
|
151
|
+
var code = value.charCodeAt(i);
|
|
152
|
+
if (code === 58) {
|
|
153
|
+
if (beg === -1)
|
|
154
|
+
beg = i + 1;
|
|
155
|
+
else
|
|
156
|
+
end = i;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
var icon = value.substring(beg, end);
|
|
161
|
+
if (icon.indexOf(' ') === -1)
|
|
162
|
+
icon = 'ti ti-' + icon;
|
|
163
|
+
return value.substring(0, beg - 1) + '<i class="' + icon + '"></i>' + value.substring(end + 1);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function markdown_urlify(str) {
|
|
167
|
+
return str.replace(/(^|\s)+(((https?:\/\/)|(www\.))[^\s]+)/g, function(url, b, c) {
|
|
168
|
+
var len = url.length;
|
|
169
|
+
var l = url.charAt(len - 1);
|
|
170
|
+
var f = url.charAt(0);
|
|
171
|
+
if (l === '.' || l === ',')
|
|
172
|
+
url = url.substring(0, len - 1);
|
|
173
|
+
else
|
|
174
|
+
l = '';
|
|
175
|
+
url = (c === 'www.' ? 'http://' + url : url).trim();
|
|
176
|
+
return (f.charCodeAt(0) < 40 ? f : '') + '[' + url + '](' + url + ')' + l;
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function parseul(builder) {
|
|
181
|
+
|
|
182
|
+
var ul = {};
|
|
183
|
+
var is = false;
|
|
184
|
+
var currentindex = -1;
|
|
185
|
+
var output = [];
|
|
186
|
+
|
|
187
|
+
for (var i = 0; i < builder.length; i++) {
|
|
188
|
+
|
|
189
|
+
var line = builder[i];
|
|
190
|
+
|
|
191
|
+
if (line.charAt(0) === '\0') {
|
|
192
|
+
|
|
193
|
+
if (!is)
|
|
194
|
+
currentindex = output.push('<ul />') - 1;
|
|
195
|
+
|
|
196
|
+
var key = currentindex + '';
|
|
197
|
+
is = true;
|
|
198
|
+
|
|
199
|
+
var tmp = line.substring(1);
|
|
200
|
+
var index = tmp.indexOf('<');
|
|
201
|
+
var obj = {};
|
|
202
|
+
obj.index = i;
|
|
203
|
+
obj.type = tmp.substring(0, 2);
|
|
204
|
+
obj.offset = +tmp.substring(2, index).trim();
|
|
205
|
+
obj.line = line.substring(index + 1);
|
|
206
|
+
|
|
207
|
+
if (ul[key])
|
|
208
|
+
ul[key].push(obj);
|
|
209
|
+
else
|
|
210
|
+
ul[key] = [obj];
|
|
211
|
+
|
|
212
|
+
} else {
|
|
213
|
+
output.push(line);
|
|
214
|
+
is = false;
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
for (var key in ul) {
|
|
219
|
+
|
|
220
|
+
var line = +key;
|
|
221
|
+
var arr = ul[key];
|
|
222
|
+
var lines = [];
|
|
223
|
+
var tags = [];
|
|
224
|
+
var prev;
|
|
225
|
+
var diff;
|
|
226
|
+
var init = false;
|
|
227
|
+
var tmp;
|
|
228
|
+
|
|
229
|
+
for (var i = 0; i < arr.length; i++) {
|
|
230
|
+
|
|
231
|
+
var li = arr[i];
|
|
232
|
+
var beg = li.type === 'ul' ? '<ul>' : li.type === 'o1' ? '<ol type="1">' : '<ol type="a">';
|
|
233
|
+
var end = li.type === 'ul' ? '</ul>' : '</ol>';
|
|
234
|
+
|
|
235
|
+
var diff = li.offset - (prev ? prev.offset : 0);
|
|
236
|
+
|
|
237
|
+
// Init
|
|
238
|
+
if (!init) {
|
|
239
|
+
init = true;
|
|
240
|
+
lines.push(beg);
|
|
241
|
+
tags.push(end);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (diff > 0) {
|
|
245
|
+
var last = lines[lines.length - 1];
|
|
246
|
+
last = last.replace(/<\/li>$/, '');
|
|
247
|
+
lines[lines.length - 1] = last;
|
|
248
|
+
tags.push(end + '</li>');
|
|
249
|
+
lines.push(beg);
|
|
250
|
+
lines.push(li.line);
|
|
251
|
+
} else if (diff < 0) {
|
|
252
|
+
while (diff < 0) {
|
|
253
|
+
tmp = tags.pop();
|
|
254
|
+
lines.push(tmp);
|
|
255
|
+
diff++;
|
|
256
|
+
}
|
|
257
|
+
lines.push(li.line);
|
|
258
|
+
} else {
|
|
259
|
+
lines.push(li.line);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
prev = li;
|
|
263
|
+
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
while (tags.length)
|
|
267
|
+
lines.push(tags.pop());
|
|
268
|
+
|
|
269
|
+
output[line] = lines.join('\n');
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return output;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
function formatline(line) {
|
|
276
|
+
var tmp = [];
|
|
277
|
+
return line.replace(REG_CODE, function(text) {
|
|
278
|
+
tmp.push(text);
|
|
279
|
+
return '\0';
|
|
280
|
+
}).replace(REG_FORMAT, markdown_format).replace(REG_NIL, () => markdown_code(tmp.shift()));
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function imagescope(val) {
|
|
284
|
+
|
|
285
|
+
var beg = -1;
|
|
286
|
+
var can = false;
|
|
287
|
+
var n;
|
|
288
|
+
|
|
289
|
+
for (var i = 0; i < val.length; i++) {
|
|
290
|
+
var c = val.charAt(i);
|
|
291
|
+
|
|
292
|
+
if (c === '[') {
|
|
293
|
+
beg = i;
|
|
294
|
+
can = false;
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
if (c === ']') {
|
|
299
|
+
|
|
300
|
+
can = false;
|
|
301
|
+
|
|
302
|
+
if (beg === -1)
|
|
303
|
+
continue;
|
|
304
|
+
|
|
305
|
+
n = val.charAt(i + 1);
|
|
306
|
+
|
|
307
|
+
// maybe a link mistake
|
|
308
|
+
if (n === ' ')
|
|
309
|
+
n = val.charAt(i + 2);
|
|
310
|
+
|
|
311
|
+
// maybe a link
|
|
312
|
+
can = n === '(';
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
if (beg > -1 && can && c === ')') {
|
|
316
|
+
n = val.charAt(beg - 1);
|
|
317
|
+
var tmp = val.substring(beg - (n === '!' ? 1 : 0), i + 1);
|
|
318
|
+
if (tmp.charAt(0) === '!')
|
|
319
|
+
val = val.replace(tmp, markdown_image(tmp));
|
|
320
|
+
can = false;
|
|
321
|
+
beg = -1;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
return val;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function linkscope(val, index, callback) {
|
|
329
|
+
|
|
330
|
+
var beg = -1;
|
|
331
|
+
var beg2 = -1;
|
|
332
|
+
var can = false;
|
|
333
|
+
var skip = false;
|
|
334
|
+
var find = false;
|
|
335
|
+
var n;
|
|
336
|
+
|
|
337
|
+
for (var i = index; i < val.length; i++) {
|
|
338
|
+
var c = val.charAt(i);
|
|
339
|
+
|
|
340
|
+
if (c === '[') {
|
|
341
|
+
beg = i;
|
|
342
|
+
can = false;
|
|
343
|
+
find = true;
|
|
344
|
+
continue;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
var codescope = val.substring(i, i + 6);
|
|
348
|
+
|
|
349
|
+
if (skip && codescope === '</code') {
|
|
350
|
+
skip = false;
|
|
351
|
+
i += 7;
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
if (skip)
|
|
356
|
+
continue;
|
|
357
|
+
|
|
358
|
+
if (!find && codescope === '<code>') {
|
|
359
|
+
skip = true;
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
var il = val.substring(i, i + 4);
|
|
364
|
+
|
|
365
|
+
if (il === '<') {
|
|
366
|
+
beg2 = i;
|
|
367
|
+
continue;
|
|
368
|
+
} else if (beg2 > -1 && il === '>') {
|
|
369
|
+
callback(val.substring(beg2, i + 4), true);
|
|
370
|
+
beg2 = -1;
|
|
371
|
+
continue;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
if (c === ']') {
|
|
375
|
+
|
|
376
|
+
can = false;
|
|
377
|
+
find = false;
|
|
378
|
+
|
|
379
|
+
if (beg === -1)
|
|
380
|
+
continue;
|
|
381
|
+
|
|
382
|
+
n = val.charAt(i + 1);
|
|
383
|
+
|
|
384
|
+
// maybe a link mistake
|
|
385
|
+
if (n === ' ')
|
|
386
|
+
n = val.charAt(i + 2);
|
|
387
|
+
|
|
388
|
+
// maybe a link
|
|
389
|
+
can = n === '(';
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if (beg > -1 && can && c === ')') {
|
|
393
|
+
n = val.charAt(beg - 1);
|
|
394
|
+
callback(val.substring(beg - (n === '!' ? 1 : 0), i + 1));
|
|
395
|
+
can = false;
|
|
396
|
+
find = false;
|
|
397
|
+
beg = -1;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
String.prototype.markdown = function(opt, nested) {
|
|
403
|
+
|
|
404
|
+
// opt.wrap = true;
|
|
405
|
+
// opt.linetag = 'p';
|
|
406
|
+
// opt.ul = true;
|
|
407
|
+
// opt.code = true;
|
|
408
|
+
// opt.images = true;
|
|
409
|
+
// opt.links = true;
|
|
410
|
+
// opt.formatting = true;
|
|
411
|
+
// opt.icons = true;
|
|
412
|
+
// opt.tables = true;
|
|
413
|
+
// opt.br = true;
|
|
414
|
+
// opt.headlines = true;
|
|
415
|
+
// opt.hr = true;
|
|
416
|
+
// opt.blockquotes = true;
|
|
417
|
+
// opt.sections = true;
|
|
418
|
+
// opt.custom
|
|
419
|
+
// opt.footnotes = true;
|
|
420
|
+
// opt.urlify = true;
|
|
421
|
+
// opt.keywords = true;
|
|
422
|
+
// opt.emptynewline = true;
|
|
423
|
+
|
|
424
|
+
var str = this;
|
|
425
|
+
|
|
426
|
+
if (!opt)
|
|
427
|
+
opt = {};
|
|
428
|
+
|
|
429
|
+
var lines = str.split('\n');
|
|
430
|
+
var builder = [];
|
|
431
|
+
var ul = [];
|
|
432
|
+
var table = false;
|
|
433
|
+
var iscode = false;
|
|
434
|
+
var isblock = false;
|
|
435
|
+
var ishead = 0;
|
|
436
|
+
var isprevblock = false;
|
|
437
|
+
var headline = '<{0} id="{3}" class="markdown-line" data-index="{1}">{2}</{0}>';
|
|
438
|
+
var line;
|
|
439
|
+
var tmp;
|
|
440
|
+
|
|
441
|
+
if (opt.wrap == null)
|
|
442
|
+
opt.wrap = true;
|
|
443
|
+
|
|
444
|
+
if (opt.linetag == null)
|
|
445
|
+
opt.linetag = 'p';
|
|
446
|
+
|
|
447
|
+
var closeul = function() {
|
|
448
|
+
while (ul.length) {
|
|
449
|
+
var text = ul.pop();
|
|
450
|
+
builder.push('</' + text + '>');
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
var linkreplace = function(text, inline) {
|
|
455
|
+
if (inline)
|
|
456
|
+
opt.$line = opt.$line.replace(text, markdown_links2);
|
|
457
|
+
else if (opt.images !== false)
|
|
458
|
+
opt.$line = opt.$line.replace(text, markdown_imagelinks);
|
|
459
|
+
else
|
|
460
|
+
opt.$line = opt.$line.replace(text, text => markdown_links(text, opt.images));
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
for (var i = 0; i < lines.length; i++) {
|
|
464
|
+
|
|
465
|
+
lines[i] = lines[i].replace(REG_ENCODETAGS, ENCODE);
|
|
466
|
+
|
|
467
|
+
if (!lines[i]) {
|
|
468
|
+
builder.push('');
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
var three = lines[i].substring(0, 3);
|
|
473
|
+
|
|
474
|
+
if (!iscode && (three === ':::' || (three === '==='))) {
|
|
475
|
+
|
|
476
|
+
if (isblock) {
|
|
477
|
+
if (opt.blocks !== false)
|
|
478
|
+
builder[builder.length - 1] += '</div></div>';
|
|
479
|
+
isblock = false;
|
|
480
|
+
isprevblock = true;
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
closeul();
|
|
485
|
+
isblock = true;
|
|
486
|
+
if (opt.blocks !== false) {
|
|
487
|
+
line = lines[i].substring(3).trim();
|
|
488
|
+
if (opt.formatting !== false)
|
|
489
|
+
line = formatline(line);
|
|
490
|
+
if (opt.custom)
|
|
491
|
+
line = opt.custom(line);
|
|
492
|
+
if (opt.html)
|
|
493
|
+
line = opt.html(line, 'block');
|
|
494
|
+
builder.push('<div class="markdown-block markdown-line" data-line="{0}"><span class="markdown-showblock"><i class="ti ti-plus"></i>{1}</span><div class="hidden">'.format(i, line));
|
|
495
|
+
}
|
|
496
|
+
continue;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if (!isblock && lines[i] && isprevblock) {
|
|
500
|
+
builder.push('<br />');
|
|
501
|
+
isprevblock = false;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
if (three === '```') {
|
|
505
|
+
|
|
506
|
+
if (iscode) {
|
|
507
|
+
if (opt.code !== false)
|
|
508
|
+
builder[builder.length - 1] += '</code></pre></div>';
|
|
509
|
+
iscode = false;
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
closeul();
|
|
514
|
+
iscode = true;
|
|
515
|
+
if (opt.code !== false)
|
|
516
|
+
tmp = '<div class="markdown-code markdown-line hidden"><pre class="noscrollbar"><code class="lang-{0}">'.format(lines[i].substring(3));
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
if (iscode) {
|
|
521
|
+
if (opt.code !== false)
|
|
522
|
+
builder.push(tmp + lines[i]);
|
|
523
|
+
if (tmp)
|
|
524
|
+
tmp = '';
|
|
525
|
+
continue;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
line = lines[i];
|
|
529
|
+
|
|
530
|
+
if (opt.br !== false)
|
|
531
|
+
line = line.replace(/<br(\s\/)?>/g, '<br />');
|
|
532
|
+
|
|
533
|
+
if (line.length > 10 && opt.urlify !== false && opt.links !== false)
|
|
534
|
+
line = markdown_urlify(line);
|
|
535
|
+
|
|
536
|
+
if (opt.custom)
|
|
537
|
+
line = opt.custom(line);
|
|
538
|
+
|
|
539
|
+
if (line.length > 2 && line !== '***' && line !== '---') {
|
|
540
|
+
|
|
541
|
+
if (opt.formatting !== false)
|
|
542
|
+
line = formatline(line);
|
|
543
|
+
|
|
544
|
+
if (opt.images !== false)
|
|
545
|
+
line = imagescope(line);
|
|
546
|
+
|
|
547
|
+
if (opt.links !== false) {
|
|
548
|
+
opt.$line = line;
|
|
549
|
+
linkscope(line, 0, linkreplace);
|
|
550
|
+
line = opt.$line;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
if (opt.keywords !== false)
|
|
554
|
+
line = line.replace(REG_KEYWORDS, markdown_keywords);
|
|
555
|
+
|
|
556
|
+
if (opt.icons !== false)
|
|
557
|
+
line = line.replace(REG_ICONS, markdown_icon);
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
if (!line) {
|
|
561
|
+
if (table) {
|
|
562
|
+
table = null;
|
|
563
|
+
if (opt.tables !== false)
|
|
564
|
+
builder.push('</tbody></table>');
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
if (line === '' && lines[i - 1] === '') {
|
|
569
|
+
closeul();
|
|
570
|
+
if (opt.emptynewline !== false)
|
|
571
|
+
builder.push('<br />');
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (line[0] === '|') {
|
|
576
|
+
closeul();
|
|
577
|
+
|
|
578
|
+
if (!table) {
|
|
579
|
+
var next = lines[i + 1];
|
|
580
|
+
if (next[0] === '|') {
|
|
581
|
+
if (next.indexOf('--') === -1) {
|
|
582
|
+
if (opt.tables !== false)
|
|
583
|
+
builder.push('<table class="table table-bordered"><thead>');
|
|
584
|
+
table = [];
|
|
585
|
+
ishead = 2;
|
|
586
|
+
} else {
|
|
587
|
+
table = [];
|
|
588
|
+
var columns = next.substring(1, next.length - 1).split('|');
|
|
589
|
+
for (var j = 0; j < columns.length; j++) {
|
|
590
|
+
var column = columns[j].trim();
|
|
591
|
+
var align = 'left';
|
|
592
|
+
if (column.charAt(column.length - 1) === ':')
|
|
593
|
+
align = column[0] === ':' ? 'center' : 'right';
|
|
594
|
+
table.push(align);
|
|
595
|
+
}
|
|
596
|
+
if (opt.tables !== false)
|
|
597
|
+
builder.push('<table class="table table-bordered"><thead>');
|
|
598
|
+
ishead = 1;
|
|
599
|
+
i++;
|
|
600
|
+
}
|
|
601
|
+
} else
|
|
602
|
+
continue;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
if (opt.tables !== false) {
|
|
606
|
+
if (ishead === 1)
|
|
607
|
+
builder.push(markdown_table(line, table, true) + '</thead><tbody>');
|
|
608
|
+
else if (ishead === 2)
|
|
609
|
+
builder.push('<tbody>' + markdown_table(line, table));
|
|
610
|
+
else
|
|
611
|
+
builder.push(markdown_table(line, table));
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
ishead = 0;
|
|
615
|
+
continue;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
if (line.charAt(0) === '#') {
|
|
619
|
+
|
|
620
|
+
closeul();
|
|
621
|
+
|
|
622
|
+
if (line.substring(0, 2) === '# ') {
|
|
623
|
+
tmp = line.substring(2).trim();
|
|
624
|
+
if (opt.headlines !== false) {
|
|
625
|
+
if (opt.html)
|
|
626
|
+
tmp = opt.html(tmp, '#');
|
|
627
|
+
builder.push(headline.format('h1', i, tmp, markdown_id(tmp)));
|
|
628
|
+
}
|
|
629
|
+
continue;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
if (line.substring(0, 3) === '## ') {
|
|
633
|
+
tmp = line.substring(3).trim();
|
|
634
|
+
if (opt.headlines !== false) {
|
|
635
|
+
if (opt.html)
|
|
636
|
+
tmp = opt.html(tmp, '##');
|
|
637
|
+
builder.push(headline.format('h2', i, tmp, markdown_id(tmp)));
|
|
638
|
+
}
|
|
639
|
+
continue;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
if (line.substring(0, 4) === '### ') {
|
|
643
|
+
tmp = line.substring(4).trim();
|
|
644
|
+
if (opt.headlines !== false) {
|
|
645
|
+
if (opt.html)
|
|
646
|
+
tmp = opt.html(tmp, '###');
|
|
647
|
+
builder.push(headline.format('h3', i, tmp, markdown_id(tmp)));
|
|
648
|
+
}
|
|
649
|
+
continue;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
if (line.substring(0, 5) === '#### ') {
|
|
653
|
+
tmp = line.substring(5).trim();
|
|
654
|
+
if (opt.headlines !== false) {
|
|
655
|
+
if (opt.html)
|
|
656
|
+
tmp = opt.html(tmp, '####');
|
|
657
|
+
builder.push(headline.format('h4', i, tmp, markdown_id(tmp)));
|
|
658
|
+
}
|
|
659
|
+
continue;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
if (line.substring(0, 6) === '##### ') {
|
|
663
|
+
tmp = line.substring(6).trim();
|
|
664
|
+
if (opt.headlines !== false) {
|
|
665
|
+
if (opt.html)
|
|
666
|
+
tmp = opt.html(tmp, '#####');
|
|
667
|
+
builder.push(headline.format('h5', i, tmp, markdown_id(tmp)));
|
|
668
|
+
}
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
tmp = line.substring(0, 3);
|
|
674
|
+
|
|
675
|
+
if (tmp === '---' || tmp === '***') {
|
|
676
|
+
if (opt.hr !== false)
|
|
677
|
+
builder.push('<hr class="markdown-line' + (tmp.charAt(0) === '-' ? '1' : '2') + ' markdown-line" data-line="' + i + '" />');
|
|
678
|
+
continue;
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
// footnotes
|
|
682
|
+
if ((/^#\d+:(\s)+/).test(line)) {
|
|
683
|
+
if (opt.footnotes !== false) {
|
|
684
|
+
tmp = line.indexOf(':');
|
|
685
|
+
builder.push('<div class="markdown-footnotebody" data-id="{0}"><span>{0}:</span> {1}</div>'.format(line.substring(1, tmp).trim(), line.substring(tmp + 1).trim()));
|
|
686
|
+
}
|
|
687
|
+
continue;
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
if (line.substring(0, 5) === '> ') {
|
|
691
|
+
if (opt.blockquotes !== false) {
|
|
692
|
+
line = line.substring(5).trim();
|
|
693
|
+
if (opt.html)
|
|
694
|
+
line = opt.html(line, 'blockquote');
|
|
695
|
+
builder.push('<blockquote class="markdown-line" data-line="' + i + '">' + line + '</blockquote>');
|
|
696
|
+
}
|
|
697
|
+
continue;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
if (line.substring(0, 5) === '< ') {
|
|
701
|
+
if (opt.sections !== false) {
|
|
702
|
+
line = line.substring(5).trim();
|
|
703
|
+
if (opt.html)
|
|
704
|
+
line = opt.html(line, 'section');
|
|
705
|
+
builder.push('<section class="markdown-line" data-line="' + i + '">' + line + '</section>');
|
|
706
|
+
}
|
|
707
|
+
continue;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
var tmpline = line.trim();
|
|
711
|
+
|
|
712
|
+
if (opt.ul !== false && REG_ORDERED.test(tmpline)) {
|
|
713
|
+
|
|
714
|
+
var size = line.match(REG_ORDEREDSIZE);
|
|
715
|
+
if (size)
|
|
716
|
+
size = size[0].length;
|
|
717
|
+
else
|
|
718
|
+
size = 0;
|
|
719
|
+
|
|
720
|
+
var ultype = tmpline.charAt(0) === '-' ? 'ul' : 'ol';
|
|
721
|
+
var tmpstr = (ultype === 'ol' ? tmpline.substring(tmpline.indexOf('.') + 1) : tmpline.substring(2));
|
|
722
|
+
var istask = false;
|
|
723
|
+
|
|
724
|
+
var tt = tmpstr.trim().substring(0, 3);
|
|
725
|
+
istask = tt === '[ ]' || tt === '[x]';
|
|
726
|
+
|
|
727
|
+
var tmpval = tmpstr.trim();
|
|
728
|
+
|
|
729
|
+
if (opt.html)
|
|
730
|
+
tmpval = opt.html(tmpval, 'li');
|
|
731
|
+
|
|
732
|
+
builder.push('\0' + (ultype === 'ol' ? ('o' + ((/\d+\./).test(tmpline) ? '1' : 'a')) : 'ul') + size + '<li data-line="{0}" class="markdown-line{1}">'.format(i, istask ? ' markdown-task' : '') + tmpval.replace(/\[x\]/g, '<i class="ti ti-check-square green"></i>').replace(/\[\s\]/g, '<i class="ti ti-square"></i>') + '</li>');
|
|
733
|
+
|
|
734
|
+
} else {
|
|
735
|
+
closeul();
|
|
736
|
+
if (line) {
|
|
737
|
+
line = line.trim();
|
|
738
|
+
if (opt.html)
|
|
739
|
+
line = opt.html(line, opt.linetag);
|
|
740
|
+
}
|
|
741
|
+
line && builder.push((opt.linetag ? ('<' + opt.linetag + ' class="markdown-line" data-line="' + i + '">') : '') + line.trim() + (opt.linetag ? ('</' + opt.linetag + '>') : ''));
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
|
|
745
|
+
closeul();
|
|
746
|
+
|
|
747
|
+
table && opt.tables !== false && builder.push('</tbody></table>');
|
|
748
|
+
iscode && opt.code !== false && builder.push('</code></pre>');
|
|
749
|
+
|
|
750
|
+
builder = parseul(builder);
|
|
751
|
+
return (opt.wrap ? ('<div class="markdown' + (nested ? '' : ' markdown-container') + '">') : '') + builder.join('\n').replace(/\t/g, ' ') + (opt.wrap ? '</div>' : '');
|
|
752
|
+
};
|
package/package.json
CHANGED
package/tms.js
CHANGED
package/utils.js
CHANGED
|
@@ -349,6 +349,7 @@ var CONTENTTYPES = {
|
|
|
349
349
|
xml: 'application/xml',
|
|
350
350
|
xpm: 'image/x-xpixmap',
|
|
351
351
|
xsl: 'application/xml',
|
|
352
|
+
xsd: 'application/xml',
|
|
352
353
|
xslt: 'application/xslt+xml',
|
|
353
354
|
zip: 'application/zip',
|
|
354
355
|
'7zip': 'application/x-7z-compressed'
|
|
@@ -3163,6 +3164,11 @@ SP.parseConfig = function(def, onerr) {
|
|
|
3163
3164
|
} else
|
|
3164
3165
|
subtype = '';
|
|
3165
3166
|
|
|
3167
|
+
if (value.substring(0, 7) === 'base64 ' && value.length > 8)
|
|
3168
|
+
value = Buffer.from(value.substring(7).trim(), 'base64').toString('utf8');
|
|
3169
|
+
else if (value.substring(0, 4) === 'hex ' && value.length > 6)
|
|
3170
|
+
value = Buffer.from(value.substring(4).trim(), 'hex').toString('utf8');
|
|
3171
|
+
|
|
3166
3172
|
switch (subtype) {
|
|
3167
3173
|
case 'string':
|
|
3168
3174
|
obj[name] = value;
|