securemark 0.245.0 → 0.247.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 +12 -0
- package/dist/index.js +52 -40
- package/karma.conf.js +1 -2
- package/markdown.d.ts +31 -19
- package/package.json +6 -5
- package/src/parser/block/extension/table.test.ts +9 -0
- package/src/parser/block/extension/table.ts +17 -4
- package/src/parser/block/reply/quote.test.ts +1 -1
- package/src/parser/inline/math.test.ts +51 -20
- package/src/parser/inline/math.ts +24 -15
- package/src/parser/inline.test.ts +2 -1
- package/src/parser/inline.ts +3 -3
- package/webpack.config.js +2 -2
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! securemark v0.
|
|
1
|
+
/*! securemark v0.247.1 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
|
|
2
2
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
3
3
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
4
4
|
module.exports = factory(require("DOMPurify"), require("Prism"));
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
exports["securemark"] = factory(require("DOMPurify"), require("Prism"));
|
|
9
9
|
else
|
|
10
10
|
root["securemark"] = factory(root["DOMPurify"], root["Prism"]);
|
|
11
|
-
})(
|
|
11
|
+
})(this, (__WEBPACK_EXTERNAL_MODULE__6231__, __WEBPACK_EXTERNAL_MODULE__9450__) => {
|
|
12
12
|
return /******/ (() => { // webpackBootstrap
|
|
13
13
|
/******/ var __webpack_modules__ = ({
|
|
14
14
|
|
|
@@ -4307,11 +4307,11 @@ const dom_1 = __webpack_require__(3252);
|
|
|
4307
4307
|
|
|
4308
4308
|
const array_1 = __webpack_require__(8112);
|
|
4309
4309
|
|
|
4310
|
-
const opener = /^(~{3,})table(?!\S)([^\n]*)(?:$|\n)/;
|
|
4310
|
+
const opener = /^(~{3,})table(?:\/(\S+))?(?!\S)([^\n]*)(?:$|\n)/;
|
|
4311
4311
|
exports.segment = (0, combinator_1.block)((0, combinator_1.validate)('~~~', (0, combinator_1.clear)((0, combinator_1.fence)(opener, 10000))));
|
|
4312
4312
|
exports.segment_ = (0, combinator_1.block)((0, combinator_1.validate)('~~~', (0, combinator_1.clear)((0, combinator_1.fence)(opener, 10000, false))), false);
|
|
4313
4313
|
exports.table = (0, combinator_1.block)((0, combinator_1.validate)('~~~', (0, combinator_1.fmap)((0, combinator_1.fence)(opener, 10000), // Bug: Type mismatch between outer and inner.
|
|
4314
|
-
([body, overflow, closer, opener, delim, param], _, context) => {
|
|
4314
|
+
([body, overflow, closer, opener, delim, type, param], _, context) => {
|
|
4315
4315
|
if (!closer || overflow || param.trimStart()) return [(0, dom_1.html)('pre', {
|
|
4316
4316
|
class: 'invalid',
|
|
4317
4317
|
translate: 'no',
|
|
@@ -4319,7 +4319,23 @@ exports.table = (0, combinator_1.block)((0, combinator_1.validate)('~~~', (0, co
|
|
|
4319
4319
|
'data-invalid-type': !closer || overflow ? 'fence' : 'argument',
|
|
4320
4320
|
'data-invalid-message': !closer ? `Missing the closing delimiter "${delim}"` : overflow ? `Invalid trailing line after the closing delimiter "${delim}"` : 'Invalid argument'
|
|
4321
4321
|
}, `${opener}${body}${overflow || closer}`)];
|
|
4322
|
-
|
|
4322
|
+
|
|
4323
|
+
switch (type) {
|
|
4324
|
+
case 'grid':
|
|
4325
|
+
case global_1.undefined:
|
|
4326
|
+
return ((0, parser_1.eval)(parser(body, context)) ?? [(0, dom_1.html)('table')]).map(el => (0, dom_1.define)(el, {
|
|
4327
|
+
'data-type': type
|
|
4328
|
+
}));
|
|
4329
|
+
|
|
4330
|
+
default:
|
|
4331
|
+
return [(0, dom_1.html)('pre', {
|
|
4332
|
+
class: 'invalid',
|
|
4333
|
+
translate: 'no',
|
|
4334
|
+
'data-invalid-syntax': 'table',
|
|
4335
|
+
'data-invalid-type': 'argument',
|
|
4336
|
+
'data-invalid-message': 'Invalid table type'
|
|
4337
|
+
}, `${opener}${body}${closer}`)];
|
|
4338
|
+
}
|
|
4323
4339
|
})));
|
|
4324
4340
|
const parser = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, locale_1.localize)((0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.union)([row])), rows => [(0, dom_1.html)('table', format(rows))]))));
|
|
4325
4341
|
const row = (0, combinator_1.lazy)(() => (0, combinator_1.dup)((0, combinator_1.fmap)((0, combinator_1.subsequence)([(0, combinator_1.dup)((0, combinator_1.union)([align])), (0, combinator_1.some)((0, combinator_1.union)([head, data, (0, combinator_1.some)(dataline, alignment), source_1.emptyline]))]), ns => !(0, alias_1.isArray)(ns[0]) ? (0, array_1.unshift)([[[]]], ns) : ns)));
|
|
@@ -5240,6 +5256,8 @@ const template_1 = __webpack_require__(4695);
|
|
|
5240
5256
|
|
|
5241
5257
|
const comment_1 = __webpack_require__(8657);
|
|
5242
5258
|
|
|
5259
|
+
const math_1 = __webpack_require__(8946);
|
|
5260
|
+
|
|
5243
5261
|
const extension_1 = __webpack_require__(8053);
|
|
5244
5262
|
|
|
5245
5263
|
const ruby_1 = __webpack_require__(6705);
|
|
@@ -5262,8 +5280,6 @@ const strong_1 = __webpack_require__(8072);
|
|
|
5262
5280
|
|
|
5263
5281
|
const code_1 = __webpack_require__(5771);
|
|
5264
5282
|
|
|
5265
|
-
const math_1 = __webpack_require__(8946);
|
|
5266
|
-
|
|
5267
5283
|
const media_1 = __webpack_require__(1303);
|
|
5268
5284
|
|
|
5269
5285
|
const htmlentity_1 = __webpack_require__(1562);
|
|
@@ -5276,7 +5292,7 @@ const bracket_1 = __webpack_require__(5196);
|
|
|
5276
5292
|
|
|
5277
5293
|
const source_1 = __webpack_require__(6743);
|
|
5278
5294
|
|
|
5279
|
-
exports.inline = (0, combinator_1.union)([escape_1.escape, annotation_1.annotation, reference_1.reference, template_1.template, comment_1.comment, extension_1.extension, ruby_1.ruby, link_1.link, media_1.media, html_1.html, insertion_1.insertion, deletion_1.deletion, mark_1.mark, emstrong_1.emstrong, strong_1.strong, emphasis_1.emphasis, code_1.code,
|
|
5295
|
+
exports.inline = (0, combinator_1.union)([escape_1.escape, annotation_1.annotation, reference_1.reference, template_1.template, comment_1.comment, math_1.math, extension_1.extension, ruby_1.ruby, link_1.link, media_1.media, html_1.html, insertion_1.insertion, deletion_1.deletion, mark_1.mark, emstrong_1.emstrong, strong_1.strong, emphasis_1.emphasis, code_1.code, htmlentity_1.htmlentity, shortmedia_1.shortmedia, autolink_1.autolink, bracket_1.bracket, source_1.text]);
|
|
5280
5296
|
|
|
5281
5297
|
var indexee_1 = __webpack_require__(1269);
|
|
5282
5298
|
|
|
@@ -6528,18 +6544,13 @@ const source_1 = __webpack_require__(6743);
|
|
|
6528
6544
|
|
|
6529
6545
|
const dom_1 = __webpack_require__(3252);
|
|
6530
6546
|
|
|
6531
|
-
const
|
|
6532
|
-
|
|
6533
|
-
|
|
6534
|
-
// $[A-z]*- : Label
|
|
6535
|
-
// $[A-z]*(?!-) : Math
|
|
6536
|
-
// $[\^_[({|] : Math
|
|
6537
|
-
// $[#$%&] : Invalid first character in Latex syntax
|
|
6538
|
-
(0, source_1.str)(/^(?![\s{}#$%&]|\d+(?:[,.]\d+)*[^-+*/=<>^_~\\$]|-[\da-z]|[a-z]+-)(?:\\\$|\x20(?!\$)|[\x21-\x23\x25-\x7E])+/i), /^\$(?![0-9a-z])/i), (0, combinator_1.surround)('$', bracket, '$')]), (source, {
|
|
6547
|
+
const syntax = /^(?:[ "([](?!\$)|\\{(?!\$)|\\[\\}$]?|^`|`(?!`)|[!#%&')\x2A-\x5A\]^_\x61-\x7A|~])+/;
|
|
6548
|
+
const forbiddenCommand = /\\(?:begin|tiny|huge|large)(?![a-z])/i;
|
|
6549
|
+
exports.math = (0, combinator_1.lazy)(() => (0, combinator_1.creator)((0, combinator_1.validate)('$', (0, combinator_1.rewrite)((0, combinator_1.union)([(0, combinator_1.surround)('$', bracket, '$'), (0, combinator_1.surround)(/^\$(?!\s)/, (0, combinator_1.some)((0, combinator_1.union)([bracket, quote, (0, source_1.str)(syntax)])), /^\$(?![0-9A-Za-z])/)]), (source, {
|
|
6539
6550
|
caches: {
|
|
6540
6551
|
math: cache
|
|
6541
6552
|
} = {}
|
|
6542
|
-
}) => [[cache?.get(source)?.cloneNode(true) || (0, dom_1.html)('span', !
|
|
6553
|
+
}) => [[cache?.get(source)?.cloneNode(true) || (0, dom_1.html)('span', !forbiddenCommand.test(source) ? {
|
|
6543
6554
|
class: 'math',
|
|
6544
6555
|
translate: 'no',
|
|
6545
6556
|
'data-src': source
|
|
@@ -6548,9 +6559,10 @@ exports.math = (0, combinator_1.lazy)(() => (0, combinator_1.creator)((0, combin
|
|
|
6548
6559
|
translate: 'no',
|
|
6549
6560
|
'data-invalid-syntax': 'math',
|
|
6550
6561
|
'data-invalid-type': 'content',
|
|
6551
|
-
'data-invalid-message': `"${source.match(
|
|
6562
|
+
'data-invalid-message': `"${source.match(forbiddenCommand)[0]}" command is forbidden`
|
|
6552
6563
|
}, source)], '']))));
|
|
6553
|
-
const bracket = (0, combinator_1.lazy)(() => (0, combinator_1.creator)((0, combinator_1.surround)('{', (0, combinator_1.some)((0, combinator_1.union)([bracket, (0, combinator_1.some)(source_1.escsource, /^(?:[{}]|\\?\n)/)])), '}', true)));
|
|
6564
|
+
const bracket = (0, combinator_1.lazy)(() => (0, combinator_1.creator)((0, combinator_1.surround)('{', (0, combinator_1.some)((0, combinator_1.union)([bracket, (0, combinator_1.some)(source_1.escsource, /^(?:[{}$]|\\?\n)/)])), '}', true)));
|
|
6565
|
+
const quote = (0, combinator_1.lazy)(() => (0, combinator_1.creator)((0, combinator_1.surround)('``', (0, combinator_1.some)((0, combinator_1.union)([quote, bracket, (0, combinator_1.focus)(/^(?:\\[\\{}$]|`(?!`)|[^`{}"$\n])*/, (0, source_1.str)(syntax))])), /^"?/, true)));
|
|
6554
6566
|
|
|
6555
6567
|
/***/ }),
|
|
6556
6568
|
|
|
@@ -8718,14 +8730,14 @@ function fix(h) {
|
|
|
8718
8730
|
/***/ }),
|
|
8719
8731
|
|
|
8720
8732
|
/***/ 3252:
|
|
8721
|
-
/***/ ((module)
|
|
8733
|
+
/***/ (function(module) {
|
|
8722
8734
|
|
|
8723
|
-
/*! typed-dom v0.0.
|
|
8735
|
+
/*! typed-dom v0.0.295 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
|
|
8724
8736
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
8725
8737
|
if(true)
|
|
8726
8738
|
module.exports = factory();
|
|
8727
8739
|
else {}
|
|
8728
|
-
})(
|
|
8740
|
+
})(this, () => {
|
|
8729
8741
|
return /******/ (() => { // webpackBootstrap
|
|
8730
8742
|
/******/ "use strict";
|
|
8731
8743
|
/******/ var __webpack_modules__ = ({
|
|
@@ -8804,11 +8816,11 @@ exports.equal = equal;
|
|
|
8804
8816
|
/***/ }),
|
|
8805
8817
|
|
|
8806
8818
|
/***/ 128:
|
|
8807
|
-
/***/ ((module, __unused_webpack_exports,
|
|
8819
|
+
/***/ ((module, __unused_webpack_exports, __nested_webpack_require_4955__) => {
|
|
8808
8820
|
|
|
8809
8821
|
|
|
8810
8822
|
|
|
8811
|
-
|
|
8823
|
+
__nested_webpack_require_4955__(921);
|
|
8812
8824
|
|
|
8813
8825
|
const global = void 0 || typeof globalThis !== 'undefined' && globalThis // @ts-ignore
|
|
8814
8826
|
|| typeof self !== 'undefined' && self || Function('return this')();
|
|
@@ -8829,7 +8841,7 @@ var global = (/* unused pure expression or super */ null && (0));
|
|
|
8829
8841
|
/***/ }),
|
|
8830
8842
|
|
|
8831
8843
|
/***/ 808:
|
|
8832
|
-
/***/ ((__unused_webpack_module, exports,
|
|
8844
|
+
/***/ ((__unused_webpack_module, exports, __nested_webpack_require_5442__) => {
|
|
8833
8845
|
|
|
8834
8846
|
|
|
8835
8847
|
|
|
@@ -8838,11 +8850,11 @@ Object.defineProperty(exports, "__esModule", ({
|
|
|
8838
8850
|
}));
|
|
8839
8851
|
exports.reduce = exports.memoize = void 0;
|
|
8840
8852
|
|
|
8841
|
-
const global_1 =
|
|
8853
|
+
const global_1 = __nested_webpack_require_5442__(128);
|
|
8842
8854
|
|
|
8843
|
-
const alias_1 =
|
|
8855
|
+
const alias_1 = __nested_webpack_require_5442__(406);
|
|
8844
8856
|
|
|
8845
|
-
const compare_1 =
|
|
8857
|
+
const compare_1 = __nested_webpack_require_5442__(529);
|
|
8846
8858
|
|
|
8847
8859
|
function memoize(f, identify = (...as) => as[0], memory) {
|
|
8848
8860
|
if (typeof identify === 'object') return memoize(f, void 0, identify);
|
|
@@ -8900,7 +8912,7 @@ exports.reduce = reduce;
|
|
|
8900
8912
|
/***/ }),
|
|
8901
8913
|
|
|
8902
8914
|
/***/ 521:
|
|
8903
|
-
/***/ ((__unused_webpack_module, exports,
|
|
8915
|
+
/***/ ((__unused_webpack_module, exports, __nested_webpack_require_6832__) => {
|
|
8904
8916
|
|
|
8905
8917
|
|
|
8906
8918
|
|
|
@@ -8909,11 +8921,11 @@ Object.defineProperty(exports, "__esModule", ({
|
|
|
8909
8921
|
}));
|
|
8910
8922
|
exports.defrag = exports.prepend = exports.append = exports.isChildren = exports.define = exports.element = exports.text = exports.svg = exports.html = exports.frag = exports.shadow = void 0;
|
|
8911
8923
|
|
|
8912
|
-
const global_1 =
|
|
8924
|
+
const global_1 = __nested_webpack_require_6832__(128);
|
|
8913
8925
|
|
|
8914
|
-
const alias_1 =
|
|
8926
|
+
const alias_1 = __nested_webpack_require_6832__(406);
|
|
8915
8927
|
|
|
8916
|
-
const memoize_1 =
|
|
8928
|
+
const memoize_1 = __nested_webpack_require_6832__(808);
|
|
8917
8929
|
|
|
8918
8930
|
var caches;
|
|
8919
8931
|
|
|
@@ -9018,7 +9030,7 @@ function defineAttrs(el, attrs) {
|
|
|
9018
9030
|
configurable: true,
|
|
9019
9031
|
enumerable: false,
|
|
9020
9032
|
writable: true,
|
|
9021
|
-
value: prop in el ? ev => ev.returnValue : ''
|
|
9033
|
+
value: prop in el && !(0, alias_1.hasOwnProperty)(el, prop) ? ev => ev.returnValue : ''
|
|
9022
9034
|
});
|
|
9023
9035
|
}
|
|
9024
9036
|
}
|
|
@@ -9045,7 +9057,7 @@ function defineAttrs(el, attrs) {
|
|
|
9045
9057
|
configurable: true,
|
|
9046
9058
|
enumerable: false,
|
|
9047
9059
|
writable: true,
|
|
9048
|
-
value: prop in el ? ev => ev.returnValue : ''
|
|
9060
|
+
value: prop in el && !(0, alias_1.hasOwnProperty)(el, prop) ? ev => ev.returnValue : ''
|
|
9049
9061
|
});
|
|
9050
9062
|
}
|
|
9051
9063
|
}
|
|
@@ -9149,7 +9161,7 @@ exports.defrag = defrag;
|
|
|
9149
9161
|
/******/ var __webpack_module_cache__ = {};
|
|
9150
9162
|
/******/
|
|
9151
9163
|
/******/ // The require function
|
|
9152
|
-
/******/ function
|
|
9164
|
+
/******/ function __nested_webpack_require_13916__(moduleId) {
|
|
9153
9165
|
/******/ // Check if module is in cache
|
|
9154
9166
|
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
9155
9167
|
/******/ if (cachedModule !== undefined) {
|
|
@@ -9163,7 +9175,7 @@ exports.defrag = defrag;
|
|
|
9163
9175
|
/******/ };
|
|
9164
9176
|
/******/
|
|
9165
9177
|
/******/ // Execute the module function
|
|
9166
|
-
/******/ __webpack_modules__[moduleId](module, module.exports,
|
|
9178
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_13916__);
|
|
9167
9179
|
/******/
|
|
9168
9180
|
/******/ // Return the exports of the module
|
|
9169
9181
|
/******/ return module.exports;
|
|
@@ -9174,7 +9186,7 @@ exports.defrag = defrag;
|
|
|
9174
9186
|
/******/ // startup
|
|
9175
9187
|
/******/ // Load entry module and return exports
|
|
9176
9188
|
/******/ // This entry module is referenced by other modules so it can't be inlined
|
|
9177
|
-
/******/ var __webpack_exports__ =
|
|
9189
|
+
/******/ var __webpack_exports__ = __nested_webpack_require_13916__(521);
|
|
9178
9190
|
/******/
|
|
9179
9191
|
/******/ return __webpack_exports__;
|
|
9180
9192
|
/******/ })()
|
|
@@ -9184,14 +9196,14 @@ exports.defrag = defrag;
|
|
|
9184
9196
|
/***/ }),
|
|
9185
9197
|
|
|
9186
9198
|
/***/ 6120:
|
|
9187
|
-
/***/ ((module)
|
|
9199
|
+
/***/ (function(module) {
|
|
9188
9200
|
|
|
9189
|
-
/*! typed-dom v0.0.
|
|
9201
|
+
/*! typed-dom v0.0.295 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
|
|
9190
9202
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
9191
9203
|
if(true)
|
|
9192
9204
|
module.exports = factory();
|
|
9193
9205
|
else {}
|
|
9194
|
-
})(
|
|
9206
|
+
})(this, () => {
|
|
9195
9207
|
return /******/ (() => { // webpackBootstrap
|
|
9196
9208
|
/******/ "use strict";
|
|
9197
9209
|
var __webpack_exports__ = {};
|
package/karma.conf.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
module.exports = function (config) {
|
|
2
2
|
config.set({
|
|
3
3
|
browsers: ['Chrome', 'Firefox'],
|
|
4
|
-
frameworks: ['mocha'],
|
|
4
|
+
frameworks: ['mocha', 'power-assert'],
|
|
5
5
|
files: [
|
|
6
|
-
{ pattern: 'https://cdn.jsdelivr.net/npm/power-assert@1.6.1/build/power-assert.js', watched: false, served: false, included: true, integrity: 'sha256-MuDC5CQFh3oWtiG0YE000HlkK08xAilD2v0ndZR+Kds=' },
|
|
7
6
|
{ pattern: 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.js', watched: false, served: false, included: true, integrity: 'sha512-2iwCHjuj+PmdCyvb88rMOch0UcKQxVHi/gsAml1fN3eg82IDaO/cdzzeXX4iF2VzIIes7pODE1/G0ts3QBwslA==' },
|
|
8
7
|
{ pattern: 'https://cdnjs.cloudflare.com/ajax/libs/benchmark/2.1.4/benchmark.js', watched: false, served: false, included: true, integrity: 'sha512-XnVGk21Ij51MbU8XezQpkwZ1/GA8b5qmoVGIOdJLBYycutjkaeemipzRJP7P6mEJl99OfnweA7M3e4WLfuG7Aw==' },
|
|
9
8
|
{ pattern: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.js', watched: false, served: false, included: true, integrity: 'sha512-n/4gHW3atM3QqRcbCn6ewmpxcLAHGaDjpEBu4xZd47N0W2oQ+6q7oc3PXstrJYXcbNU1OHdQ1T7pAP+gi5Yu8g==' },
|
package/markdown.d.ts
CHANGED
|
@@ -652,6 +652,7 @@ export namespace MarkdownParser {
|
|
|
652
652
|
InlineParser.ReferenceParser,
|
|
653
653
|
InlineParser.TemplateParser,
|
|
654
654
|
InlineParser.CommentParser,
|
|
655
|
+
InlineParser.MathParser,
|
|
655
656
|
InlineParser.ExtensionParser,
|
|
656
657
|
InlineParser.RubyParser,
|
|
657
658
|
InlineParser.LinkParser,
|
|
@@ -664,7 +665,6 @@ export namespace MarkdownParser {
|
|
|
664
665
|
InlineParser.StrongParser,
|
|
665
666
|
InlineParser.EmphasisParser,
|
|
666
667
|
InlineParser.CodeParser,
|
|
667
|
-
InlineParser.MathParser,
|
|
668
668
|
InlineParser.HTMLEntityParser,
|
|
669
669
|
InlineParser.ShortmediaParser,
|
|
670
670
|
InlineParser.AutolinkParser,
|
|
@@ -748,6 +748,36 @@ export namespace MarkdownParser {
|
|
|
748
748
|
InlineParser,
|
|
749
749
|
]> {
|
|
750
750
|
}
|
|
751
|
+
export interface MathParser extends
|
|
752
|
+
// $expr$
|
|
753
|
+
// ${expr}$
|
|
754
|
+
Inline<'math'>,
|
|
755
|
+
Parser<HTMLElement, Context, [
|
|
756
|
+
MathParser.BracketParser,
|
|
757
|
+
Parser<string, Context, [
|
|
758
|
+
MathParser.BracketParser,
|
|
759
|
+
MathParser.QuoteParser,
|
|
760
|
+
SourceParser.StrParser,
|
|
761
|
+
]>,
|
|
762
|
+
]> {
|
|
763
|
+
}
|
|
764
|
+
export namespace MathParser {
|
|
765
|
+
export interface BracketParser extends
|
|
766
|
+
Inline<'math/bracket'>,
|
|
767
|
+
Parser<HTMLElement, Context, [
|
|
768
|
+
BracketParser,
|
|
769
|
+
SourceParser.EscapableSourceParser,
|
|
770
|
+
]> {
|
|
771
|
+
}
|
|
772
|
+
export interface QuoteParser extends
|
|
773
|
+
Inline<'math/quote'>,
|
|
774
|
+
Parser<HTMLElement, Context, [
|
|
775
|
+
QuoteParser,
|
|
776
|
+
BracketParser,
|
|
777
|
+
SourceParser.StrParser,
|
|
778
|
+
]> {
|
|
779
|
+
}
|
|
780
|
+
}
|
|
751
781
|
export interface ExtensionParser extends
|
|
752
782
|
// [#abc]
|
|
753
783
|
Inline<'extension'>,
|
|
@@ -1039,24 +1069,6 @@ export namespace MarkdownParser {
|
|
|
1039
1069
|
SourceParser.StrParser,
|
|
1040
1070
|
]> {
|
|
1041
1071
|
}
|
|
1042
|
-
export interface MathParser extends
|
|
1043
|
-
// $expr$
|
|
1044
|
-
// ${expr}$
|
|
1045
|
-
Inline<'math'>,
|
|
1046
|
-
Parser<HTMLElement, Context, [
|
|
1047
|
-
SourceParser.StrParser,
|
|
1048
|
-
MathParser.BracketParser,
|
|
1049
|
-
]> {
|
|
1050
|
-
}
|
|
1051
|
-
export namespace MathParser {
|
|
1052
|
-
export interface BracketParser extends
|
|
1053
|
-
Inline<'math/bracket'>,
|
|
1054
|
-
Parser<HTMLElement, Context, [
|
|
1055
|
-
BracketParser,
|
|
1056
|
-
SourceParser.EscapableSourceParser,
|
|
1057
|
-
]> {
|
|
1058
|
-
}
|
|
1059
|
-
}
|
|
1060
1072
|
export interface HTMLEntityParser extends
|
|
1061
1073
|
// ©
|
|
1062
1074
|
Inline<'htmlentity'>,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "securemark",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.247.1",
|
|
4
4
|
"description": "Secure markdown renderer working on browsers for user input data.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/falsandtru/securemark",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"babel-loader": "^8.2.5",
|
|
39
39
|
"babel-plugin-unassert": "^3.2.0",
|
|
40
40
|
"concurrently": "^7.2.0",
|
|
41
|
-
"eslint": "^8.
|
|
41
|
+
"eslint": "^8.16.0",
|
|
42
42
|
"eslint-plugin-redos": "^4.4.0",
|
|
43
43
|
"eslint-webpack-plugin": "^3.1.1",
|
|
44
44
|
"glob": "^8.0.3",
|
|
@@ -47,12 +47,13 @@
|
|
|
47
47
|
"karma-coverage": "^2.2.0",
|
|
48
48
|
"karma-firefox-launcher": "^2.1.2",
|
|
49
49
|
"karma-mocha": "^2.0.1",
|
|
50
|
+
"karma-power-assert": "^1.0.0",
|
|
50
51
|
"mocha": "^10.0.0",
|
|
51
|
-
"npm-check-updates": "^13.0.
|
|
52
|
+
"npm-check-updates": "^13.0.3",
|
|
52
53
|
"semver": "^7.3.7",
|
|
53
|
-
"spica": "0.0.
|
|
54
|
+
"spica": "0.0.551",
|
|
54
55
|
"ts-loader": "^9.3.0",
|
|
55
|
-
"typed-dom": "^0.0.
|
|
56
|
+
"typed-dom": "^0.0.295",
|
|
56
57
|
"typescript": "4.6.4",
|
|
57
58
|
"webpack": "^5.72.1",
|
|
58
59
|
"webpack-cli": "^4.9.2",
|
|
@@ -654,6 +654,15 @@ describe('Unit: parser/block/extension/table', () => {
|
|
|
654
654
|
]).outerHTML], '']);
|
|
655
655
|
});
|
|
656
656
|
|
|
657
|
+
it('type', () => {
|
|
658
|
+
assert.deepStrictEqual(
|
|
659
|
+
inspect(parser('~~~table/invalid\n~~~')),
|
|
660
|
+
[['<pre class="invalid" translate="no">~~~table/invalid\n~~~</pre>'], '']);
|
|
661
|
+
assert.deepStrictEqual(
|
|
662
|
+
inspect(parser('~~~table/grid\n~~~')),
|
|
663
|
+
[[html('table', { 'data-type': 'grid' }).outerHTML], '']);
|
|
664
|
+
});
|
|
665
|
+
|
|
657
666
|
});
|
|
658
667
|
|
|
659
668
|
});
|
|
@@ -7,7 +7,7 @@ import { inline } from '../../inline';
|
|
|
7
7
|
import { str, anyline, emptyline, contentline } from '../../source';
|
|
8
8
|
import { localize } from '../../locale';
|
|
9
9
|
import { visualize } from '../../util';
|
|
10
|
-
import { html, defrag } from 'typed-dom/dom';
|
|
10
|
+
import { html, define, defrag } from 'typed-dom/dom';
|
|
11
11
|
import { unshift, splice } from 'spica/array';
|
|
12
12
|
|
|
13
13
|
import TableParser = ExtensionParser.TableParser;
|
|
@@ -15,7 +15,7 @@ import RowParser = TableParser.RowParser;
|
|
|
15
15
|
import AlignParser = TableParser.AlignParser;
|
|
16
16
|
import CellParser = TableParser.CellParser;
|
|
17
17
|
|
|
18
|
-
const opener = /^(~{3,})table(?!\S)([^\n]*)(?:$|\n)/;
|
|
18
|
+
const opener = /^(~{3,})table(?:\/(\S+))?(?!\S)([^\n]*)(?:$|\n)/;
|
|
19
19
|
|
|
20
20
|
export const segment: TableParser.SegmentParser = block(validate('~~~',
|
|
21
21
|
clear(fence(opener, 10000))));
|
|
@@ -26,7 +26,7 @@ export const segment_: TableParser.SegmentParser = block(validate('~~~',
|
|
|
26
26
|
export const table: TableParser = block(validate('~~~', fmap(
|
|
27
27
|
fence(opener, 10000),
|
|
28
28
|
// Bug: Type mismatch between outer and inner.
|
|
29
|
-
([body, overflow, closer, opener, delim, param]: string[], _, context) => {
|
|
29
|
+
([body, overflow, closer, opener, delim, type, param]: string[], _, context) => {
|
|
30
30
|
if (!closer || overflow || param.trimStart()) return [html('pre', {
|
|
31
31
|
class: 'invalid',
|
|
32
32
|
translate: 'no',
|
|
@@ -37,7 +37,20 @@ export const table: TableParser = block(validate('~~~', fmap(
|
|
|
37
37
|
overflow ? `Invalid trailing line after the closing delimiter "${delim}"` :
|
|
38
38
|
'Invalid argument',
|
|
39
39
|
}, `${opener}${body}${overflow || closer}`)];
|
|
40
|
-
|
|
40
|
+
switch (type) {
|
|
41
|
+
case 'grid':
|
|
42
|
+
case undefined:
|
|
43
|
+
return (eval(parser(body, context)) ?? [html('table')])
|
|
44
|
+
.map(el => define(el, { 'data-type': type }));
|
|
45
|
+
default:
|
|
46
|
+
return [html('pre', {
|
|
47
|
+
class: 'invalid',
|
|
48
|
+
translate: 'no',
|
|
49
|
+
'data-invalid-syntax': 'table',
|
|
50
|
+
'data-invalid-type': 'argument',
|
|
51
|
+
'data-invalid-message': 'Invalid table type',
|
|
52
|
+
}, `${opener}${body}${closer}`)];
|
|
53
|
+
}
|
|
41
54
|
})));
|
|
42
55
|
|
|
43
56
|
const parser: TableParser = lazy(() => block(localize(fmap(
|
|
@@ -52,7 +52,7 @@ describe('Unit: parser/block/reply/quote', () => {
|
|
|
52
52
|
assert.deepStrictEqual(inspect(parser('> > a\n> > b\n> > c')), [['<span class="quote">> > a<br>> > b<br>> > c</span>', '<br>'], '']);
|
|
53
53
|
assert.deepStrictEqual(inspect(parser('> > > a\n> > > b')), [['<span class="quote">> > > a<br>> > > b</span>', '<br>'], '']);
|
|
54
54
|
assert.deepStrictEqual(inspect(parser('> #a')), [['<span class="quote">> <a href="/hashtags/a" class="hashtag">#a</a></span>', '<br>'], '']);
|
|
55
|
-
assert.deepStrictEqual(inspect(parser('>
|
|
55
|
+
assert.deepStrictEqual(inspect(parser('> $-a, $-b')), [['<span class="quote">> $-a, $-b</span>', '<br>'], '']);
|
|
56
56
|
assert.deepStrictEqual(inspect(parser('> $a=b$')), [['<span class="quote">> <span class="math" translate="no" data-src="$a=b$">$a=b$</span></span>', '<br>'], '']);
|
|
57
57
|
assert.deepStrictEqual(inspect(parser('> ${a}$')), [['<span class="quote">> <span class="math" translate="no" data-src="${a}$">${a}$</span></span>', '<br>'], '']);
|
|
58
58
|
});
|
|
@@ -12,21 +12,24 @@ describe('Unit: parser/inline/math', () => {
|
|
|
12
12
|
assert.deepStrictEqual(inspect(parser('$$')), undefined);
|
|
13
13
|
assert.deepStrictEqual(inspect(parser('$$$')), undefined);
|
|
14
14
|
assert.deepStrictEqual(inspect(parser('$0 $')), undefined);
|
|
15
|
-
assert.deepStrictEqual(inspect(parser('
|
|
16
|
-
assert.deepStrictEqual(inspect(parser('
|
|
17
|
-
assert.deepStrictEqual(inspect(parser('
|
|
18
|
-
assert.deepStrictEqual(inspect(parser('
|
|
19
|
-
assert.deepStrictEqual(inspect(parser('
|
|
20
|
-
assert.deepStrictEqual(inspect(parser('$0 -$')), undefined);
|
|
21
|
-
assert.deepStrictEqual(inspect(parser('$0 - $')), undefined);
|
|
22
|
-
assert.deepStrictEqual(inspect(parser('$0 + $')), undefined);
|
|
23
|
-
assert.deepStrictEqual(inspect(parser('$-0$')), undefined);
|
|
24
|
-
assert.deepStrictEqual(inspect(parser('$-0$-1')), undefined);
|
|
25
|
-
assert.deepStrictEqual(inspect(parser('$-a$')), undefined);
|
|
26
|
-
assert.deepStrictEqual(inspect(parser('$-a$-b')), undefined);
|
|
15
|
+
assert.deepStrictEqual(inspect(parser('$-0, $-1')), undefined);
|
|
16
|
+
assert.deepStrictEqual(inspect(parser('$-0 and $-1')), undefined);
|
|
17
|
+
assert.deepStrictEqual(inspect(parser('$-0と$-1')), undefined);
|
|
18
|
+
assert.deepStrictEqual(inspect(parser('$-a $-b')), undefined);
|
|
19
|
+
assert.deepStrictEqual(inspect(parser('$-a\\ $-b')), undefined);
|
|
27
20
|
assert.deepStrictEqual(inspect(parser('$a $')), undefined);
|
|
28
|
-
assert.deepStrictEqual(inspect(parser('
|
|
29
|
-
assert.deepStrictEqual(inspect(parser('
|
|
21
|
+
assert.deepStrictEqual(inspect(parser('$-a"$-b"')), undefined);
|
|
22
|
+
assert.deepStrictEqual(inspect(parser('$-a\\"$-b\\"')), undefined);
|
|
23
|
+
assert.deepStrictEqual(inspect(parser('$a"$')), undefined);
|
|
24
|
+
assert.deepStrictEqual(inspect(parser('$-a($-b)')), undefined);
|
|
25
|
+
assert.deepStrictEqual(inspect(parser('$-a\\($-b\\)')), undefined);
|
|
26
|
+
assert.deepStrictEqual(inspect(parser('$a($')), undefined);
|
|
27
|
+
assert.deepStrictEqual(inspect(parser('$-a[$-b]')), undefined);
|
|
28
|
+
assert.deepStrictEqual(inspect(parser('$-a\\[$-b\\]')), undefined);
|
|
29
|
+
assert.deepStrictEqual(inspect(parser('$a[$')), undefined);
|
|
30
|
+
assert.deepStrictEqual(inspect(parser('$-a{$-b}')), undefined);
|
|
31
|
+
assert.deepStrictEqual(inspect(parser('$-a\\{$-b\\}')), undefined);
|
|
32
|
+
assert.deepStrictEqual(inspect(parser('$a{$')), undefined);
|
|
30
33
|
assert.deepStrictEqual(inspect(parser('$a$b')), undefined);
|
|
31
34
|
assert.deepStrictEqual(inspect(parser('$a$b$')), undefined);
|
|
32
35
|
assert.deepStrictEqual(inspect(parser('$ $')), undefined);
|
|
@@ -35,35 +38,46 @@ describe('Unit: parser/inline/math', () => {
|
|
|
35
38
|
assert.deepStrictEqual(inspect(parser('$\n$')), undefined);
|
|
36
39
|
assert.deepStrictEqual(inspect(parser('$a\\$\nb$')), undefined);
|
|
37
40
|
assert.deepStrictEqual(inspect(parser('$a\\$\\\nb$')), undefined);
|
|
41
|
+
assert.deepStrictEqual(inspect(parser('$`"$')), undefined);
|
|
42
|
+
assert.deepStrictEqual(inspect(parser('$``a"$0')), undefined);
|
|
43
|
+
assert.deepStrictEqual(inspect(parser('$``a""$')), undefined);
|
|
44
|
+
assert.deepStrictEqual(inspect(parser('$```a""$')), undefined);
|
|
45
|
+
assert.deepStrictEqual(inspect(parser('$``\n"$')), undefined);
|
|
46
|
+
assert.deepStrictEqual(inspect(parser('$``a\\$\nb"$')), undefined);
|
|
47
|
+
assert.deepStrictEqual(inspect(parser('$``a\\$\\\nb"$')), undefined);
|
|
48
|
+
assert.deepStrictEqual(inspect(parser('$"$')), undefined);
|
|
49
|
+
assert.deepStrictEqual(inspect(parser('$}$')), undefined);
|
|
38
50
|
assert.deepStrictEqual(inspect(parser('${')), undefined);
|
|
39
51
|
assert.deepStrictEqual(inspect(parser('${a')), undefined);
|
|
40
52
|
assert.deepStrictEqual(inspect(parser('${$')), undefined);
|
|
41
53
|
assert.deepStrictEqual(inspect(parser('${}')), undefined);
|
|
42
54
|
assert.deepStrictEqual(inspect(parser('${a} $')), undefined);
|
|
43
|
-
assert.deepStrictEqual(inspect(parser('${a}b$')), undefined);
|
|
44
|
-
assert.deepStrictEqual(inspect(parser('${a}{b}$')), undefined);
|
|
45
55
|
assert.deepStrictEqual(inspect(parser('${a{b}$')), undefined);
|
|
46
56
|
assert.deepStrictEqual(inspect(parser('${a}b}$')), undefined);
|
|
57
|
+
assert.deepStrictEqual(inspect(parser('${$}$')), undefined);
|
|
47
58
|
assert.deepStrictEqual(inspect(parser('${\\}$')), undefined);
|
|
48
59
|
assert.deepStrictEqual(inspect(parser('${\n}$')), undefined);
|
|
49
60
|
assert.deepStrictEqual(inspect(parser('${a\\$\nb}$')), undefined);
|
|
50
61
|
assert.deepStrictEqual(inspect(parser('${a\\$\\\nb}$')), undefined);
|
|
62
|
+
assert.deepStrictEqual(inspect(parser('$\\begin{}$')), [['<span class="invalid" translate="no">$\\begin{}$</span>'], '']);
|
|
63
|
+
assert.deepStrictEqual(inspect(parser('$\\huge0$')), [['<span class="invalid" translate="no">$\\huge0$</span>'], '']);
|
|
64
|
+
assert.deepStrictEqual(inspect(parser('$\\Begin{}$')), [['<span class="invalid" translate="no">$\\Begin{}$</span>'], '']);
|
|
51
65
|
assert.deepStrictEqual(inspect(parser('${\\begin}$')), [['<span class="invalid" translate="no">${\\begin}$</span>'], '']);
|
|
52
|
-
assert.deepStrictEqual(inspect(parser('${\\Huge}$')), [['<span class="invalid" translate="no">${\\Huge}$</span>'], '']);
|
|
53
|
-
assert.deepStrictEqual(inspect(parser('${a}b$')), undefined);
|
|
54
66
|
assert.deepStrictEqual(inspect(parser(' ${a}$')), undefined);
|
|
55
67
|
});
|
|
56
68
|
|
|
57
69
|
it('basic', () => {
|
|
58
70
|
assert.deepStrictEqual(inspect(parser('$0$')), [['<span class="math" translate="no" data-src="$0$">$0$</span>'], '']);
|
|
59
71
|
assert.deepStrictEqual(inspect(parser('$0$$')), [['<span class="math" translate="no" data-src="$0$">$0$</span>'], '$']);
|
|
72
|
+
assert.deepStrictEqual(inspect(parser('$00$')), [['<span class="math" translate="no" data-src="$00$">$00$</span>'], '']);
|
|
73
|
+
assert.deepStrictEqual(inspect(parser('$-0$')), [['<span class="math" translate="no" data-src="$-0$">$-0$</span>'], '']);
|
|
60
74
|
assert.deepStrictEqual(inspect(parser('$0-1$')), [['<span class="math" translate="no" data-src="$0-1$">$0-1$</span>'], '']);
|
|
61
75
|
assert.deepStrictEqual(inspect(parser('$0+1$')), [['<span class="math" translate="no" data-src="$0+1$">$0+1$</span>'], '']);
|
|
62
76
|
assert.deepStrictEqual(inspect(parser('$0*1$')), [['<span class="math" translate="no" data-src="$0*1$">$0*1$</span>'], '']);
|
|
63
77
|
assert.deepStrictEqual(inspect(parser('$0/1$')), [['<span class="math" translate="no" data-src="$0/1$">$0/1$</span>'], '']);
|
|
64
78
|
assert.deepStrictEqual(inspect(parser('$a$')), [['<span class="math" translate="no" data-src="$a$">$a$</span>'], '']);
|
|
65
79
|
assert.deepStrictEqual(inspect(parser('$a$$')), [['<span class="math" translate="no" data-src="$a$">$a$</span>'], '$']);
|
|
66
|
-
assert.deepStrictEqual(inspect(parser('$a
|
|
80
|
+
assert.deepStrictEqual(inspect(parser('$a-b$')), [['<span class="math" translate="no" data-src="$a-b$">$a-b$</span>'], '']);
|
|
67
81
|
assert.deepStrictEqual(inspect(parser('$a+b$')), [['<span class="math" translate="no" data-src="$a+b$">$a+b$</span>'], '']);
|
|
68
82
|
assert.deepStrictEqual(inspect(parser('$a*b$')), [['<span class="math" translate="no" data-src="$a*b$">$a*b$</span>'], '']);
|
|
69
83
|
assert.deepStrictEqual(inspect(parser('$a/b$')), [['<span class="math" translate="no" data-src="$a/b$">$a/b$</span>'], '']);
|
|
@@ -71,6 +85,7 @@ describe('Unit: parser/inline/math', () => {
|
|
|
71
85
|
assert.deepStrictEqual(inspect(parser(`$a''$`)), [[`<span class="math" translate="no" data-src="$a''$">$a''$</span>`], '']);
|
|
72
86
|
assert.deepStrictEqual(inspect(parser('$a$[A](a)')), [['<span class="math" translate="no" data-src="$a$">$a$</span>'], '[A](a)']);
|
|
73
87
|
assert.deepStrictEqual(inspect(parser('$A$')), [['<span class="math" translate="no" data-src="$A$">$A$</span>'], '']);
|
|
88
|
+
assert.deepStrictEqual(inspect(parser('$-a$')), [['<span class="math" translate="no" data-src="$-a$">$-a$</span>'], '']);
|
|
74
89
|
assert.deepStrictEqual(inspect(parser('$\\$$')), [['<span class="math" translate="no" data-src="$\\$$">$\\$$</span>'], '']);
|
|
75
90
|
assert.deepStrictEqual(inspect(parser('$\\Pi$')), [['<span class="math" translate="no" data-src="$\\Pi$">$\\Pi$</span>'], '']);
|
|
76
91
|
assert.deepStrictEqual(inspect(parser('$\\ 0$')), [['<span class="math" translate="no" data-src="$\\ 0$">$\\ 0$</span>'], '']);
|
|
@@ -86,6 +101,18 @@ describe('Unit: parser/inline/math', () => {
|
|
|
86
101
|
assert.deepStrictEqual(inspect(parser('$f(x)$')), [['<span class="math" translate="no" data-src="$f(x)$">$f(x)$</span>'], '']);
|
|
87
102
|
assert.deepStrictEqual(inspect(parser('$f: x \\to y$')), [['<span class="math" translate="no" data-src="$f: x \\to y$">$f: x \\to y$</span>'], '']);
|
|
88
103
|
assert.deepStrictEqual(inspect(parser('$k$-space')), [['<span class="math" translate="no" data-src="$k$">$k$</span>'], '-space']);
|
|
104
|
+
assert.deepStrictEqual(inspect(parser('$`$')), [['<span class="math" translate="no" data-src="$`$">$`$</span>'], '']);
|
|
105
|
+
assert.deepStrictEqual(inspect(parser('$`"a$')), [['<span class="math" translate="no" data-src="$`"a$">$`"a$</span>'], '']);
|
|
106
|
+
assert.deepStrictEqual(inspect(parser('$``$')), [['<span class="math" translate="no" data-src="$``$">$``$</span>'], '']);
|
|
107
|
+
assert.deepStrictEqual(inspect(parser('$``"$')), [['<span class="math" translate="no" data-src="$``"$">$``"$</span>'], '']);
|
|
108
|
+
assert.deepStrictEqual(inspect(parser('$``""a$')), [['<span class="math" translate="no" data-src="$``""a$">$``""a$</span>'], '']);
|
|
109
|
+
assert.deepStrictEqual(inspect(parser('$``a"$')), [['<span class="math" translate="no" data-src="$``a"$">$``a"$</span>'], '']);
|
|
110
|
+
assert.deepStrictEqual(inspect(parser('$``$"$')), [['<span class="math" translate="no" data-src="$``$">$``$</span>'], '"$']);
|
|
111
|
+
assert.deepStrictEqual(inspect(parser('$``\\"$')), [['<span class="math" translate="no" data-src="$``\\"$">$``\\"$</span>'], '']);
|
|
112
|
+
assert.deepStrictEqual(inspect(parser('$``a``b"c"$')), [['<span class="math" translate="no" data-src="$``a``b"c"$">$``a``b"c"$</span>'], '']);
|
|
113
|
+
assert.deepStrictEqual(inspect(parser('$```"$')), [['<span class="math" translate="no" data-src="$```"$">$```"$</span>'], '']);
|
|
114
|
+
assert.deepStrictEqual(inspect(parser('$````""$')), [['<span class="math" translate="no" data-src="$````""$">$````""$</span>'], '']);
|
|
115
|
+
assert.deepStrictEqual(inspect(parser('$a{b}$')), [['<span class="math" translate="no" data-src="$a{b}$">$a{b}$</span>'], '']);
|
|
89
116
|
assert.deepStrictEqual(inspect(parser('${}$')), [['<span class="math" translate="no" data-src="${}$">${}$</span>'], '']);
|
|
90
117
|
assert.deepStrictEqual(inspect(parser('${ }$')), [['<span class="math" translate="no" data-src="${ }$">${ }$</span>'], '']);
|
|
91
118
|
assert.deepStrictEqual(inspect(parser('${a}$')), [['<span class="math" translate="no" data-src="${a}$">${a}$</span>'], '']);
|
|
@@ -97,10 +124,14 @@ describe('Unit: parser/inline/math', () => {
|
|
|
97
124
|
assert.deepStrictEqual(inspect(parser('${a }$')), [['<span class="math" translate="no" data-src="${a }$">${a }$</span>'], '']);
|
|
98
125
|
assert.deepStrictEqual(inspect(parser('${ a}$')), [['<span class="math" translate="no" data-src="${ a}$">${ a}$</span>'], '']);
|
|
99
126
|
assert.deepStrictEqual(inspect(parser('${ a }$')), [['<span class="math" translate="no" data-src="${ a }$">${ a }$</span>'], '']);
|
|
100
|
-
assert.deepStrictEqual(inspect(parser('${
|
|
127
|
+
assert.deepStrictEqual(inspect(parser('${``a"}$')), [['<span class="math" translate="no" data-src="${``a"}$">${``a"}$</span>'], '']);
|
|
101
128
|
assert.deepStrictEqual(inspect(parser('${\\a}$')), [['<span class="math" translate="no" data-src="${\\a}$">${\\a}$</span>'], '']);
|
|
102
129
|
assert.deepStrictEqual(inspect(parser('${\\$}$')), [['<span class="math" translate="no" data-src="${\\$}$">${\\$}$</span>'], '']);
|
|
103
130
|
assert.deepStrictEqual(inspect(parser('${\\\\}$')), [['<span class="math" translate="no" data-src="${\\\\}$">${\\\\}$</span>'], '']);
|
|
131
|
+
assert.deepStrictEqual(inspect(parser('${a}b$')), [['<span class="math" translate="no" data-src="${a}b$">${a}b$</span>'], '']);
|
|
132
|
+
assert.deepStrictEqual(inspect(parser('${a}b{c}$')), [['<span class="math" translate="no" data-src="${a}b{c}$">${a}b{c}$</span>'], '']);
|
|
133
|
+
assert.deepStrictEqual(inspect(parser('${a}{b}$')), [['<span class="math" translate="no" data-src="${a}{b}$">${a}{b}$</span>'], '']);
|
|
134
|
+
assert.deepStrictEqual(inspect(parser('${あ}$')), [['<span class="math" translate="no" data-src="${あ}$">${あ}$</span>'], '']);
|
|
104
135
|
});
|
|
105
136
|
|
|
106
137
|
it('nest', () => {
|
|
@@ -1,35 +1,34 @@
|
|
|
1
1
|
import { MathParser } from '../inline';
|
|
2
|
-
import { union, some, validate, rewrite, creator, surround, lazy } from '../../combinator';
|
|
2
|
+
import { union, some, validate, focus, rewrite, creator, surround, lazy } from '../../combinator';
|
|
3
3
|
import { escsource, str } from '../source';
|
|
4
4
|
import { html } from 'typed-dom/dom';
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const syntax = /^(?:[ "([](?!\$)|\\{(?!\$)|\\[\\}$]?|^`|`(?!`)|[!#%&')\x2A-\x5A\]^_\x61-\x7A|~])+/;
|
|
7
|
+
const forbiddenCommand = /\\(?:begin|tiny|huge|large)(?![a-z])/i;
|
|
7
8
|
|
|
8
9
|
export const math: MathParser = lazy(() => creator(validate('$', rewrite(
|
|
9
10
|
union([
|
|
10
|
-
surround(
|
|
11
|
-
'$',
|
|
12
|
-
// Latex's reserved characters: # $ % ^ & _ { } ~ \
|
|
13
|
-
// $[0-9]+ : Dollar
|
|
14
|
-
// $[A-z]*- : Label
|
|
15
|
-
// $[A-z]*(?!-) : Math
|
|
16
|
-
// $[\^_[({|] : Math
|
|
17
|
-
// $[#$%&] : Invalid first character in Latex syntax
|
|
18
|
-
str(/^(?![\s{}#$%&]|\d+(?:[,.]\d+)*[^-+*/=<>^_~\\$]|-[\da-z]|[a-z]+-)(?:\\\$|\x20(?!\$)|[\x21-\x23\x25-\x7E])+/i),
|
|
19
|
-
/^\$(?![0-9a-z])/i),
|
|
20
11
|
surround('$', bracket, '$'),
|
|
12
|
+
surround(
|
|
13
|
+
/^\$(?!\s)/,
|
|
14
|
+
some(union([
|
|
15
|
+
bracket,
|
|
16
|
+
quote,
|
|
17
|
+
str(syntax),
|
|
18
|
+
])),
|
|
19
|
+
/^\$(?![0-9A-Za-z])/),
|
|
21
20
|
]),
|
|
22
21
|
(source, { caches: { math: cache } = {} }) => [[
|
|
23
22
|
cache?.get(source)?.cloneNode(true) ||
|
|
24
23
|
html('span',
|
|
25
|
-
!
|
|
24
|
+
!forbiddenCommand.test(source)
|
|
26
25
|
? { class: 'math', translate: 'no', 'data-src': source }
|
|
27
26
|
: {
|
|
28
27
|
class: 'invalid',
|
|
29
28
|
translate: 'no',
|
|
30
29
|
'data-invalid-syntax': 'math',
|
|
31
30
|
'data-invalid-type': 'content',
|
|
32
|
-
'data-invalid-message': `"${source.match(
|
|
31
|
+
'data-invalid-message': `"${source.match(forbiddenCommand)![0]}" command is forbidden`,
|
|
33
32
|
},
|
|
34
33
|
source)
|
|
35
34
|
], '']))));
|
|
@@ -38,7 +37,17 @@ const bracket: MathParser.BracketParser = lazy(() => creator(surround(
|
|
|
38
37
|
'{',
|
|
39
38
|
some(union([
|
|
40
39
|
bracket,
|
|
41
|
-
some(escsource, /^(?:[{}]|\\?\n)/),
|
|
40
|
+
some(escsource, /^(?:[{}$]|\\?\n)/),
|
|
42
41
|
])),
|
|
43
42
|
'}',
|
|
44
43
|
true)));
|
|
44
|
+
|
|
45
|
+
const quote: MathParser.QuoteParser = lazy(() => creator(surround(
|
|
46
|
+
'``',
|
|
47
|
+
some(union([
|
|
48
|
+
quote,
|
|
49
|
+
bracket,
|
|
50
|
+
focus(/^(?:\\[\\{}$]|`(?!`)|[^`{}"$\n])*/, str(syntax)),
|
|
51
|
+
])),
|
|
52
|
+
/^"?/,
|
|
53
|
+
true)));
|
|
@@ -112,7 +112,8 @@ describe('Unit: parser/inline', () => {
|
|
|
112
112
|
assert.deepStrictEqual(inspect(parser('[$1]')), [['[', '$', '1', ']'], '']);
|
|
113
113
|
assert.deepStrictEqual(inspect(parser('[$1-2]')), [['[', '$', '1', '-', '2', ']'], '']);
|
|
114
114
|
assert.deepStrictEqual(inspect(parser('[$-1][$-2]')), [['<a class="label" data-label="$-1">$-1</a>', '<a class="label" data-label="$-2">$-2</a>'], '']);
|
|
115
|
-
assert.deepStrictEqual(inspect(parser('$-1$-2')), [['<a class="label" data-label="$-1">$-1</a>', '<a class="label" data-label="$-2">$-2</a>'], '']);
|
|
115
|
+
assert.deepStrictEqual(inspect(parser('$-1, $-2')), [['<a class="label" data-label="$-1">$-1</a>', ',', ' ', '<a class="label" data-label="$-2">$-2</a>'], '']);
|
|
116
|
+
assert.deepStrictEqual(inspect(parser('$-1 and $-2')), [['<a class="label" data-label="$-1">$-1</a>', ' ', 'and', ' ', '<a class="label" data-label="$-2">$-2</a>'], '']);
|
|
116
117
|
assert.deepStrictEqual(inspect(parser('$$-1')), [['$', '<a class="label" data-label="$-1">$-1</a>'], '']);
|
|
117
118
|
assert.deepStrictEqual(inspect(parser('[[#a]]')), [['<sup class="reference"><a href="/hashtags/a" class="hashtag">#a</a></sup>'], '']);
|
|
118
119
|
assert.deepStrictEqual(inspect(parser('[[$-1]]')), [['<sup class="reference"><a class="label" data-label="$-1">$-1</a></sup>'], '']);
|
package/src/parser/inline.ts
CHANGED
|
@@ -5,6 +5,7 @@ import { annotation } from './inline/annotation';
|
|
|
5
5
|
import { reference } from './inline/reference';
|
|
6
6
|
import { template } from './inline/template';
|
|
7
7
|
import { comment } from './inline/comment';
|
|
8
|
+
import { math } from './inline/math';
|
|
8
9
|
import { extension } from './inline/extension';
|
|
9
10
|
import { ruby } from './inline/ruby';
|
|
10
11
|
import { link } from './inline/link';
|
|
@@ -16,7 +17,6 @@ import { emstrong } from './inline/emstrong';
|
|
|
16
17
|
import { emphasis } from './inline/emphasis';
|
|
17
18
|
import { strong } from './inline/strong';
|
|
18
19
|
import { code } from './inline/code';
|
|
19
|
-
import { math } from './inline/math';
|
|
20
20
|
import { media } from './inline/media';
|
|
21
21
|
import { htmlentity } from './inline/htmlentity';
|
|
22
22
|
import { shortmedia } from './inline/shortmedia';
|
|
@@ -30,6 +30,7 @@ export import AnnotationParser = InlineParser.AnnotationParser;
|
|
|
30
30
|
export import ReferenceParser = InlineParser.ReferenceParser;
|
|
31
31
|
export import TemplateParser = InlineParser.TemplateParser;
|
|
32
32
|
export import CommentParser = InlineParser.CommentParser;
|
|
33
|
+
export import MathParser = InlineParser.MathParser;
|
|
33
34
|
export import ExtensionParser = InlineParser.ExtensionParser;
|
|
34
35
|
export import RubyParser = InlineParser.RubyParser;
|
|
35
36
|
export import LinkParser = InlineParser.LinkParser;
|
|
@@ -41,7 +42,6 @@ export import EmStrongParser = InlineParser.EmStrongParser;
|
|
|
41
42
|
export import EmphasisParser = InlineParser.EmphasisParser;
|
|
42
43
|
export import StrongParser = InlineParser.StrongParser;
|
|
43
44
|
export import CodeParser = InlineParser.CodeParser;
|
|
44
|
-
export import MathParser = InlineParser.MathParser;
|
|
45
45
|
export import MediaParser = InlineParser.MediaParser;
|
|
46
46
|
export import HTMLEntityParser = InlineParser.HTMLEntityParser;
|
|
47
47
|
export import UnsafeHTMLEntityParser = InlineParser.UnsafeHTMLEntityParser;
|
|
@@ -55,6 +55,7 @@ export const inline: InlineParser = union([
|
|
|
55
55
|
reference,
|
|
56
56
|
template,
|
|
57
57
|
comment,
|
|
58
|
+
math,
|
|
58
59
|
extension,
|
|
59
60
|
ruby,
|
|
60
61
|
link,
|
|
@@ -67,7 +68,6 @@ export const inline: InlineParser = union([
|
|
|
67
68
|
strong,
|
|
68
69
|
emphasis,
|
|
69
70
|
code,
|
|
70
|
-
math,
|
|
71
71
|
htmlentity,
|
|
72
72
|
shortmedia,
|
|
73
73
|
autolink,
|
package/webpack.config.js
CHANGED
|
@@ -6,7 +6,7 @@ const { mergeWithRules } = require('webpack-merge');
|
|
|
6
6
|
const ESLintPlugin = require('eslint-webpack-plugin');
|
|
7
7
|
const pkg = require('./package.json');
|
|
8
8
|
|
|
9
|
-
shell('rm -rf
|
|
9
|
+
shell('rm -rf coverage');
|
|
10
10
|
|
|
11
11
|
module.exports = env => {
|
|
12
12
|
const merge = mergeWithRules({
|
|
@@ -39,7 +39,7 @@ module.exports = env => {
|
|
|
39
39
|
path: path.resolve(__dirname, 'dist'),
|
|
40
40
|
library: pkg.name,
|
|
41
41
|
libraryTarget: 'umd',
|
|
42
|
-
globalObject: '
|
|
42
|
+
globalObject: 'this',
|
|
43
43
|
clean: true,
|
|
44
44
|
},
|
|
45
45
|
module: {
|