securemark 0.289.2 → 0.289.3
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 +4 -0
- package/design.md +2 -1
- package/dist/index.js +94 -78
- package/package.json +1 -1
- package/src/combinator/control/constraint/block.ts +1 -1
- package/src/combinator/control/constraint/contract.ts +7 -7
- package/src/combinator/control/constraint/line.ts +1 -1
- package/src/combinator/control/manipulation/clear.ts +7 -0
- package/src/combinator/control/manipulation/convert.ts +1 -1
- package/src/combinator/control/manipulation/duplicate.ts +4 -4
- package/src/combinator/control/manipulation/fallback.ts +3 -3
- package/src/combinator/control/manipulation/indent.ts +3 -3
- package/src/combinator/control/manipulation/lazy.ts +2 -2
- package/src/combinator/control/manipulation/match.ts +1 -1
- package/src/combinator/control/manipulation/recovery.ts +3 -3
- package/src/combinator/control/manipulation/reverse.ts +1 -1
- package/src/combinator/control/manipulation/scope.ts +3 -3
- package/src/combinator/control/manipulation/surround.ts +59 -61
- package/src/combinator/control/manipulation/trim.ts +3 -3
- package/src/combinator/control/monad/bind.ts +6 -6
- package/src/combinator/control/monad/fmap.ts +6 -6
- package/src/combinator/data/parser/context/delimiter.ts +21 -19
- package/src/combinator/data/parser/context.ts +8 -8
- package/src/combinator/data/parser/inits.ts +4 -4
- package/src/combinator/data/parser/sequence.ts +4 -4
- package/src/combinator/data/parser/some.ts +3 -3
- package/src/combinator/data/parser/subsequence.ts +3 -3
- package/src/combinator/data/parser/tails.ts +3 -3
- package/src/combinator/data/parser/union.ts +3 -3
- package/src/combinator/data/parser.ts +13 -13
- package/src/combinator.ts +1 -0
- package/src/parser/block/extension/figure.ts +1 -1
- package/src/parser/block/extension/table.ts +3 -3
- package/src/parser/block/olist.ts +4 -4
- package/src/parser/block/reply/cite.ts +3 -3
- package/src/parser/block/ulist.ts +1 -1
- package/src/parser/inline/autolink/hashnum.ts +5 -1
- package/src/parser/inline/code.ts +2 -1
- package/src/parser/inline/extension/label.ts +1 -1
- package/src/parser/util.ts +10 -10
- package/src/parser/visibility.ts +11 -11
- package/src/util/quote.ts +1 -1
package/CHANGELOG.md
CHANGED
package/design.md
CHANGED
|
@@ -321,9 +321,10 @@ Markdownに本当に必要な仕様はSecuremarkのクラス化制約のよう
|
|
|
321
321
|
- 画像のalt(`![*a*]()`, `![![a]()`)をMarkdownとして解釈
|
|
322
322
|
- 再帰的バックトラック回避の必要上修正不可能
|
|
323
323
|
- リンクのURLを効率的に解析不可能
|
|
324
|
-
- altはまだしもURLは文脈依存構文としての解析を避けられないため再帰もまた避けられず公式デモページのCommonMarkで`[](`を1
|
|
324
|
+
- altはまだしもURLは文脈依存構文としての解析を避けられないため再帰もまた避けられず公式デモページのCommonMarkで`[](`を1万回程度繰り返しただけで解析時間が1秒を超える
|
|
325
325
|
- この欠陥は入れ子数を制限することで回避可能だがこれはCommonmarkは文脈依存構文全般に入れ子数制限を要することを意味する
|
|
326
326
|
- CommonMarkは最初のバージョンから数年後にこの欠陥を入れ子数制限により修正しこれにより最悪計算量が当初の想定の2nから32nへと32倍に劇的に悪化したことから文脈自由言語および最小計算量としての設計と開発が破綻し失敗に終わったことが明らかである
|
|
327
|
+
- GFMも`[1]([2]()(...[34]()...))`で32回の再帰的バックトラックを行い最悪計算量が32nであることが確認できる
|
|
327
328
|
- これほど計算量が悪ければ入れ子数制限付き文脈依存言語と大差ない計算量であり素直に文脈依存言語として作り直したほうが遥かに拡張性と発展性が高く優れている
|
|
328
329
|
- 計算資源は使うためにあるにもかかわらず言語と一致しない不適切な解析方法を使用してまでこの程度の計算資源を惜しんで人間に不便と不自由を強いて生産性を下げるのは本末転倒である
|
|
329
330
|
- 計算機は人間の生産性に奉仕しなければならない
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! securemark v0.289.
|
|
1
|
+
/*! securemark v0.289.3 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("Prism"), require("DOMPurify"));
|
|
@@ -2680,6 +2680,7 @@ __exportStar(__webpack_require__(4271), exports);
|
|
|
2680
2680
|
__exportStar(__webpack_require__(7190), exports);
|
|
2681
2681
|
__exportStar(__webpack_require__(549), exports);
|
|
2682
2682
|
__exportStar(__webpack_require__(7723), exports);
|
|
2683
|
+
__exportStar(__webpack_require__(8606), exports);
|
|
2683
2684
|
__exportStar(__webpack_require__(5781), exports);
|
|
2684
2685
|
__exportStar(__webpack_require__(1638), exports);
|
|
2685
2686
|
__exportStar(__webpack_require__(6572), exports);
|
|
@@ -2821,6 +2822,24 @@ exports.isBlank = isBlank;
|
|
|
2821
2822
|
|
|
2822
2823
|
/***/ },
|
|
2823
2824
|
|
|
2825
|
+
/***/ 8606
|
|
2826
|
+
(__unused_webpack_module, exports, __webpack_require__) {
|
|
2827
|
+
|
|
2828
|
+
"use strict";
|
|
2829
|
+
|
|
2830
|
+
|
|
2831
|
+
Object.defineProperty(exports, "__esModule", ({
|
|
2832
|
+
value: true
|
|
2833
|
+
}));
|
|
2834
|
+
exports.clear = void 0;
|
|
2835
|
+
const fmap_1 = __webpack_require__(2705);
|
|
2836
|
+
function clear(parser) {
|
|
2837
|
+
return (0, fmap_1.fmap)(parser, () => []);
|
|
2838
|
+
}
|
|
2839
|
+
exports.clear = clear;
|
|
2840
|
+
|
|
2841
|
+
/***/ },
|
|
2842
|
+
|
|
2824
2843
|
/***/ 6572
|
|
2825
2844
|
(__unused_webpack_module, exports, __webpack_require__) {
|
|
2826
2845
|
|
|
@@ -2972,7 +2991,7 @@ function indent(opener, parser, separation = false) {
|
|
|
2972
2991
|
if (typeof opener === 'function') return indent(/^([ \t])\1*/, opener, parser);
|
|
2973
2992
|
return (0, bind_1.bind)((0, block_1.block)((0, match_1.match)(opener, (0, memoize_1.memoize)(([indent]) => (0, some_1.some)((0, line_1.line)((0, surround_1.open)(indent, ({
|
|
2974
2993
|
source
|
|
2975
|
-
}) => [[source], '']))), ([indent]) => indent.length * 2 + +(indent[0] === ' '), {})
|
|
2994
|
+
}) => [[source], '']))), ([indent]) => indent.length * 2 + +(indent[0] === ' '), {})), separation), (lines, rest, context) => {
|
|
2976
2995
|
// 影響する使用はないはず
|
|
2977
2996
|
//const { backtracks } = context;
|
|
2978
2997
|
//context.backtracks = {};
|
|
@@ -3022,7 +3041,7 @@ Object.defineProperty(exports, "__esModule", ({
|
|
|
3022
3041
|
exports.match = void 0;
|
|
3023
3042
|
const parser_1 = __webpack_require__(605);
|
|
3024
3043
|
const combinator_1 = __webpack_require__(3484);
|
|
3025
|
-
function match(pattern, f, cost =
|
|
3044
|
+
function match(pattern, f, cost = false) {
|
|
3026
3045
|
return input => {
|
|
3027
3046
|
const {
|
|
3028
3047
|
source,
|
|
@@ -3156,9 +3175,8 @@ exports.rewrite = rewrite;
|
|
|
3156
3175
|
Object.defineProperty(exports, "__esModule", ({
|
|
3157
3176
|
value: true
|
|
3158
3177
|
}));
|
|
3159
|
-
exports.
|
|
3178
|
+
exports.close = exports.open = exports.surround = void 0;
|
|
3160
3179
|
const parser_1 = __webpack_require__(605);
|
|
3161
|
-
const fmap_1 = __webpack_require__(2705);
|
|
3162
3180
|
const array_1 = __webpack_require__(6876);
|
|
3163
3181
|
function surround(opener, parser, closer, optional = false, f, g, backtracks = [], backtrackstate = 0) {
|
|
3164
3182
|
switch (typeof opener) {
|
|
@@ -3176,19 +3194,19 @@ function surround(opener, parser, closer, optional = false, f, g, backtracks = [
|
|
|
3176
3194
|
source,
|
|
3177
3195
|
context
|
|
3178
3196
|
}) => {
|
|
3179
|
-
const
|
|
3180
|
-
if (
|
|
3197
|
+
const sme_ = source;
|
|
3198
|
+
if (sme_ === '') return;
|
|
3181
3199
|
const {
|
|
3182
3200
|
linebreak
|
|
3183
3201
|
} = context;
|
|
3184
3202
|
context.linebreak = undefined;
|
|
3185
|
-
const
|
|
3186
|
-
source:
|
|
3203
|
+
const resultS = opener({
|
|
3204
|
+
source: sme_,
|
|
3187
3205
|
context
|
|
3188
3206
|
});
|
|
3189
|
-
if (
|
|
3190
|
-
const
|
|
3191
|
-
const
|
|
3207
|
+
if (resultS === undefined) return void revert(context, linebreak);
|
|
3208
|
+
const nodesS = (0, parser_1.eval)(resultS);
|
|
3209
|
+
const me_ = (0, parser_1.exec)(resultS);
|
|
3192
3210
|
for (const backtrack of backtracks) {
|
|
3193
3211
|
if (backtrack & 1) {
|
|
3194
3212
|
const {
|
|
@@ -3196,9 +3214,9 @@ function surround(opener, parser, closer, optional = false, f, g, backtracks = [
|
|
|
3196
3214
|
backtrack: state = 0,
|
|
3197
3215
|
offset = 0
|
|
3198
3216
|
} = context;
|
|
3199
|
-
for (let i = 0; i < source.length -
|
|
3217
|
+
for (let i = 0; i < source.length - me_.length; ++i) {
|
|
3200
3218
|
if (source[i] !== source[0]) break;
|
|
3201
|
-
const pos = source.length + offset -
|
|
3219
|
+
const pos = source.length - i + offset - 1;
|
|
3202
3220
|
if (!(pos in backtracks)) continue;
|
|
3203
3221
|
const shift = backtrack >>> statesize & state >>> statesize ? state & (1 << statesize) - 1 : 0;
|
|
3204
3222
|
if (backtracks[pos] & 1 << size(backtrack >>> statesize) + shift) return void revert(context, linebreak);
|
|
@@ -3209,34 +3227,35 @@ function surround(opener, parser, closer, optional = false, f, g, backtracks = [
|
|
|
3209
3227
|
backtrack = 0
|
|
3210
3228
|
} = context;
|
|
3211
3229
|
context.backtrack = backtrack | backtrackstate;
|
|
3212
|
-
const
|
|
3213
|
-
source:
|
|
3230
|
+
const resultM = me_ !== '' ? parser({
|
|
3231
|
+
source: me_,
|
|
3214
3232
|
context
|
|
3215
3233
|
}) : undefined;
|
|
3216
3234
|
context.backtrack = backtrack;
|
|
3217
|
-
const
|
|
3218
|
-
const
|
|
3219
|
-
if (!
|
|
3220
|
-
const
|
|
3221
|
-
source:
|
|
3235
|
+
const nodesM = (0, parser_1.eval)(resultM);
|
|
3236
|
+
const e_ = (0, parser_1.exec)(resultM, me_);
|
|
3237
|
+
if (!nodesM && !optional) return void revert(context, linebreak);
|
|
3238
|
+
const resultE = closer({
|
|
3239
|
+
source: e_,
|
|
3222
3240
|
context
|
|
3223
3241
|
});
|
|
3224
|
-
const
|
|
3225
|
-
const rest = (0, parser_1.exec)(
|
|
3226
|
-
if (rest.length ===
|
|
3242
|
+
const nodesE = (0, parser_1.eval)(resultE);
|
|
3243
|
+
const rest = (0, parser_1.exec)(resultE, e_);
|
|
3244
|
+
if (rest.length === sme_.length) return void revert(context, linebreak);
|
|
3227
3245
|
for (const backtrack of backtracks) {
|
|
3228
|
-
if (backtrack & 2 &&
|
|
3246
|
+
if (backtrack & 2 && nodesE === undefined) {
|
|
3229
3247
|
const {
|
|
3230
3248
|
backtracks = {},
|
|
3231
3249
|
backtrack: state = 0,
|
|
3232
3250
|
offset = 0
|
|
3233
3251
|
} = context;
|
|
3252
|
+
const pos = source.length + offset - 1;
|
|
3234
3253
|
const shift = backtrack >>> statesize & state >>> statesize ? state & (1 << statesize) - 1 : 0;
|
|
3235
|
-
backtracks[
|
|
3254
|
+
backtracks[pos] |= 1 << size(backtrack >>> statesize) + shift;
|
|
3236
3255
|
}
|
|
3237
3256
|
}
|
|
3238
|
-
context.recent = [
|
|
3239
|
-
const result =
|
|
3257
|
+
context.recent = [sme_.slice(0, sme_.length - me_.length), me_.slice(0, me_.length - e_.length), e_.slice(0, e_.length - rest.length)];
|
|
3258
|
+
const result = nodesE ? f ? f([nodesS, nodesM, nodesE], rest, context) : [(0, array_1.push)((0, array_1.unshift)(nodesS, nodesM ?? []), nodesE), rest] : g ? g([nodesS, nodesM, me_], rest, context) : undefined;
|
|
3240
3259
|
if (result) {
|
|
3241
3260
|
context.linebreak ??= linebreak;
|
|
3242
3261
|
} else {
|
|
@@ -3246,6 +3265,14 @@ function surround(opener, parser, closer, optional = false, f, g, backtracks = [
|
|
|
3246
3265
|
};
|
|
3247
3266
|
}
|
|
3248
3267
|
exports.surround = surround;
|
|
3268
|
+
function open(opener, parser, optional = false) {
|
|
3269
|
+
return surround(opener, parser, '', optional);
|
|
3270
|
+
}
|
|
3271
|
+
exports.open = open;
|
|
3272
|
+
function close(parser, closer, optional = false) {
|
|
3273
|
+
return surround('', parser, closer, optional);
|
|
3274
|
+
}
|
|
3275
|
+
exports.close = close;
|
|
3249
3276
|
function match(pattern) {
|
|
3250
3277
|
switch (typeof pattern) {
|
|
3251
3278
|
case 'string':
|
|
@@ -3261,30 +3288,19 @@ function match(pattern) {
|
|
|
3261
3288
|
};
|
|
3262
3289
|
}
|
|
3263
3290
|
}
|
|
3291
|
+
function revert(context, linebreak) {
|
|
3292
|
+
context.linebreak = linebreak;
|
|
3293
|
+
}
|
|
3264
3294
|
function size(bits) {
|
|
3265
3295
|
if (bits === 0) return 0;
|
|
3266
3296
|
let p = 0;
|
|
3267
3297
|
for (let s = 32 / 2; s > 0; s >>>= 1) {
|
|
3268
|
-
|
|
3269
|
-
|
|
3298
|
+
const q = p + s;
|
|
3299
|
+
if (bits >>> q === 0) continue;
|
|
3300
|
+
p = q;
|
|
3270
3301
|
}
|
|
3271
3302
|
return p + 1;
|
|
3272
3303
|
}
|
|
3273
|
-
function revert(context, linebreak) {
|
|
3274
|
-
context.linebreak = linebreak;
|
|
3275
|
-
}
|
|
3276
|
-
function open(opener, parser, optional = false) {
|
|
3277
|
-
return surround(opener, parser, '', optional);
|
|
3278
|
-
}
|
|
3279
|
-
exports.open = open;
|
|
3280
|
-
function close(parser, closer, optional = false) {
|
|
3281
|
-
return surround('', parser, closer, optional);
|
|
3282
|
-
}
|
|
3283
|
-
exports.close = close;
|
|
3284
|
-
function clear(parser) {
|
|
3285
|
-
return (0, fmap_1.fmap)(parser, () => []);
|
|
3286
|
-
}
|
|
3287
|
-
exports.clear = clear;
|
|
3288
3304
|
|
|
3289
3305
|
/***/ },
|
|
3290
3306
|
|
|
@@ -3556,7 +3572,6 @@ exports.constraint = constraint;
|
|
|
3556
3572
|
"use strict";
|
|
3557
3573
|
|
|
3558
3574
|
|
|
3559
|
-
var _a;
|
|
3560
3575
|
Object.defineProperty(exports, "__esModule", ({
|
|
3561
3576
|
value: true
|
|
3562
3577
|
}));
|
|
@@ -3569,14 +3584,24 @@ class Delimiters {
|
|
|
3569
3584
|
this.stack = [];
|
|
3570
3585
|
this.states = [];
|
|
3571
3586
|
}
|
|
3572
|
-
static signature(pattern) {
|
|
3587
|
+
static signature(pattern, linebreakable) {
|
|
3573
3588
|
switch (typeof pattern) {
|
|
3574
3589
|
case 'undefined':
|
|
3575
3590
|
return `undefined`;
|
|
3576
3591
|
case 'string':
|
|
3577
|
-
return `s:${pattern}`;
|
|
3592
|
+
return `s:${pattern}:${+linebreakable}`;
|
|
3578
3593
|
case 'object':
|
|
3579
|
-
return `r/${pattern.source}/${
|
|
3594
|
+
return `r/${pattern.source}/${+linebreakable}`;
|
|
3595
|
+
}
|
|
3596
|
+
}
|
|
3597
|
+
static matcher(pattern) {
|
|
3598
|
+
switch (typeof pattern) {
|
|
3599
|
+
case 'undefined':
|
|
3600
|
+
return () => undefined;
|
|
3601
|
+
case 'string':
|
|
3602
|
+
return source => source.slice(0, pattern.length) === pattern || undefined;
|
|
3603
|
+
case 'object':
|
|
3604
|
+
return source => pattern.test(source) || undefined;
|
|
3580
3605
|
}
|
|
3581
3606
|
}
|
|
3582
3607
|
push(delims) {
|
|
@@ -3596,13 +3621,14 @@ class Delimiters {
|
|
|
3596
3621
|
} = delims[i];
|
|
3597
3622
|
const memory = registry(signature);
|
|
3598
3623
|
const index = memory[0]?.index ?? delimiters.length;
|
|
3599
|
-
if (memory.length === 0
|
|
3624
|
+
if (memory.length === 0) {
|
|
3600
3625
|
const delimiter = {
|
|
3626
|
+
memory,
|
|
3601
3627
|
index,
|
|
3602
3628
|
signature,
|
|
3603
3629
|
matcher,
|
|
3604
3630
|
precedence,
|
|
3605
|
-
linebreakable
|
|
3631
|
+
linebreakable,
|
|
3606
3632
|
state: true
|
|
3607
3633
|
};
|
|
3608
3634
|
delimiters[index] = delimiter;
|
|
@@ -3616,14 +3642,15 @@ class Delimiters {
|
|
|
3616
3642
|
}
|
|
3617
3643
|
pop(count) {
|
|
3618
3644
|
const {
|
|
3619
|
-
registry,
|
|
3620
3645
|
delimiters,
|
|
3621
3646
|
stack
|
|
3622
3647
|
} = this;
|
|
3623
3648
|
for (let i = 0; i < count; ++i) {
|
|
3624
3649
|
const index = stack.pop();
|
|
3625
3650
|
if (index === -1) continue;
|
|
3626
|
-
const
|
|
3651
|
+
const {
|
|
3652
|
+
memory
|
|
3653
|
+
} = delimiters[index];
|
|
3627
3654
|
if (memory.length === 1) {
|
|
3628
3655
|
memory.pop();
|
|
3629
3656
|
delimiters.pop();
|
|
@@ -3679,17 +3706,6 @@ class Delimiters {
|
|
|
3679
3706
|
}
|
|
3680
3707
|
}
|
|
3681
3708
|
exports.Delimiters = Delimiters;
|
|
3682
|
-
_a = Delimiters;
|
|
3683
|
-
Delimiters.matcher = (0, memoize_1.memoize)(pattern => {
|
|
3684
|
-
switch (typeof pattern) {
|
|
3685
|
-
case 'undefined':
|
|
3686
|
-
return () => undefined;
|
|
3687
|
-
case 'string':
|
|
3688
|
-
return source => source.slice(0, pattern.length) === pattern || undefined;
|
|
3689
|
-
case 'object':
|
|
3690
|
-
return source => pattern.test(source) || undefined;
|
|
3691
|
-
}
|
|
3692
|
-
}, _a.signature);
|
|
3693
3709
|
|
|
3694
3710
|
/***/ },
|
|
3695
3711
|
|
|
@@ -3788,7 +3804,7 @@ function some(parser, end, delimiters = [], limit = -1) {
|
|
|
3788
3804
|
if (typeof end === 'number') return some(parser, undefined, delimiters, end);
|
|
3789
3805
|
const match = delimiter_1.Delimiters.matcher(end);
|
|
3790
3806
|
const delims = delimiters.map(([delimiter, precedence, linebreakable = true]) => ({
|
|
3791
|
-
signature: delimiter_1.Delimiters.signature(delimiter),
|
|
3807
|
+
signature: delimiter_1.Delimiters.signature(delimiter, linebreakable),
|
|
3792
3808
|
matcher: delimiter_1.Delimiters.matcher(delimiter),
|
|
3793
3809
|
precedence,
|
|
3794
3810
|
linebreakable
|
|
@@ -4802,7 +4818,7 @@ const memoize_1 = __webpack_require__(6925);
|
|
|
4802
4818
|
const dom_1 = __webpack_require__(394);
|
|
4803
4819
|
exports.segment = (0, combinator_1.block)((0, combinator_1.match)(/^(~{3,})(?:figure[^\S\n])?(?=\[?\$)/, (0, memoize_1.memoize)(([, fence], closer = new RegExp(String.raw`^${fence}[^\S\n]*(?:$|\n)`)) => (0, combinator_1.close)((0, combinator_1.sequence)([source_1.contentline, (0, combinator_1.inits)([
|
|
4804
4820
|
// All parsers which can include closing terms.
|
|
4805
|
-
(0, combinator_1.union)([codeblock_1.segment_, mathblock_1.segment_, table_2.segment_, blockquote_1.segment, placeholder_1.segment_, (0, combinator_1.some)(source_1.contentline, closer)]), source_1.emptyline, (0, combinator_1.union)([source_1.emptyline, (0, combinator_1.some)(source_1.contentline, closer)])])]), closer), ([, fence]) => fence.length, {})
|
|
4821
|
+
(0, combinator_1.union)([codeblock_1.segment_, mathblock_1.segment_, table_2.segment_, blockquote_1.segment, placeholder_1.segment_, (0, combinator_1.some)(source_1.contentline, closer)]), source_1.emptyline, (0, combinator_1.union)([source_1.emptyline, (0, combinator_1.some)(source_1.contentline, closer)])])]), closer), ([, fence]) => fence.length, {})));
|
|
4806
4822
|
exports.figure = (0, combinator_1.block)((0, combinator_1.fallback)((0, combinator_1.rewrite)(exports.segment, (0, combinator_1.fmap)((0, combinator_1.convert)(source => source.slice(source.match(/^~+(?:\w+\s+)?/)[0].length, source.trimEnd().lastIndexOf('\n')), (0, combinator_1.sequence)([(0, combinator_1.line)((0, combinator_1.sequence)([label_1.label, (0, source_1.str)(/^(?=\s).*\n/)])), (0, combinator_1.inits)([(0, combinator_1.block)((0, combinator_1.union)([ulist_1.ulist, olist_1.olist, table_1.table, codeblock_1.codeblock, mathblock_1.mathblock, example_1.example, table_2.table, blockquote_1.blockquote, placeholder_1.placeholder, (0, combinator_1.line)(inline_1.media), (0, combinator_1.line)(inline_1.shortmedia)])), source_1.emptyline, (0, combinator_1.block)((0, visibility_1.visualize)((0, visibility_1.trimBlank)((0, combinator_1.some)(inline_1.inline))))])]), false), ([label, param, content, ...caption]) => [(0, dom_1.html)('figure', attributes(label.getAttribute('data-label'), param, content, caption), [(0, dom_1.html)('figcaption', [(0, dom_1.html)('span', {
|
|
4807
4823
|
class: 'figindex'
|
|
4808
4824
|
}), (0, dom_1.html)('span', {
|
|
@@ -5349,7 +5365,7 @@ const openers = {
|
|
|
5349
5365
|
'(': /^\(([0-9]*|[a-z]*)(?![^)\n])\)?(?:-(?!-)[0-9]*)*(?:$|\s)/
|
|
5350
5366
|
};
|
|
5351
5367
|
exports.olist = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.validate)(new RegExp([/^([0-9]+|[a-z]+|[A-Z]+)(?:-[0-9]+)*\.(?=[^\S\n]|\n[^\S\n]*\S)/.source, /^\(([0-9]+|[a-z]+)\)(?:-[0-9]+)*(?=[^\S\n]|\n[^\S\n]*\S)/.source].join('|')), exports.olist_)));
|
|
5352
|
-
exports.olist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.union)([(0, combinator_1.match)(openers['.'], (0, memoize_1.memoize)(ms => list(type(ms[1]), '.'), ms => idx(ms[1]), [])
|
|
5368
|
+
exports.olist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.union)([(0, combinator_1.match)(openers['.'], (0, memoize_1.memoize)(ms => list(type(ms[1]), '.'), ms => idx(ms[1]), [])), (0, combinator_1.match)(openers['('], (0, memoize_1.memoize)(ms => list(type(ms[1]), '('), ms => idx(ms[1]), []))])));
|
|
5353
5369
|
const list = (type, form) => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.recursion)(3 /* Recursion.listitem */, (0, combinator_1.union)([(0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(heads[form], (0, combinator_1.subsequence)([ulist_1.checkbox, (0, combinator_1.trim)((0, visibility_1.visualize)((0, util_1.lineable)((0, visibility_1.trimBlank)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline]))))))]), true)), (0, combinator_1.indent)((0, combinator_1.union)([ulist_1.ulist_, exports.olist_, ilist_1.ilist_]))]), ilist_1.ilistitem), ns => [(0, dom_1.html)('li', {
|
|
5354
5370
|
'data-index': (0, inline_1.dataindex)(ns),
|
|
5355
5371
|
'data-marker': ns.shift() || undefined
|
|
@@ -5357,10 +5373,10 @@ const list = (type, form) => (0, combinator_1.fmap)((0, combinator_1.some)((0, c
|
|
|
5357
5373
|
const heads = {
|
|
5358
5374
|
'.': (0, combinator_1.focus)(openers['.'], ({
|
|
5359
5375
|
source
|
|
5360
|
-
}) => [[source.trimEnd().split('.', 1)[0] + '.'], '']
|
|
5376
|
+
}) => [[source.trimEnd().split('.', 1)[0] + '.'], '']),
|
|
5361
5377
|
'(': (0, combinator_1.focus)(openers['('], ({
|
|
5362
5378
|
source
|
|
5363
|
-
}) => [[source.trimEnd().replace(/^\($/, '(1)').replace(/^\((\w+)$/, '($1)')], '']
|
|
5379
|
+
}) => [[source.trimEnd().replace(/^\($/, '(1)').replace(/^\((\w+)$/, '($1)')], ''])
|
|
5364
5380
|
};
|
|
5365
5381
|
function idx(value) {
|
|
5366
5382
|
switch (value) {
|
|
@@ -5533,15 +5549,15 @@ exports.cite = (0, combinator_1.line)((0, combinator_1.fmap)((0, combinator_1.va
|
|
|
5533
5549
|
source
|
|
5534
5550
|
}) => [[(0, dom_1.html)('a', {
|
|
5535
5551
|
class: 'anchor'
|
|
5536
|
-
}, source)], '']
|
|
5552
|
+
}, source)], '']), (0, combinator_1.focus)(/^>>https?:\/\/\S+(?=\s*$)/, ({
|
|
5537
5553
|
source
|
|
5538
5554
|
}) => [[(0, dom_1.html)('a', {
|
|
5539
5555
|
class: 'anchor',
|
|
5540
5556
|
href: source.slice(2).trimEnd(),
|
|
5541
5557
|
target: '_blank'
|
|
5542
|
-
}, source)], '']
|
|
5558
|
+
}, source)], '']), (0, combinator_1.focus)(/^>>.+(?=\s*$)/, ({
|
|
5543
5559
|
source
|
|
5544
|
-
}) => [[source], '']
|
|
5560
|
+
}) => [[source], ''])]))), ([quotes, node]) => [(0, dom_1.html)('span', typeof node === 'object' ? {
|
|
5545
5561
|
class: 'cite'
|
|
5546
5562
|
} : {
|
|
5547
5563
|
class: 'cite invalid',
|
|
@@ -5676,7 +5692,7 @@ exports.checkbox = (0, combinator_1.focus)(/^\[[xX ]\](?=$|\s)/, ({
|
|
|
5676
5692
|
source
|
|
5677
5693
|
}) => [[(0, dom_1.html)('span', {
|
|
5678
5694
|
class: 'checkbox'
|
|
5679
|
-
}, source[1].trimStart() ? '☑' : '☐')], '']
|
|
5695
|
+
}, source[1].trimStart() ? '☑' : '☐')], '']);
|
|
5680
5696
|
function fillFirstLine(ns) {
|
|
5681
5697
|
return ns.length === 1 && typeof ns[0] === 'object' && ['UL', 'OL'].includes(ns[0].tagName) ? (0, array_1.unshift)([(0, dom_1.html)('br')], ns) : ns;
|
|
5682
5698
|
}
|
|
@@ -6054,7 +6070,7 @@ const link_1 = __webpack_require__(3628);
|
|
|
6054
6070
|
const hashtag_1 = __webpack_require__(5764);
|
|
6055
6071
|
const source_1 = __webpack_require__(8745);
|
|
6056
6072
|
const dom_1 = __webpack_require__(394);
|
|
6057
|
-
exports.hashnum = (0, combinator_1.lazy)(() => (0, combinator_1.rewrite)((0, combinator_1.open)('#', (0, source_1.str)(new RegExp(/^[0-9]{1,9}(?![^\p{C}\p{S}\p{P}\s]|emoji)/u.source.replace(/emoji/, hashtag_1.emoji), 'u'))), (0, combinator_1.union)([(0, combinator_1.constraint)(1 /* State.autolink */, false, (0, combinator_1.state)(1 /* State.autolink */, (0, combinator_1.fmap)((0, combinator_1.convert)(source => `[${source}]{ ${source.slice(1)} }`, link_1.unsafelink, false), ([el]) => [(0, dom_1.define)(el, {
|
|
6073
|
+
exports.hashnum = (0, combinator_1.lazy)(() => (0, combinator_1.rewrite)((0, combinator_1.open)('#', (0, source_1.str)(new RegExp([/^[0-9]{1,9}(?![^\p{C}\p{S}\p{P}\s]|emoji)/u.source].join('').replace(/emoji/, hashtag_1.emoji), 'u'))), (0, combinator_1.union)([(0, combinator_1.constraint)(1 /* State.autolink */, false, (0, combinator_1.state)(1 /* State.autolink */, (0, combinator_1.fmap)((0, combinator_1.convert)(source => `[${source}]{ ${source.slice(1)} }`, link_1.unsafelink, false), ([el]) => [(0, dom_1.define)(el, {
|
|
6058
6074
|
class: 'hashnum',
|
|
6059
6075
|
href: null
|
|
6060
6076
|
})]))), ({
|
|
@@ -6161,7 +6177,7 @@ exports.code = (0, combinator_1.match)(/^(`+)(?!`)([^\n]*?[^`\n])\1(?!`)/, ([who
|
|
|
6161
6177
|
source
|
|
6162
6178
|
}) => [[(0, dom_1.html)('code', {
|
|
6163
6179
|
'data-src': whole
|
|
6164
|
-
}, format(body))], source.slice(whole.length)]);
|
|
6180
|
+
}, format(body))], source.slice(whole.length)], true);
|
|
6165
6181
|
function format(text) {
|
|
6166
6182
|
return `${text[0]}${text.at(-1)}` === ' ' && text.trimStart() ? text.slice(1, -1) : text;
|
|
6167
6183
|
}
|
|
@@ -8134,15 +8150,15 @@ function trimBlankEnd(parser) {
|
|
|
8134
8150
|
return (0, combinator_1.fmap)(parser, trimBlankNodeEnd);
|
|
8135
8151
|
}
|
|
8136
8152
|
exports.trimBlankEnd = trimBlankEnd;
|
|
8137
|
-
//export function trimBlankNode<
|
|
8153
|
+
//export function trimBlankNode<N extends HTMLElement | string>(nodes: N[]): N[] {
|
|
8138
8154
|
// return trimBlankNodeStart(trimBlankNodeEnd(nodes));
|
|
8139
8155
|
//}
|
|
8140
|
-
//function trimBlankNodeStart<
|
|
8156
|
+
//function trimBlankNodeStart<N extends HTMLElement | string>(nodes: N[]): N[] {
|
|
8141
8157
|
// for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[0], 0);) {
|
|
8142
8158
|
// if (typeof node === 'string') {
|
|
8143
8159
|
// const pos = node.trimStart().length;
|
|
8144
8160
|
// if (pos > 0) {
|
|
8145
|
-
// nodes[0] = node.slice(-pos) as
|
|
8161
|
+
// nodes[0] = node.slice(-pos) as N;
|
|
8146
8162
|
// break;
|
|
8147
8163
|
// }
|
|
8148
8164
|
// }
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@ import { Parser, exec } from '../../data/parser';
|
|
|
2
2
|
import { firstline, isBlank } from './line';
|
|
3
3
|
|
|
4
4
|
export function block<P extends Parser<unknown>>(parser: P, separation?: boolean): P;
|
|
5
|
-
export function block<
|
|
5
|
+
export function block<N>(parser: Parser<N>, separation = true): Parser<N> {
|
|
6
6
|
assert(parser);
|
|
7
7
|
return input => {
|
|
8
8
|
const { source } = input;
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { isArray } from 'spica/alias';
|
|
2
|
-
import { Parser, Input, Ctx,
|
|
2
|
+
import { Parser, Input, Ctx, Node, Context, eval, exec, check } from '../../data/parser';
|
|
3
3
|
|
|
4
4
|
//export function contract<P extends Parser<unknown>>(patterns: string | RegExp | (string | RegExp)[], parser: P, cond: (nodes: readonly Data<P>[], rest: string) => boolean): P;
|
|
5
|
-
//export function contract<
|
|
5
|
+
//export function contract<N>(patterns: string | RegExp | (string | RegExp)[], parser: Parser<N>, cond: (nodes: readonly N[], rest: string) => boolean): Parser<N> {
|
|
6
6
|
// return verify(validate(patterns, parser), cond);
|
|
7
7
|
//}
|
|
8
8
|
|
|
9
9
|
export function validate<P extends Parser<unknown>>(patterns: string | RegExp | (string | RegExp)[], parser: P): P;
|
|
10
10
|
export function validate<P extends Parser<unknown>>(patterns: string | RegExp | (string | RegExp)[], has: string, parser: P): P;
|
|
11
11
|
export function validate<P extends Parser<unknown>>(cond: ((input: Input<Context<P>>) => boolean), parser: P): P;
|
|
12
|
-
export function validate<
|
|
13
|
-
if (typeof patterns === 'function') return guard(patterns, has as Parser<
|
|
12
|
+
export function validate<N>(patterns: string | RegExp | (string | RegExp)[] | ((input: Input<Ctx>) => boolean), has: string | Parser<N>, parser?: Parser<N>): Parser<N> {
|
|
13
|
+
if (typeof patterns === 'function') return guard(patterns, has as Parser<N>);
|
|
14
14
|
if (typeof has === 'function') return validate(patterns, '', has);
|
|
15
15
|
if (!isArray(patterns)) return validate([patterns], has, parser!);
|
|
16
16
|
assert(patterns.length > 0);
|
|
@@ -38,15 +38,15 @@ export function validate<T>(patterns: string | RegExp | (string | RegExp)[] | ((
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
function guard<P extends Parser<unknown>>(f: (input: Input<Context<P>>) => boolean, parser: P): P;
|
|
41
|
-
function guard<
|
|
41
|
+
function guard<N>(f: (input: Input<Ctx>) => boolean, parser: Parser<N>): Parser<N> {
|
|
42
42
|
return input =>
|
|
43
43
|
f(input)
|
|
44
44
|
? parser(input)
|
|
45
45
|
: undefined;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
export function verify<P extends Parser<unknown>>(parser: P, cond: (nodes: readonly
|
|
49
|
-
export function verify<
|
|
48
|
+
export function verify<P extends Parser<unknown>>(parser: P, cond: (nodes: readonly Node<P>[], rest: string, context: Context<P>) => boolean): P;
|
|
49
|
+
export function verify<N>(parser: Parser<N>, cond: (nodes: readonly N[], rest: string, context: Ctx) => boolean): Parser<N> {
|
|
50
50
|
assert(parser);
|
|
51
51
|
return input => {
|
|
52
52
|
const { source, context } = input;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Parser, eval, exec, check } from '../../data/parser';
|
|
2
2
|
|
|
3
3
|
export function line<P extends Parser<unknown>>(parser: P): P;
|
|
4
|
-
export function line<
|
|
4
|
+
export function line<N>(parser: Parser<N>): Parser<N> {
|
|
5
5
|
assert(parser);
|
|
6
6
|
return ({ source, context }) => {
|
|
7
7
|
if (source === '') return;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Parser, Ctx } from '../../data/parser';
|
|
2
|
+
import { fmap } from '../monad/fmap';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export function clear<D extends Parser<unknown, C>[], C extends Ctx>(parser: Parser<unknown, C, D>): Parser<never, C, D> {
|
|
6
|
+
return fmap<never, Parser<unknown, C, D>>(parser, () => []);
|
|
7
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Parser, Ctx, Context, check } from '../../data/parser';
|
|
2
2
|
|
|
3
3
|
export function convert<P extends Parser<unknown>>(conv: (source: string, context: Context<P>) => string, parser: P, continuous: boolean, empty?: boolean): P;
|
|
4
|
-
export function convert<
|
|
4
|
+
export function convert<N>(conv: (source: string, context: Ctx) => string, parser: Parser<N>, continuous: boolean, empty = false): Parser<N> {
|
|
5
5
|
assert(parser);
|
|
6
6
|
return ({ source, context }) => {
|
|
7
7
|
if (source === '') return;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Parser, Ctx,
|
|
1
|
+
import { Parser, Ctx, Node, Context, SubParsers } from '../../data/parser';
|
|
2
2
|
import { fmap } from '../monad/fmap';
|
|
3
3
|
|
|
4
|
-
export function dup<P extends Parser<unknown[]>>(parser: Parser<
|
|
5
|
-
export function dup<
|
|
6
|
-
export function dup<
|
|
4
|
+
export function dup<P extends Parser<unknown[]>>(parser: Parser<Node<P>[number], Context<P>, SubParsers<P>>): P;
|
|
5
|
+
export function dup<N, C extends Ctx, D extends Parser<unknown, C>[]>(parser: Parser<N, C, D>): Parser<N[], C, D>;
|
|
6
|
+
export function dup<N>(parser: Parser<N>): Parser<N[]> {
|
|
7
7
|
return fmap(parser, nodes => [nodes]);
|
|
8
8
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Parser,
|
|
1
|
+
import { Parser, Node, Context } from '../../data/parser';
|
|
2
2
|
import { union } from '../../data/parser/union';
|
|
3
3
|
|
|
4
|
-
export function fallback<P extends Parser<unknown>>(parser: P, otherwise: Parser<
|
|
5
|
-
export function fallback<
|
|
4
|
+
export function fallback<P extends Parser<unknown>>(parser: P, otherwise: Parser<Node<P>, Context<P>>): P;
|
|
5
|
+
export function fallback<N>(parser: Parser<N>, otherwise: Parser<N>): Parser<N> {
|
|
6
6
|
return union([parser, otherwise]);
|
|
7
7
|
}
|
|
@@ -9,7 +9,7 @@ import { memoize } from 'spica/memoize';
|
|
|
9
9
|
|
|
10
10
|
export function indent<P extends Parser<unknown>>(parser: P, separation?: boolean): P;
|
|
11
11
|
export function indent<P extends Parser<unknown>>(opener: RegExp, parser: P, separation?: boolean): P;
|
|
12
|
-
export function indent<
|
|
12
|
+
export function indent<N>(opener: RegExp | Parser<N>, parser?: Parser<N> | boolean, separation = false): Parser<N> {
|
|
13
13
|
if (typeof opener === 'function') return indent(/^([ \t])\1*/, opener, parser as boolean);
|
|
14
14
|
assert(parser);
|
|
15
15
|
return bind(block(match(
|
|
@@ -17,9 +17,9 @@ export function indent<T>(opener: RegExp | Parser<T>, parser?: Parser<T> | boole
|
|
|
17
17
|
memoize(
|
|
18
18
|
([indent]) =>
|
|
19
19
|
some(line(open(indent, ({ source }) => [[source], '']))),
|
|
20
|
-
([indent]) => indent.length * 2 + +(indent[0] === ' '), {})
|
|
20
|
+
([indent]) => indent.length * 2 + +(indent[0] === ' '), {})), separation),
|
|
21
21
|
(lines, rest, context) => {
|
|
22
|
-
assert(parser = parser as Parser<
|
|
22
|
+
assert(parser = parser as Parser<N>);
|
|
23
23
|
// 影響する使用はないはず
|
|
24
24
|
//const { backtracks } = context;
|
|
25
25
|
//context.backtracks = {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Parser } from '../../data/parser';
|
|
2
2
|
|
|
3
3
|
export function lazy<P extends Parser<unknown>>(builder: () => P): P;
|
|
4
|
-
export function lazy<
|
|
5
|
-
let parser: Parser<
|
|
4
|
+
export function lazy<N>(builder: () => Parser<N>): Parser<N> {
|
|
5
|
+
let parser: Parser<N>;
|
|
6
6
|
return input =>
|
|
7
7
|
parser !== undefined
|
|
8
8
|
? parser(input)
|
|
@@ -2,7 +2,7 @@ import { Parser, exec, check } from '../../data/parser';
|
|
|
2
2
|
import { consume } from '../../../combinator';
|
|
3
3
|
|
|
4
4
|
export function match<P extends Parser<unknown>>(pattern: RegExp, f: (matched: RegExpMatchArray) => P, cost?: boolean): P;
|
|
5
|
-
export function match<
|
|
5
|
+
export function match<N>(pattern: RegExp, f: (matched: RegExpMatchArray) => Parser<N>, cost = false): Parser<N> {
|
|
6
6
|
assert(!pattern.flags.match(/[gmy]/) && pattern.source.startsWith('^'));
|
|
7
7
|
return input => {
|
|
8
8
|
const { source, context } = input;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Parser, Input, Result,
|
|
1
|
+
import { Parser, Input, Result, Node, Context } from '../../data/parser';
|
|
2
2
|
|
|
3
|
-
export function recover<P extends Parser<unknown>>(parser: P, fallback: (input: Input<Context<P>>, reason: unknown) => Result<
|
|
4
|
-
export function recover<
|
|
3
|
+
export function recover<P extends Parser<unknown>>(parser: P, fallback: (input: Input<Context<P>>, reason: unknown) => Result<Node<P>>): P;
|
|
4
|
+
export function recover<N>(parser: Parser<N>, fallback: (input: Input, reason: unknown) => Result<N>): Parser<N> {
|
|
5
5
|
return input => {
|
|
6
6
|
try {
|
|
7
7
|
return parser(input);
|
|
@@ -2,7 +2,7 @@ import { Parser } from '../../data/parser';
|
|
|
2
2
|
import { fmap } from '../monad/fmap';
|
|
3
3
|
|
|
4
4
|
export function reverse<P extends Parser<unknown>>(parser: P): P;
|
|
5
|
-
export function reverse<
|
|
5
|
+
export function reverse<N>(parser: Parser<N>): Parser<N> {
|
|
6
6
|
return fmap(parser, nodes => nodes.reverse());
|
|
7
7
|
}
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@ import { Parser, Context, eval, exec, check } from '../../data/parser';
|
|
|
2
2
|
import { consume } from '../../../combinator';
|
|
3
3
|
|
|
4
4
|
export function focus<P extends Parser<unknown>>(scope: string | RegExp, parser: P, cost?: boolean): P;
|
|
5
|
-
export function focus<
|
|
5
|
+
export function focus<N>(scope: string | RegExp, parser: Parser<N>, cost = true): Parser<N> {
|
|
6
6
|
assert(scope instanceof RegExp ? !scope.flags.match(/[gmy]/) && scope.source.startsWith('^') : scope);
|
|
7
7
|
assert(parser);
|
|
8
8
|
const match: (source: string) => string = typeof scope === 'string'
|
|
@@ -29,9 +29,9 @@ export function focus<T>(scope: string | RegExp, parser: Parser<T>, cost = true)
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
//export function rewrite<
|
|
32
|
+
//export function rewrite<N, C extends Ctx, D extends Parser<unknown, C>[]>(scope: Parser<unknown, C, D>, parser: Parser<N, C, never>): Parser<N, C, D>;
|
|
33
33
|
export function rewrite<P extends Parser<unknown>>(scope: Parser<unknown, Context<P>>, parser: P): P;
|
|
34
|
-
export function rewrite<
|
|
34
|
+
export function rewrite<N>(scope: Parser<unknown>, parser: Parser<N>): Parser<N> {
|
|
35
35
|
assert(scope);
|
|
36
36
|
assert(parser);
|
|
37
37
|
return input => {
|