securemark 0.280.2 → 0.280.4
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 +8 -0
- package/dist/index.js +46 -42
- package/markdown.d.ts +22 -22
- package/package.json +1 -1
- package/src/combinator/control/constraint/block.ts +0 -2
- package/src/combinator/control/constraint/line.ts +0 -2
- package/src/combinator/control/manipulation/convert.ts +7 -2
- package/src/combinator/control/manipulation/fence.ts +2 -2
- package/src/combinator/control/manipulation/indent.ts +4 -2
- package/src/combinator/control/manipulation/scope.ts +8 -4
- package/src/combinator/data/parser/context/memo.ts +7 -3
- package/src/combinator/data/parser/context.ts +5 -7
- package/src/combinator/data/parser/some.ts +1 -1
- package/src/parser/block.ts +5 -2
- package/src/parser/context.ts +15 -13
- package/src/parser/inline/annotation.ts +1 -1
- package/src/parser/inline/autolink.ts +1 -1
- package/src/parser/inline/htmlentity.ts +1 -1
- package/src/parser/inline/media.ts +7 -4
- package/src/parser/inline/template.ts +6 -3
- package/src/parser/inline.ts +5 -5
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! securemark v0.280.
|
|
1
|
+
/*! securemark v0.280.4 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"));
|
|
@@ -2682,7 +2682,6 @@ Object.defineProperty(exports, "__esModule", ({
|
|
|
2682
2682
|
}));
|
|
2683
2683
|
exports.block = void 0;
|
|
2684
2684
|
const parser_1 = __webpack_require__(6728);
|
|
2685
|
-
const memo_1 = __webpack_require__(1090);
|
|
2686
2685
|
const line_1 = __webpack_require__(9315);
|
|
2687
2686
|
function block(parser, separation = true) {
|
|
2688
2687
|
return ({
|
|
@@ -2690,7 +2689,6 @@ function block(parser, separation = true) {
|
|
|
2690
2689
|
context
|
|
2691
2690
|
}) => {
|
|
2692
2691
|
if (source === '') return;
|
|
2693
|
-
context.memo ??= new memo_1.Memo();
|
|
2694
2692
|
const result = parser({
|
|
2695
2693
|
source,
|
|
2696
2694
|
context
|
|
@@ -2767,14 +2765,12 @@ Object.defineProperty(exports, "__esModule", ({
|
|
|
2767
2765
|
}));
|
|
2768
2766
|
exports.isBlank = exports.firstline = exports.line = void 0;
|
|
2769
2767
|
const parser_1 = __webpack_require__(6728);
|
|
2770
|
-
const memo_1 = __webpack_require__(1090);
|
|
2771
2768
|
function line(parser) {
|
|
2772
2769
|
return ({
|
|
2773
2770
|
source,
|
|
2774
2771
|
context
|
|
2775
2772
|
}) => {
|
|
2776
2773
|
if (source === '') return;
|
|
2777
|
-
context.memo ??= new memo_1.Memo();
|
|
2778
2774
|
const line = firstline(source);
|
|
2779
2775
|
context.offset ??= 0;
|
|
2780
2776
|
context.offset += source.length - line.length;
|
|
@@ -2818,6 +2814,7 @@ Object.defineProperty(exports, "__esModule", ({
|
|
|
2818
2814
|
}));
|
|
2819
2815
|
exports.convert = void 0;
|
|
2820
2816
|
const parser_1 = __webpack_require__(6728);
|
|
2817
|
+
const alias_1 = __webpack_require__(5406);
|
|
2821
2818
|
function convert(conv, parser, empty = false) {
|
|
2822
2819
|
return ({
|
|
2823
2820
|
source,
|
|
@@ -2826,13 +2823,14 @@ function convert(conv, parser, empty = false) {
|
|
|
2826
2823
|
if (source === '') return;
|
|
2827
2824
|
const src = conv(source, context);
|
|
2828
2825
|
if (src === '') return empty ? [[], ''] : undefined;
|
|
2826
|
+
const offset = (0, alias_1.max)(source.length - src.length, 0);
|
|
2829
2827
|
context.offset ??= 0;
|
|
2830
|
-
context.offset +=
|
|
2828
|
+
context.offset += offset;
|
|
2831
2829
|
const result = parser({
|
|
2832
2830
|
source: src,
|
|
2833
2831
|
context
|
|
2834
2832
|
});
|
|
2835
|
-
context.offset -=
|
|
2833
|
+
context.offset -= offset;
|
|
2836
2834
|
return result;
|
|
2837
2835
|
};
|
|
2838
2836
|
}
|
|
@@ -2927,7 +2925,7 @@ function fence(opener, limit, separation = true) {
|
|
|
2927
2925
|
}
|
|
2928
2926
|
rest = rest.slice(line.length);
|
|
2929
2927
|
}
|
|
2930
|
-
return [(0, array_1.
|
|
2928
|
+
return [(0, array_1.push)([block, overflow, closer], matches), rest];
|
|
2931
2929
|
};
|
|
2932
2930
|
}
|
|
2933
2931
|
exports.fence = fence;
|
|
@@ -2957,13 +2955,14 @@ function indent(opener, parser, separation = false) {
|
|
|
2957
2955
|
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, ({
|
|
2958
2956
|
source
|
|
2959
2957
|
}) => [[source], '']))), ([indent]) => indent.length * 2 + +(indent[0] === ' '), {})), separation), (lines, rest, context) => {
|
|
2958
|
+
const offset = rest.length;
|
|
2960
2959
|
context.offset ??= 0;
|
|
2961
|
-
context.offset +=
|
|
2960
|
+
context.offset += offset;
|
|
2962
2961
|
const result = parser({
|
|
2963
2962
|
source: trimBlockEnd(lines.join('')),
|
|
2964
2963
|
context
|
|
2965
2964
|
});
|
|
2966
|
-
context.offset -=
|
|
2965
|
+
context.offset -= offset;
|
|
2967
2966
|
return result && (0, parser_1.exec)(result) === '' ? [(0, parser_1.eval)(result), rest] : undefined;
|
|
2968
2967
|
});
|
|
2969
2968
|
}
|
|
@@ -3084,13 +3083,14 @@ function focus(scope, parser) {
|
|
|
3084
3083
|
if (source === '') return;
|
|
3085
3084
|
const src = match(source);
|
|
3086
3085
|
if (src === '') return;
|
|
3086
|
+
const offset = source.length - src.length;
|
|
3087
3087
|
context.offset ??= 0;
|
|
3088
|
-
context.offset +=
|
|
3088
|
+
context.offset += offset;
|
|
3089
3089
|
const result = parser({
|
|
3090
3090
|
source: src,
|
|
3091
3091
|
context
|
|
3092
3092
|
});
|
|
3093
|
-
context.offset -=
|
|
3093
|
+
context.offset -= offset;
|
|
3094
3094
|
if (result === undefined) return;
|
|
3095
3095
|
return (0, parser_1.exec)(result).length < src.length ? [(0, parser_1.eval)(result), (0, parser_1.exec)(result) + source.slice(src.length)] : undefined;
|
|
3096
3096
|
};
|
|
@@ -3111,13 +3111,14 @@ function rewrite(scope, parser) {
|
|
|
3111
3111
|
context.memo = memo;
|
|
3112
3112
|
if (res1 === undefined || (0, parser_1.exec)(res1).length >= source.length) return;
|
|
3113
3113
|
const src = source.slice(0, source.length - (0, parser_1.exec)(res1).length);
|
|
3114
|
+
const offset = source.length - src.length;
|
|
3114
3115
|
context.offset ??= 0;
|
|
3115
|
-
context.offset +=
|
|
3116
|
+
context.offset += offset;
|
|
3116
3117
|
const res2 = parser({
|
|
3117
3118
|
source: src,
|
|
3118
3119
|
context
|
|
3119
3120
|
});
|
|
3120
|
-
context.offset -=
|
|
3121
|
+
context.offset -= offset;
|
|
3121
3122
|
if (res2 === undefined) return;
|
|
3122
3123
|
return (0, parser_1.exec)(res2).length < src.length ? [(0, parser_1.eval)(res2), (0, parser_1.exec)(res2) + (0, parser_1.exec)(res1)] : undefined;
|
|
3123
3124
|
};
|
|
@@ -3384,16 +3385,15 @@ function syntax(syntax, prec, state, parser) {
|
|
|
3384
3385
|
const position = source.length + context.offset;
|
|
3385
3386
|
const stateOuter = context.state ?? 0;
|
|
3386
3387
|
const stateInner = context.state = stateOuter | state;
|
|
3387
|
-
const cache = syntax
|
|
3388
|
+
const cache = syntax & memo.targets && stateInner && memo.get(position, syntax, stateInner);
|
|
3388
3389
|
const result = cache ? cache.length === 0 ? undefined : [cache[0], source.slice(cache[1])] : parser({
|
|
3389
3390
|
source,
|
|
3390
3391
|
context
|
|
3391
3392
|
});
|
|
3392
|
-
if (
|
|
3393
|
-
|
|
3394
|
-
}
|
|
3395
|
-
|
|
3396
|
-
memo.resize(position + 2);
|
|
3393
|
+
if (stateOuter && !cache && syntax & memo.targets) {
|
|
3394
|
+
memo.set(position, syntax, stateInner, (0, parser_1.eval)(result), source.length - (0, parser_1.exec)(result, '').length);
|
|
3395
|
+
} else if (!stateOuter && result && memo.length >= position + memo.margin) {
|
|
3396
|
+
memo.resize(position + memo.margin);
|
|
3397
3397
|
}
|
|
3398
3398
|
context.state = stateOuter;
|
|
3399
3399
|
return result;
|
|
@@ -3626,20 +3626,23 @@ Object.defineProperty(exports, "__esModule", ({
|
|
|
3626
3626
|
}));
|
|
3627
3627
|
exports.Memo = void 0;
|
|
3628
3628
|
class Memo {
|
|
3629
|
-
constructor(targets = ~0) {
|
|
3629
|
+
constructor(targets = ~0, margin = 0) {
|
|
3630
3630
|
this.targets = targets;
|
|
3631
|
+
this.margin = margin;
|
|
3631
3632
|
this.memory = [];
|
|
3632
|
-
this.
|
|
3633
|
+
this.count = 0;
|
|
3633
3634
|
}
|
|
3634
3635
|
get length() {
|
|
3635
3636
|
return this.memory.length;
|
|
3636
3637
|
}
|
|
3637
3638
|
get(position, syntax, state) {
|
|
3639
|
+
if (this.count === 0) return;
|
|
3638
3640
|
//console.log('get', position, syntax, state, this.memory[position - 1]?.[syntax]?.[state]);
|
|
3639
3641
|
const cache = this.memory[position - 1]?.[syntax]?.[state];
|
|
3640
3642
|
return cache?.length === 2 ? [cache[0].slice(), cache[1]] : cache;
|
|
3641
3643
|
}
|
|
3642
3644
|
set(position, syntax, state, nodes, offset) {
|
|
3645
|
+
this.count += +!this.memory[position - 1];
|
|
3643
3646
|
const record = this.memory[position - 1] ??= {};
|
|
3644
3647
|
(record[syntax] ??= {})[state] = nodes ? [nodes.slice(), offset] : [];
|
|
3645
3648
|
//console.log('set', position, syntax, state, record[syntax]?.[state]);
|
|
@@ -3647,14 +3650,15 @@ class Memo {
|
|
|
3647
3650
|
|
|
3648
3651
|
resize(position) {
|
|
3649
3652
|
const memory = this.memory;
|
|
3650
|
-
for (let
|
|
3651
|
-
memory.pop();
|
|
3653
|
+
for (let i = memory.length; i > position; --i) {
|
|
3654
|
+
this.count -= +memory.pop();
|
|
3652
3655
|
}
|
|
3653
3656
|
//console.log('resize', position + 1);
|
|
3654
3657
|
}
|
|
3655
3658
|
|
|
3656
3659
|
clear() {
|
|
3657
3660
|
this.memory = [];
|
|
3661
|
+
this.count = 0;
|
|
3658
3662
|
}
|
|
3659
3663
|
}
|
|
3660
3664
|
exports.Memo = Memo;
|
|
@@ -3780,7 +3784,7 @@ function some(parser, end, delimiters = [], limit = -1) {
|
|
|
3780
3784
|
context
|
|
3781
3785
|
});
|
|
3782
3786
|
if (result === undefined) break;
|
|
3783
|
-
nodes = nodes ? nodes.length < (0, parser_1.eval)(result).length ? (0, array_1.unshift)(nodes, (0, parser_1.eval)(result)) : (0, array_1.push)(nodes, (0, parser_1.eval)(result)) : (0, parser_1.eval)(result);
|
|
3787
|
+
nodes = nodes ? nodes.length < (0, parser_1.eval)(result).length / 8 ? (0, array_1.unshift)(nodes, (0, parser_1.eval)(result)) : (0, array_1.push)(nodes, (0, parser_1.eval)(result)) : (0, parser_1.eval)(result);
|
|
3784
3788
|
rest = (0, parser_1.exec)(result);
|
|
3785
3789
|
if (limit >= 0 && source.length - rest.length > limit) break;
|
|
3786
3790
|
}
|
|
@@ -4376,7 +4380,7 @@ exports.block = (0, combinator_1.creation)(0, false, (0, combinator_1.reset)({
|
|
|
4376
4380
|
clock: 20000,
|
|
4377
4381
|
recursion: 20 + 1
|
|
4378
4382
|
},
|
|
4379
|
-
memo: new memo_1.Memo(
|
|
4383
|
+
memo: new memo_1.Memo(508 /* Syntax.targets */, 2)
|
|
4380
4384
|
}, error((0, combinator_1.union)([source_1.emptyline, pagebreak_1.pagebreak, heading_1.heading, ulist_1.ulist, olist_1.olist, ilist_1.ilist, dlist_1.dlist, table_1.table, codeblock_1.codeblock, mathblock_1.mathblock, extension_1.extension, sidefence_1.sidefence, blockquote_1.blockquote, mediablock_1.mediablock, reply_1.reply, paragraph_1.paragraph]))));
|
|
4381
4385
|
function error(parser) {
|
|
4382
4386
|
return (0, combinator_1.recover)((0, combinator_1.fallback)((0, combinator_1.open)('\x07', ({
|
|
@@ -5770,7 +5774,6 @@ const annotation_1 = __webpack_require__(2736);
|
|
|
5770
5774
|
const reference_1 = __webpack_require__(3555);
|
|
5771
5775
|
const template_1 = __webpack_require__(4695);
|
|
5772
5776
|
const remark_1 = __webpack_require__(3217);
|
|
5773
|
-
const math_1 = __webpack_require__(8946);
|
|
5774
5777
|
const extension_1 = __webpack_require__(8053);
|
|
5775
5778
|
const ruby_1 = __webpack_require__(6705);
|
|
5776
5779
|
const link_1 = __webpack_require__(9628);
|
|
@@ -5779,14 +5782,15 @@ const insertion_1 = __webpack_require__(2945);
|
|
|
5779
5782
|
const deletion_1 = __webpack_require__(7501);
|
|
5780
5783
|
const mark_1 = __webpack_require__(2480);
|
|
5781
5784
|
const emstrong_1 = __webpack_require__(6132);
|
|
5782
|
-
const emphasis_1 = __webpack_require__(3867);
|
|
5783
5785
|
const strong_1 = __webpack_require__(6578);
|
|
5786
|
+
const emphasis_1 = __webpack_require__(3867);
|
|
5787
|
+
const math_1 = __webpack_require__(8946);
|
|
5784
5788
|
const code_1 = __webpack_require__(5771);
|
|
5785
5789
|
const htmlentity_1 = __webpack_require__(1562);
|
|
5786
5790
|
const autolink_1 = __webpack_require__(6051);
|
|
5787
5791
|
const bracket_1 = __webpack_require__(5196);
|
|
5788
5792
|
const source_1 = __webpack_require__(6743);
|
|
5789
|
-
exports.inline = (0, combinator_1.lazy)(() => (0, combinator_1.union)([annotation_1.annotation, reference_1.reference, template_1.template, remark_1.remark,
|
|
5793
|
+
exports.inline = (0, combinator_1.lazy)(() => (0, combinator_1.union)([annotation_1.annotation, reference_1.reference, template_1.template, remark_1.remark, extension_1.extension, ruby_1.ruby, link_1.textlink, html_1.html, insertion_1.insertion, deletion_1.deletion, mark_1.mark, emstrong_1.emstrong, strong_1.strong, emphasis_1.emphasis, math_1.math, code_1.code, htmlentity_1.htmlentity, autolink_1.autolink, bracket_1.bracket, source_1.text]));
|
|
5790
5794
|
var indexee_1 = __webpack_require__(1269);
|
|
5791
5795
|
Object.defineProperty(exports, "indexee", ({
|
|
5792
5796
|
enumerable: true,
|
|
@@ -5839,7 +5843,7 @@ const combinator_1 = __webpack_require__(2087);
|
|
|
5839
5843
|
const inline_1 = __webpack_require__(1160);
|
|
5840
5844
|
const visibility_1 = __webpack_require__(7618);
|
|
5841
5845
|
const dom_1 = __webpack_require__(3252);
|
|
5842
|
-
exports.annotation = (0, combinator_1.lazy)(() => (0, combinator_1.creation)((0, combinator_1.surround)('((', (0, combinator_1.constraint)(256 /* State.annotation */, false, (0, combinator_1.syntax)(
|
|
5846
|
+
exports.annotation = (0, combinator_1.lazy)(() => (0, combinator_1.creation)((0, combinator_1.surround)('((', (0, combinator_1.constraint)(256 /* State.annotation */, false, (0, combinator_1.syntax)(256 /* Syntax.annotation */, 6, 256 /* State.annotation */ | 8 /* State.media */, (0, visibility_1.trimBlankStart)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), ')', [[/^\\?\n/, 9], [')', 2], ['))', 6]])))), '))', false, ([, ns], rest) => [[(0, dom_1.html)('sup', {
|
|
5843
5847
|
class: 'annotation'
|
|
5844
5848
|
}, [(0, dom_1.html)('span', (0, visibility_1.trimNodeEnd)((0, dom_1.defrag)(ns)))])], rest])));
|
|
5845
5849
|
|
|
@@ -5875,7 +5879,7 @@ exports.autolink = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(/^(?:
|
|
|
5875
5879
|
// Escape unmatched hashtag-like strings.
|
|
5876
5880
|
(0, source_1.str)(new RegExp(/^#+(?:[^\p{C}\p{S}\p{P}\s]|emoji|['_])*/u.source.replace('emoji', hashtag_1.emoji), 'u')),
|
|
5877
5881
|
// Escape invalid leading characters.
|
|
5878
|
-
(0, source_1.str)(/^[0-
|
|
5882
|
+
(0, source_1.str)(/^[0-9a-z](?=>)/iu), anchor_1.anchor])), ns => ns.length === 1 ? ns : [(0, util_1.stringify)(ns)])])))));
|
|
5879
5883
|
|
|
5880
5884
|
/***/ }),
|
|
5881
5885
|
|
|
@@ -6058,11 +6062,11 @@ const source_1 = __webpack_require__(6743);
|
|
|
6058
6062
|
const array_1 = __webpack_require__(8112);
|
|
6059
6063
|
const dom_1 = __webpack_require__(3252);
|
|
6060
6064
|
const index = /^[0-9A-Za-z]+(?:(?:[.-]|, )[0-9A-Za-z]+)*/;
|
|
6061
|
-
exports.bracket = (0, combinator_1.lazy)(() => (0, combinator_1.union)([(0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.creation)((0, combinator_1.syntax)(0 /* Syntax.none */, 2, 0 /* State.none */, (0, source_1.str)(index))), (0, source_1.str)(')')), (0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.creation)((0, combinator_1.syntax)(
|
|
6065
|
+
exports.bracket = (0, combinator_1.lazy)(() => (0, combinator_1.union)([(0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.creation)((0, combinator_1.syntax)(0 /* Syntax.none */, 2, 0 /* State.none */, (0, source_1.str)(index))), (0, source_1.str)(')')), (0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.creation)((0, combinator_1.syntax)(4 /* Syntax.bracket */, 2, 0 /* State.none */, (0, combinator_1.some)(inline_1.inline, ')', [[/^\\?\n/, 3], [')', 2]]))), (0, source_1.str)(')'), true, ([as, bs = [], cs], rest) => [[(0, dom_1.html)('span', {
|
|
6062
6066
|
class: 'paren'
|
|
6063
|
-
}, (0, dom_1.defrag)((0, array_1.push)((0, array_1.unshift)(as, bs), cs)))], rest], ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.creation)((0, combinator_1.syntax)(0 /* Syntax.none */, 2, 0 /* State.none */, (0, source_1.str)(new RegExp(index.source.replace(', ', '[,、]').replace(/[09AZaz.]|\-(?!\w)/g, c => c.trimStart() && String.fromCharCode(c.charCodeAt(0) + 0xFEE0)))))), (0, source_1.str)(')')), (0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.creation)((0, combinator_1.syntax)(
|
|
6067
|
+
}, (0, dom_1.defrag)((0, array_1.push)((0, array_1.unshift)(as, bs), cs)))], rest], ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.creation)((0, combinator_1.syntax)(0 /* Syntax.none */, 2, 0 /* State.none */, (0, source_1.str)(new RegExp(index.source.replace(', ', '[,、]').replace(/[09AZaz.]|\-(?!\w)/g, c => c.trimStart() && String.fromCharCode(c.charCodeAt(0) + 0xFEE0)))))), (0, source_1.str)(')')), (0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.creation)((0, combinator_1.syntax)(4 /* Syntax.bracket */, 2, 0 /* State.none */, (0, combinator_1.some)(inline_1.inline, ')', [[/^\\?\n/, 3], [')', 2]]))), (0, source_1.str)(')'), true, ([as, bs = [], cs], rest) => [[(0, dom_1.html)('span', {
|
|
6064
6068
|
class: 'paren'
|
|
6065
|
-
}, (0, dom_1.defrag)((0, array_1.push)((0, array_1.unshift)(as, bs), cs)))], rest], ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('['), (0, combinator_1.creation)((0, combinator_1.syntax)(
|
|
6069
|
+
}, (0, dom_1.defrag)((0, array_1.push)((0, array_1.unshift)(as, bs), cs)))], rest], ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('['), (0, combinator_1.creation)((0, combinator_1.syntax)(4 /* Syntax.bracket */, 2, 0 /* State.none */, (0, combinator_1.some)(inline_1.inline, ']', [[/^\\?\n/, 3], [']', 2]]))), (0, source_1.str)(']'), true, undefined, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('['), (0, combinator_1.creation)((0, combinator_1.syntax)(4 /* Syntax.bracket */, 2, 0 /* State.none */, (0, combinator_1.some)(inline_1.inline, ']', [[/^\\?\n/, 3], [']', 2]]))), (0, source_1.str)(']'), true, undefined, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('{'), (0, combinator_1.creation)((0, combinator_1.syntax)(4 /* Syntax.bracket */, 2, 0 /* State.none */, (0, combinator_1.some)(inline_1.inline, '}', [[/^\\?\n/, 3], ['}', 2]]))), (0, source_1.str)('}'), true, undefined, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('{'), (0, combinator_1.creation)((0, combinator_1.syntax)(4 /* Syntax.bracket */, 2, 0 /* State.none */, (0, combinator_1.some)(inline_1.inline, '}', [[/^\\?\n/, 3], ['}', 2]]))), (0, source_1.str)('}'), true, undefined, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('"'), (0, combinator_1.creation)((0, combinator_1.syntax)(0 /* Syntax.none */, 3, 0 /* State.none */, (0, combinator_1.some)(inline_1.inline, '"', [[/^\\?\n/, 4], ['"', 3]]))), (0, source_1.str)('"'), true, undefined, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('“'), (0, combinator_1.creation)((0, combinator_1.syntax)(0 /* Syntax.none */, 3, 0 /* State.none */, (0, combinator_1.some)(inline_1.inline, '”', [[/^\\?\n/, 4], ['”', 3]]))), (0, source_1.str)('”'), true, undefined, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('‘'), (0, combinator_1.creation)((0, combinator_1.syntax)(0 /* Syntax.none */, 3, 0 /* State.none */, (0, combinator_1.some)(inline_1.inline, '’', [[/^\\?\n/, 4], ['’', 3]]))), (0, source_1.str)('’'), true, undefined, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('「'), (0, combinator_1.creation)((0, combinator_1.syntax)(0 /* Syntax.none */, 3, 0 /* State.none */, (0, combinator_1.some)(inline_1.inline, '」', [[/^\\?\n/, 4], ['」', 3]]))), (0, source_1.str)('」'), true, undefined, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('『'), (0, combinator_1.creation)((0, combinator_1.syntax)(0 /* Syntax.none */, 3, 0 /* State.none */, (0, combinator_1.some)(inline_1.inline, '』', [[/^\\?\n/, 4], ['』', 3]]))), (0, source_1.str)('』'), true, undefined, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest])]));
|
|
6066
6070
|
|
|
6067
6071
|
/***/ }),
|
|
6068
6072
|
|
|
@@ -6204,7 +6208,7 @@ const indexee_1 = __webpack_require__(1269);
|
|
|
6204
6208
|
const source_1 = __webpack_require__(6743);
|
|
6205
6209
|
const visibility_1 = __webpack_require__(7618);
|
|
6206
6210
|
const dom_1 = __webpack_require__(3252);
|
|
6207
|
-
exports.index = (0, combinator_1.lazy)(() => (0, combinator_1.validate)('[#', (0, combinator_1.creation)((0, combinator_1.fmap)((0, indexee_1.indexee)((0, combinator_1.surround)('[#', (0, combinator_1.constraint)(64 /* State.index */, false, (0, combinator_1.syntax)(
|
|
6211
|
+
exports.index = (0, combinator_1.lazy)(() => (0, combinator_1.validate)('[#', (0, combinator_1.creation)((0, combinator_1.fmap)((0, indexee_1.indexee)((0, combinator_1.surround)('[#', (0, combinator_1.constraint)(64 /* State.index */, false, (0, combinator_1.syntax)(64 /* Syntax.index */, 2, 502 /* State.linkers */ | 8 /* State.media */, (0, visibility_1.startTight)((0, combinator_1.some)((0, combinator_1.inits)([inline_1.inline, exports.signature]), ']', [[/^\\?\n/, 9], [']', 2]])))), ']', false, ([, ns], rest) => [[(0, dom_1.html)('a', (0, visibility_1.trimNodeEnd)((0, dom_1.defrag)(ns)))], rest])), ([el]) => [(0, dom_1.define)(el, {
|
|
6208
6212
|
id: el.id ? null : undefined,
|
|
6209
6213
|
class: 'index',
|
|
6210
6214
|
href: el.id ? `#${el.id}` : undefined
|
|
@@ -6406,7 +6410,7 @@ const array_1 = __webpack_require__(8112);
|
|
|
6406
6410
|
const dom_1 = __webpack_require__(3252);
|
|
6407
6411
|
// Don't use the symbols already used: !#$%@&*+~=|
|
|
6408
6412
|
// All syntax surrounded by square brackets shouldn't contain line breaks.
|
|
6409
|
-
exports.placeholder = (0, combinator_1.lazy)(() => (0, combinator_1.validate)('[', (0, combinator_1.creation)((0, combinator_1.surround)((0, source_1.str)(/^\[[:^|]/), (0, combinator_1.syntax)(
|
|
6413
|
+
exports.placeholder = (0, combinator_1.lazy)(() => (0, combinator_1.validate)('[', (0, combinator_1.creation)((0, combinator_1.surround)((0, source_1.str)(/^\[[:^|]/), (0, combinator_1.syntax)(32 /* Syntax.placeholder */, 2, 0 /* State.none */, (0, visibility_1.startTight)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), ']', [[']', 2]]))), (0, source_1.str)(']'), false, ([, bs], rest) => [[(0, dom_1.html)('span', {
|
|
6410
6414
|
class: 'invalid',
|
|
6411
6415
|
'data-invalid-syntax': 'extension',
|
|
6412
6416
|
'data-invalid-type': 'syntax',
|
|
@@ -6517,7 +6521,7 @@ const parse = (0, memoize_1.reduce)((el => entity => {
|
|
|
6517
6521
|
el.innerHTML = entity;
|
|
6518
6522
|
const text = el.textContent;
|
|
6519
6523
|
return entity === text ? undefined : text;
|
|
6520
|
-
})((0, dom_1.html)('
|
|
6524
|
+
})((0, dom_1.html)('span')));
|
|
6521
6525
|
|
|
6522
6526
|
/***/ }),
|
|
6523
6527
|
|
|
@@ -6564,11 +6568,11 @@ const optspec = {
|
|
|
6564
6568
|
};
|
|
6565
6569
|
Object.setPrototypeOf(optspec, null);
|
|
6566
6570
|
exports.link = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['[', '{'], (0, combinator_1.union)([exports.medialink, exports.textlink])));
|
|
6567
|
-
exports.textlink = (0, combinator_1.lazy)(() => (0, combinator_1.creation)(10, (0, combinator_1.constraint)(16 /* State.link */, false, (0, combinator_1.syntax)(
|
|
6571
|
+
exports.textlink = (0, combinator_1.lazy)(() => (0, combinator_1.creation)(10, (0, combinator_1.constraint)(16 /* State.link */, false, (0, combinator_1.syntax)(8 /* Syntax.link */, 2, 502 /* State.linkers */ | 8 /* State.media */, (0, combinator_1.bind)((0, combinator_1.reverse)((0, combinator_1.tails)([(0, combinator_1.dup)((0, combinator_1.surround)('[', (0, visibility_1.trimBlankStart)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), ']', [[/^\\?\n/, 9], [']', 2]])), ']', true)), (0, combinator_1.dup)((0, combinator_1.surround)(/^{(?![{}])/, (0, combinator_1.inits)([exports.uri, (0, combinator_1.some)(exports.option)]), /^[^\S\n]*}/))])), ([params, content = []], rest, context) => {
|
|
6568
6572
|
if (content.length !== 0 && (0, visibility_1.trimNodeEnd)(content = (0, dom_1.defrag)(content)).length === 0) return;
|
|
6569
6573
|
return [[parse(content, params, context)], rest];
|
|
6570
6574
|
})))));
|
|
6571
|
-
exports.medialink = (0, combinator_1.lazy)(() => (0, combinator_1.creation)(10, (0, combinator_1.constraint)(16 /* State.link */ | 8 /* State.media */, false, (0, combinator_1.syntax)(
|
|
6575
|
+
exports.medialink = (0, combinator_1.lazy)(() => (0, combinator_1.creation)(10, (0, combinator_1.constraint)(16 /* State.link */ | 8 /* State.media */, false, (0, combinator_1.syntax)(8 /* Syntax.link */, 2, 502 /* State.linkers */, (0, combinator_1.bind)((0, combinator_1.reverse)((0, combinator_1.sequence)([(0, combinator_1.dup)((0, combinator_1.surround)('[', (0, combinator_1.union)([inline_1.media, inline_1.shortmedia]), ']')), (0, combinator_1.dup)((0, combinator_1.surround)(/^{(?![{}])/, (0, combinator_1.inits)([exports.uri, (0, combinator_1.some)(exports.option)]), /^[^\S\n]*}/))])), ([params, content = []], rest, context) => [[parse((0, dom_1.defrag)(content), params, context)], rest])))));
|
|
6572
6576
|
exports.linemedialink = (0, combinator_1.surround)(source_1.linebreak, (0, combinator_1.union)([exports.medialink]), /^(?=[^\S\n]*(?:$|\n))/);
|
|
6573
6577
|
exports.unsafelink = (0, combinator_1.lazy)(() => (0, combinator_1.creation)(10, (0, combinator_1.precedence)(2, (0, combinator_1.bind)((0, combinator_1.reverse)((0, combinator_1.tails)([(0, combinator_1.dup)((0, combinator_1.surround)('[', (0, combinator_1.some)((0, combinator_1.union)([source_1.unescsource]), ']'), ']')), (0, combinator_1.dup)((0, combinator_1.surround)(/^{(?![{}])/, (0, combinator_1.inits)([exports.uri, (0, combinator_1.some)(exports.option)]), /^[^\S\n]*}/))])), ([params, content = []], rest, context) => [[parse((0, dom_1.defrag)(content), params, context)], rest]))));
|
|
6574
6578
|
exports.uri = (0, combinator_1.union)([(0, combinator_1.open)(/^[^\S\n]+/, (0, source_1.str)(/^\S+/)), (0, source_1.str)(/^[^\s{}]+/)]);
|
|
@@ -6748,7 +6752,7 @@ const optspec = {
|
|
|
6748
6752
|
rel: undefined
|
|
6749
6753
|
};
|
|
6750
6754
|
Object.setPrototypeOf(optspec, null);
|
|
6751
|
-
exports.media = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['![', '!{'], (0, combinator_1.creation)(10, (0, combinator_1.open)('!', (0, combinator_1.constraint)(8 /* State.media */, false, (0, combinator_1.syntax)(
|
|
6755
|
+
exports.media = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['![', '!{'], (0, combinator_1.creation)(10, (0, combinator_1.open)('!', (0, combinator_1.constraint)(8 /* State.media */, false, (0, combinator_1.syntax)(0 /* Syntax.none */, 2, ~16 /* State.link */, (0, combinator_1.bind)((0, combinator_1.verify)((0, combinator_1.fmap)((0, combinator_1.tails)([(0, combinator_1.dup)((0, combinator_1.surround)('[', (0, combinator_1.some)((0, combinator_1.union)([htmlentity_1.unsafehtmlentity, bracket, source_1.txt]), ']', [[/^\\?\n/, 9]]), ']', true)), (0, combinator_1.dup)((0, combinator_1.surround)(/^{(?![{}])/, (0, combinator_1.inits)([link_1.uri, (0, combinator_1.some)(option)]), /^[^\S\n]*}/))]), ([as, bs]) => bs ? [[as.join('').trim() || as.join('')], bs] : [[''], as]), ([[text]]) => text === '' || text.trim() !== ''), ([[text], params], rest, context) => {
|
|
6752
6756
|
const INSECURE_URI = params.shift();
|
|
6753
6757
|
const url = new url_1.ReadonlyURL((0, link_1.resolve)(INSECURE_URI, context.host ?? location, context.url ?? context.host ?? location), context.host?.href || location.href);
|
|
6754
6758
|
let cache;
|
|
@@ -6820,7 +6824,7 @@ const inline_1 = __webpack_require__(1160);
|
|
|
6820
6824
|
const source_1 = __webpack_require__(6743);
|
|
6821
6825
|
const visibility_1 = __webpack_require__(7618);
|
|
6822
6826
|
const dom_1 = __webpack_require__(3252);
|
|
6823
|
-
exports.reference = (0, combinator_1.lazy)(() => (0, combinator_1.creation)((0, combinator_1.surround)('[[', (0, combinator_1.constraint)(128 /* State.reference */, false, (0, combinator_1.syntax)(
|
|
6827
|
+
exports.reference = (0, combinator_1.lazy)(() => (0, combinator_1.creation)((0, combinator_1.surround)('[[', (0, combinator_1.constraint)(128 /* State.reference */, false, (0, combinator_1.syntax)(128 /* Syntax.reference */, 6, 256 /* State.annotation */ | 128 /* State.reference */ | 8 /* State.media */, (0, combinator_1.subsequence)([abbr, (0, visibility_1.trimBlankStart)((0, combinator_1.some)(inline_1.inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]]))]))), ']]', false, ([, ns], rest) => [[(0, dom_1.html)('sup', attributes(ns), [(0, dom_1.html)('span', (0, visibility_1.trimNodeEnd)((0, dom_1.defrag)(ns)))])], rest])));
|
|
6824
6828
|
// Chicago-Style
|
|
6825
6829
|
const abbr = (0, combinator_1.creation)((0, combinator_1.surround)('^', (0, combinator_1.union)([(0, source_1.str)(/^(?=[A-Z])(?:[0-9A-Za-z]'?|(?:[-.:]|\.?\??,? ?)(?!['\-.:?, ]))+/)]), /^\|?(?=]])|^\|[^\S\n]*/, true, ([, ns], rest) => ns ? [['\n', ns[0].trimEnd()], rest.replace(visibility_1.blank.start, '')] : [[''], `^${rest}`], ([,, rest]) => [[''], `^${rest}`]));
|
|
6826
6830
|
function attributes(ns) {
|
|
@@ -6889,7 +6893,7 @@ const source_1 = __webpack_require__(6743);
|
|
|
6889
6893
|
const visibility_1 = __webpack_require__(7618);
|
|
6890
6894
|
const array_1 = __webpack_require__(8112);
|
|
6891
6895
|
const dom_1 = __webpack_require__(3252);
|
|
6892
|
-
exports.ruby = (0, combinator_1.lazy)(() => (0, combinator_1.validate)('[', (0, combinator_1.creation)((0, combinator_1.syntax)(
|
|
6896
|
+
exports.ruby = (0, combinator_1.lazy)(() => (0, combinator_1.validate)('[', (0, combinator_1.creation)((0, combinator_1.syntax)(16 /* Syntax.ruby */, 2, -1 /* State.all */, (0, combinator_1.fmap)((0, combinator_1.verify)((0, combinator_1.fmap)((0, combinator_1.sequence)([(0, combinator_1.surround)('[', (0, source_1.str)(/^(?:\\[^\n]|[^\\[\](){}"\n])+/), ']'), (0, combinator_1.surround)('(', (0, source_1.str)(/^(?:\\[^\n]|[^\\[\](){}"\n])+/), ')')]), ([texts, rubies], _, context) => [(0, parser_1.eval)(text({
|
|
6893
6897
|
source: texts,
|
|
6894
6898
|
context
|
|
6895
6899
|
}), [])[0] ?? '', (0, parser_1.eval)(text({
|
package/markdown.d.ts
CHANGED
|
@@ -661,7 +661,6 @@ export namespace MarkdownParser {
|
|
|
661
661
|
InlineParser.ReferenceParser,
|
|
662
662
|
InlineParser.TemplateParser,
|
|
663
663
|
InlineParser.RemarkParser,
|
|
664
|
-
InlineParser.MathParser,
|
|
665
664
|
InlineParser.ExtensionParser,
|
|
666
665
|
InlineParser.RubyParser,
|
|
667
666
|
InlineParser.LinkParser.TextLinkParser,
|
|
@@ -672,6 +671,7 @@ export namespace MarkdownParser {
|
|
|
672
671
|
InlineParser.EmStrongParser,
|
|
673
672
|
InlineParser.StrongParser,
|
|
674
673
|
InlineParser.EmphasisParser,
|
|
674
|
+
InlineParser.MathParser,
|
|
675
675
|
InlineParser.CodeParser,
|
|
676
676
|
InlineParser.HTMLEntityParser,
|
|
677
677
|
InlineParser.AutolinkParser,
|
|
@@ -743,27 +743,6 @@ export namespace MarkdownParser {
|
|
|
743
743
|
InlineParser,
|
|
744
744
|
]> {
|
|
745
745
|
}
|
|
746
|
-
export interface MathParser extends
|
|
747
|
-
// $expr$
|
|
748
|
-
// ${expr}$
|
|
749
|
-
Inline<'math'>,
|
|
750
|
-
Parser<HTMLElement, Context, [
|
|
751
|
-
MathParser.BracketParser,
|
|
752
|
-
Parser<string, Context, [
|
|
753
|
-
MathParser.BracketParser,
|
|
754
|
-
SourceParser.UnescapableSourceParser,
|
|
755
|
-
]>,
|
|
756
|
-
]> {
|
|
757
|
-
}
|
|
758
|
-
export namespace MathParser {
|
|
759
|
-
export interface BracketParser extends
|
|
760
|
-
Inline<'math/bracket'>,
|
|
761
|
-
Parser<HTMLElement, Context, [
|
|
762
|
-
BracketParser,
|
|
763
|
-
SourceParser.EscapableSourceParser,
|
|
764
|
-
]> {
|
|
765
|
-
}
|
|
766
|
-
}
|
|
767
746
|
export interface ExtensionParser extends
|
|
768
747
|
Inline<'extension'>,
|
|
769
748
|
Parser<HTMLElement | string, Context, [
|
|
@@ -1097,6 +1076,27 @@ export namespace MarkdownParser {
|
|
|
1097
1076
|
]>,
|
|
1098
1077
|
]> {
|
|
1099
1078
|
}
|
|
1079
|
+
export interface MathParser extends
|
|
1080
|
+
// $expr$
|
|
1081
|
+
// ${expr}$
|
|
1082
|
+
Inline<'math'>,
|
|
1083
|
+
Parser<HTMLElement, Context, [
|
|
1084
|
+
MathParser.BracketParser,
|
|
1085
|
+
Parser<string, Context, [
|
|
1086
|
+
MathParser.BracketParser,
|
|
1087
|
+
SourceParser.UnescapableSourceParser,
|
|
1088
|
+
]>,
|
|
1089
|
+
]> {
|
|
1090
|
+
}
|
|
1091
|
+
export namespace MathParser {
|
|
1092
|
+
export interface BracketParser extends
|
|
1093
|
+
Inline<'math/bracket'>,
|
|
1094
|
+
Parser<HTMLElement, Context, [
|
|
1095
|
+
BracketParser,
|
|
1096
|
+
SourceParser.EscapableSourceParser,
|
|
1097
|
+
]> {
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
1100
|
export interface CodeParser extends
|
|
1101
1101
|
// `abc`
|
|
1102
1102
|
Inline<'code'>,
|
package/package.json
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { Parser, exec } from '../../data/parser';
|
|
2
|
-
import { Memo } from '../../data/parser/context/memo';
|
|
3
2
|
import { firstline, isBlank } from './line';
|
|
4
3
|
|
|
5
4
|
export function block<P extends Parser<unknown>>(parser: P, separation?: boolean): P;
|
|
@@ -7,7 +6,6 @@ export function block<T>(parser: Parser<T>, separation = true): Parser<T> {
|
|
|
7
6
|
assert(parser);
|
|
8
7
|
return ({ source, context }) => {
|
|
9
8
|
if (source === '') return;
|
|
10
|
-
context.memo ??= new Memo();
|
|
11
9
|
const result = parser({ source, context });
|
|
12
10
|
if (result === undefined) return;
|
|
13
11
|
const rest = exec(result);
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Parser, eval, exec, check } from '../../data/parser';
|
|
2
|
-
import { Memo } from '../../data/parser/context/memo';
|
|
3
2
|
|
|
4
3
|
export function line<P extends Parser<unknown>>(parser: P): P;
|
|
5
4
|
export function line<T>(parser: Parser<T>): Parser<T> {
|
|
6
5
|
assert(parser);
|
|
7
6
|
return ({ source, context }) => {
|
|
8
7
|
if (source === '') return;
|
|
9
|
-
context.memo ??= new Memo();
|
|
10
8
|
const line = firstline(source);
|
|
11
9
|
context.offset ??= 0;
|
|
12
10
|
context.offset += source.length - line.length;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { Parser, Ctx, Context, check } from '../../data/parser';
|
|
2
|
+
import { max } from 'spica/alias';
|
|
2
3
|
|
|
4
|
+
// 設計上キャッシュが汚染されるが運用で回避可能
|
|
5
|
+
// 変換の前または後のみキャッシュされるなら問題ない
|
|
3
6
|
export function convert<P extends Parser<unknown>>(conv: (source: string, context: Context<P>) => string, parser: P, empty?: boolean): P;
|
|
4
7
|
export function convert<T>(conv: (source: string, context: Ctx) => string, parser: Parser<T>, empty = false): Parser<T> {
|
|
5
8
|
assert(parser);
|
|
@@ -7,11 +10,13 @@ export function convert<T>(conv: (source: string, context: Ctx) => string, parse
|
|
|
7
10
|
if (source === '') return;
|
|
8
11
|
const src = conv(source, context);
|
|
9
12
|
if (src === '') return empty ? [[], ''] : undefined;
|
|
13
|
+
const offset = max(source.length - src.length, 0);
|
|
14
|
+
assert(offset >= 0);
|
|
10
15
|
context.offset ??= 0;
|
|
11
|
-
context.offset +=
|
|
16
|
+
context.offset += offset;
|
|
12
17
|
const result = parser({ source: src, context });
|
|
13
18
|
assert(check(src, result));
|
|
14
|
-
context.offset -=
|
|
19
|
+
context.offset -= offset;
|
|
15
20
|
return result;
|
|
16
21
|
};
|
|
17
22
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Parser, Ctx } from '../../data/parser';
|
|
2
2
|
import { firstline, isBlank } from '../constraint/line';
|
|
3
|
-
import {
|
|
3
|
+
import { push } from 'spica/array';
|
|
4
4
|
|
|
5
5
|
export function fence<C extends Ctx, D extends Parser<unknown, C>[]>(opener: RegExp, limit: number, separation = true): Parser<string, C, D> {
|
|
6
6
|
return ({ source }) => {
|
|
@@ -42,6 +42,6 @@ export function fence<C extends Ctx, D extends Parser<unknown, C>[]>(opener: Reg
|
|
|
42
42
|
}
|
|
43
43
|
rest = rest.slice(line.length);
|
|
44
44
|
}
|
|
45
|
-
return [
|
|
45
|
+
return [push([block, overflow, closer], matches), rest];
|
|
46
46
|
};
|
|
47
47
|
}
|
|
@@ -20,10 +20,12 @@ export function indent<T>(opener: RegExp | Parser<T>, parser?: Parser<T> | boole
|
|
|
20
20
|
([indent]) => indent.length * 2 + +(indent[0] === ' '), {})), separation),
|
|
21
21
|
(lines, rest, context) => {
|
|
22
22
|
assert(parser = parser as Parser<T>);
|
|
23
|
+
const offset = rest.length;
|
|
24
|
+
assert(offset >= 0);
|
|
23
25
|
context.offset ??= 0;
|
|
24
|
-
context.offset +=
|
|
26
|
+
context.offset += offset;
|
|
25
27
|
const result = parser({ source: trimBlockEnd(lines.join('')), context });
|
|
26
|
-
context.offset -=
|
|
28
|
+
context.offset -= offset;
|
|
27
29
|
return result && exec(result) === ''
|
|
28
30
|
? [eval(result), rest]
|
|
29
31
|
: undefined;
|
|
@@ -12,11 +12,13 @@ export function focus<T>(scope: string | RegExp, parser: Parser<T>): Parser<T> {
|
|
|
12
12
|
const src = match(source);
|
|
13
13
|
assert(source.startsWith(src));
|
|
14
14
|
if (src === '') return;
|
|
15
|
+
const offset = source.length - src.length;
|
|
16
|
+
assert(offset >= 0);
|
|
15
17
|
context.offset ??= 0;
|
|
16
|
-
context.offset +=
|
|
18
|
+
context.offset += offset;
|
|
17
19
|
const result = parser({ source: src, context });
|
|
18
20
|
assert(check(src, result));
|
|
19
|
-
context.offset -=
|
|
21
|
+
context.offset -= offset;
|
|
20
22
|
if (result === undefined) return;
|
|
21
23
|
assert(exec(result).length < src.length);
|
|
22
24
|
return exec(result).length < src.length
|
|
@@ -41,11 +43,13 @@ export function rewrite<T>(scope: Parser<unknown>, parser: Parser<T>): Parser<T>
|
|
|
41
43
|
const src = source.slice(0, source.length - exec(res1).length);
|
|
42
44
|
assert(src !== '');
|
|
43
45
|
assert(source.startsWith(src));
|
|
46
|
+
const offset = source.length - src.length;
|
|
47
|
+
assert(offset >= 0);
|
|
44
48
|
context.offset ??= 0;
|
|
45
|
-
context.offset +=
|
|
49
|
+
context.offset += offset;
|
|
46
50
|
const res2 = parser({ source: src, context });
|
|
47
51
|
assert(check(src, res2));
|
|
48
|
-
context.offset -=
|
|
52
|
+
context.offset -= offset;
|
|
49
53
|
if (res2 === undefined) return;
|
|
50
54
|
assert(exec(res2) === '');
|
|
51
55
|
return exec(res2).length < src.length
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export class Memo {
|
|
2
2
|
constructor(
|
|
3
3
|
public readonly targets = ~0,
|
|
4
|
+
public readonly margin = 0,
|
|
4
5
|
) {
|
|
5
|
-
this.targets = targets;
|
|
6
6
|
}
|
|
7
7
|
private memory: Record<number, Record<number, readonly [any[], number] | readonly []>>[/* pos */] = [];
|
|
8
|
+
private count = 0;
|
|
8
9
|
public get length(): number {
|
|
9
10
|
return this.memory.length;
|
|
10
11
|
}
|
|
@@ -13,6 +14,7 @@ export class Memo {
|
|
|
13
14
|
syntax: number,
|
|
14
15
|
state: number,
|
|
15
16
|
): readonly [any[], number] | readonly [] | undefined {
|
|
17
|
+
if (this.count === 0) return;
|
|
16
18
|
//console.log('get', position, syntax, state, this.memory[position - 1]?.[syntax]?.[state]);
|
|
17
19
|
const cache = this.memory[position - 1]?.[syntax]?.[state];
|
|
18
20
|
return cache?.length === 2
|
|
@@ -26,6 +28,7 @@ export class Memo {
|
|
|
26
28
|
nodes: any[] | undefined,
|
|
27
29
|
offset: number,
|
|
28
30
|
): void {
|
|
31
|
+
this.count += +!this.memory[position - 1];
|
|
29
32
|
const record = this.memory[position - 1] ??= {};
|
|
30
33
|
assert(!record[syntax]?.[state]);
|
|
31
34
|
(record[syntax] ??= {})[state] = nodes
|
|
@@ -35,12 +38,13 @@ export class Memo {
|
|
|
35
38
|
}
|
|
36
39
|
public resize(position: number): void {
|
|
37
40
|
const memory = this.memory;
|
|
38
|
-
for (let
|
|
39
|
-
memory.pop()
|
|
41
|
+
for (let i = memory.length; i > position; --i) {
|
|
42
|
+
this.count -= +memory.pop()!;
|
|
40
43
|
}
|
|
41
44
|
//console.log('resize', position + 1);
|
|
42
45
|
}
|
|
43
46
|
public clear(): void {
|
|
44
47
|
this.memory = [];
|
|
48
|
+
this.count = 0;
|
|
45
49
|
}
|
|
46
50
|
}
|
|
@@ -69,19 +69,17 @@ export function syntax<T>(syntax: number, prec: number, state: number, parser?:
|
|
|
69
69
|
const position = source.length + context.offset!;
|
|
70
70
|
const stateOuter = context.state ?? 0;
|
|
71
71
|
const stateInner = context.state = stateOuter | state;
|
|
72
|
-
const cache = syntax
|
|
72
|
+
const cache = syntax & memo.targets && stateInner && memo.get(position, syntax, stateInner);
|
|
73
73
|
const result: Result<T> = cache
|
|
74
74
|
? cache.length === 0
|
|
75
75
|
? undefined
|
|
76
76
|
: [cache[0], source.slice(cache[1])]
|
|
77
77
|
: parser!({ source, context });
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
assert.deepStrictEqual(cache && cache, cache && memo.get(position, syntax, stateInner));
|
|
78
|
+
if (stateOuter && !cache && syntax & memo.targets) {
|
|
79
|
+
memo.set(position, syntax, stateInner, eval(result), source.length - exec(result, '').length);
|
|
81
80
|
}
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
memo.resize(position + 2);
|
|
81
|
+
else if (!stateOuter && result && memo.length! >= position + memo.margin) {
|
|
82
|
+
memo.resize(position + memo.margin);
|
|
85
83
|
}
|
|
86
84
|
context.state = stateOuter;
|
|
87
85
|
return result;
|
|
@@ -32,7 +32,7 @@ export function some<T>(parser: Parser<T>, end?: string | RegExp | number, delim
|
|
|
32
32
|
assert.doesNotThrow(() => limit < 0 && check(rest, result));
|
|
33
33
|
if (result === undefined) break;
|
|
34
34
|
nodes = nodes
|
|
35
|
-
? nodes.length < eval(result).length
|
|
35
|
+
? nodes.length < eval(result).length / 8
|
|
36
36
|
? unshift(nodes, eval(result))
|
|
37
37
|
: push(nodes, eval(result))
|
|
38
38
|
: eval(result);
|
package/src/parser/block.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { blockquote } from './block/blockquote';
|
|
|
17
17
|
import { mediablock } from './block/mediablock';
|
|
18
18
|
import { reply } from './block/reply';
|
|
19
19
|
import { paragraph } from './block/paragraph';
|
|
20
|
-
import {
|
|
20
|
+
import { Syntax } from './context';
|
|
21
21
|
import { rnd0Z } from 'spica/random';
|
|
22
22
|
import { html } from 'typed-dom/dom';
|
|
23
23
|
|
|
@@ -39,7 +39,10 @@ export import ReplyParser = BlockParser.ReplyParser;
|
|
|
39
39
|
export import ParagraphParser = BlockParser.ParagraphParser;
|
|
40
40
|
|
|
41
41
|
export const block: BlockParser = creation(0, false,
|
|
42
|
-
reset({
|
|
42
|
+
reset({
|
|
43
|
+
resources: { clock: 20000, recursion: 20 + 1 },
|
|
44
|
+
memo: new Memo(Syntax.targets, 2),
|
|
45
|
+
},
|
|
43
46
|
error(union([
|
|
44
47
|
emptyline,
|
|
45
48
|
pagebreak,
|
package/src/parser/context.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
export const enum Syntax {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
annotation = 1 << 8,
|
|
3
|
+
reference = 1 << 7,
|
|
4
|
+
index = 1 << 6,
|
|
5
|
+
placeholder = 1 << 5,
|
|
6
|
+
ruby = 1 << 4,
|
|
7
|
+
link = 1 << 3,
|
|
8
|
+
bracket = 1 << 2,
|
|
9
9
|
autolink = 1 << 1,
|
|
10
10
|
none = 0,
|
|
11
|
+
targets = 0
|
|
12
|
+
| Syntax.annotation
|
|
13
|
+
| Syntax.reference
|
|
14
|
+
| Syntax.index
|
|
15
|
+
| Syntax.placeholder
|
|
16
|
+
| Syntax.ruby
|
|
17
|
+
| Syntax.link
|
|
18
|
+
| Syntax.bracket,
|
|
11
19
|
}
|
|
12
20
|
|
|
13
21
|
export const enum State {
|
|
@@ -30,10 +38,4 @@ export const enum State {
|
|
|
30
38
|
| State.link
|
|
31
39
|
| State.mark
|
|
32
40
|
| State.autolink,
|
|
33
|
-
backtrackers = 0
|
|
34
|
-
| State.annotation
|
|
35
|
-
| State.reference
|
|
36
|
-
| State.index
|
|
37
|
-
| State.link
|
|
38
|
-
| State.media,
|
|
39
41
|
}
|
|
@@ -8,7 +8,7 @@ import { html, defrag } from 'typed-dom/dom';
|
|
|
8
8
|
export const annotation: AnnotationParser = lazy(() => creation(surround(
|
|
9
9
|
'((',
|
|
10
10
|
constraint(State.annotation, false,
|
|
11
|
-
syntax(Syntax.
|
|
11
|
+
syntax(Syntax.annotation, 6, State.annotation | State.media,
|
|
12
12
|
trimBlankStart(some(union([inline]), ')', [[/^\\?\n/, 9], [')', 2], ['))', 6]])))),
|
|
13
13
|
'))',
|
|
14
14
|
false,
|
|
@@ -33,7 +33,7 @@ export const autolink: AutolinkParser = lazy(() =>
|
|
|
33
33
|
// Escape unmatched hashtag-like strings.
|
|
34
34
|
str(new RegExp(/^#+(?:[^\p{C}\p{S}\p{P}\s]|emoji|['_])*/u.source.replace('emoji', emoji), 'u')),
|
|
35
35
|
// Escape invalid leading characters.
|
|
36
|
-
str(/^[0-
|
|
36
|
+
str(/^[0-9a-z](?=>)/iu),
|
|
37
37
|
anchor,
|
|
38
38
|
])),
|
|
39
39
|
ns => ns.length === 1 ? ns : [stringify(ns)]),
|
|
@@ -21,7 +21,7 @@ Object.setPrototypeOf(optspec, null);
|
|
|
21
21
|
export const media: MediaParser = lazy(() => validate(['![', '!{'], creation(10, open(
|
|
22
22
|
'!',
|
|
23
23
|
constraint(State.media, false,
|
|
24
|
-
syntax(Syntax.
|
|
24
|
+
syntax(Syntax.none, 2, ~State.link,
|
|
25
25
|
bind(verify(fmap(tails([
|
|
26
26
|
dup(surround(
|
|
27
27
|
'[',
|
|
@@ -68,9 +68,12 @@ export const linemedia: MediaParser.LineMediaParser = surround(
|
|
|
68
68
|
/^(?=[^\S\n]*(?:$|\n))/);
|
|
69
69
|
|
|
70
70
|
const bracket: MediaParser.TextParser.BracketParser = lazy(() => creation(union([
|
|
71
|
-
surround(str('('), some(union([unsafehtmlentity, bracket, txt]), ')'), str(')'), true,
|
|
72
|
-
|
|
73
|
-
surround(str('
|
|
71
|
+
surround(str('('), some(union([unsafehtmlentity, bracket, txt]), ')'), str(')'), true,
|
|
72
|
+
undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
73
|
+
surround(str('['), some(union([unsafehtmlentity, bracket, txt]), ']'), str(']'), true,
|
|
74
|
+
undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
75
|
+
surround(str('{'), some(union([unsafehtmlentity, bracket, txt]), '}'), str('}'), true,
|
|
76
|
+
undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
74
77
|
surround(str('"'), precedence(3, some(union([unsafehtmlentity, txt]), '"')), str('"'), true),
|
|
75
78
|
])));
|
|
76
79
|
|
|
@@ -13,8 +13,11 @@ export const template: TemplateParser = lazy(() => creation(surround(
|
|
|
13
13
|
([, ns = []], rest) => [[html('span', { class: 'template' }, `{{${ns.join('').replace(/\x1B/g, '')}}}`)], rest])));
|
|
14
14
|
|
|
15
15
|
const bracket: TemplateParser.BracketParser = lazy(() => creation(union([
|
|
16
|
-
surround(str('('), some(union([bracket, escsource]), ')'), str(')'), true,
|
|
17
|
-
|
|
18
|
-
surround(str('
|
|
16
|
+
surround(str('('), some(union([bracket, escsource]), ')'), str(')'), true,
|
|
17
|
+
undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
18
|
+
surround(str('['), some(union([bracket, escsource]), ']'), str(']'), true,
|
|
19
|
+
undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
20
|
+
surround(str('{'), some(union([bracket, escsource]), '}'), str('}'), true,
|
|
21
|
+
undefined, ([as, bs = []], rest) => [unshift(as, bs), rest]),
|
|
19
22
|
surround(str('"'), precedence(3, some(escsource, /^"|^\\?\n/)), str('"'), true),
|
|
20
23
|
])));
|
package/src/parser/inline.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { annotation } from './inline/annotation';
|
|
|
4
4
|
import { reference } from './inline/reference';
|
|
5
5
|
import { template } from './inline/template';
|
|
6
6
|
import { remark } from './inline/remark';
|
|
7
|
-
import { math } from './inline/math';
|
|
8
7
|
import { extension } from './inline/extension';
|
|
9
8
|
import { ruby } from './inline/ruby';
|
|
10
9
|
import { textlink } from './inline/link';
|
|
@@ -13,8 +12,9 @@ import { insertion } from './inline/insertion';
|
|
|
13
12
|
import { deletion } from './inline/deletion';
|
|
14
13
|
import { mark } from './inline/mark';
|
|
15
14
|
import { emstrong } from './inline/emstrong';
|
|
16
|
-
import { emphasis } from './inline/emphasis';
|
|
17
15
|
import { strong } from './inline/strong';
|
|
16
|
+
import { emphasis } from './inline/emphasis';
|
|
17
|
+
import { math } from './inline/math';
|
|
18
18
|
import { code } from './inline/code';
|
|
19
19
|
import { htmlentity } from './inline/htmlentity';
|
|
20
20
|
import { autolink } from './inline/autolink';
|
|
@@ -26,7 +26,6 @@ export import AnnotationParser = InlineParser.AnnotationParser;
|
|
|
26
26
|
export import ReferenceParser = InlineParser.ReferenceParser;
|
|
27
27
|
export import TemplateParser = InlineParser.TemplateParser;
|
|
28
28
|
export import RemarkParser = InlineParser.RemarkParser;
|
|
29
|
-
export import MathParser = InlineParser.MathParser;
|
|
30
29
|
export import ExtensionParser = InlineParser.ExtensionParser;
|
|
31
30
|
export import RubyParser = InlineParser.RubyParser;
|
|
32
31
|
export import LinkParser = InlineParser.LinkParser;
|
|
@@ -35,8 +34,9 @@ export import InsertionParser = InlineParser.InsertionParser;
|
|
|
35
34
|
export import DeletionParser = InlineParser.DeletionParser;
|
|
36
35
|
export import MarkParser = InlineParser.MarkParser;
|
|
37
36
|
export import EmStrongParser = InlineParser.EmStrongParser;
|
|
38
|
-
export import EmphasisParser = InlineParser.EmphasisParser;
|
|
39
37
|
export import StrongParser = InlineParser.StrongParser;
|
|
38
|
+
export import EmphasisParser = InlineParser.EmphasisParser;
|
|
39
|
+
export import MathParser = InlineParser.MathParser;
|
|
40
40
|
export import CodeParser = InlineParser.CodeParser;
|
|
41
41
|
export import MediaParser = InlineParser.MediaParser;
|
|
42
42
|
export import HTMLEntityParser = InlineParser.HTMLEntityParser;
|
|
@@ -50,7 +50,6 @@ export const inline: InlineParser = lazy(() => union([
|
|
|
50
50
|
reference,
|
|
51
51
|
template,
|
|
52
52
|
remark,
|
|
53
|
-
math,
|
|
54
53
|
extension,
|
|
55
54
|
ruby,
|
|
56
55
|
textlink,
|
|
@@ -61,6 +60,7 @@ export const inline: InlineParser = lazy(() => union([
|
|
|
61
60
|
emstrong,
|
|
62
61
|
strong,
|
|
63
62
|
emphasis,
|
|
63
|
+
math,
|
|
64
64
|
code,
|
|
65
65
|
htmlentity,
|
|
66
66
|
autolink,
|