securemark 0.300.1 → 0.300.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 +8 -0
- package/dist/index.js +87 -65
- package/index.d.ts +1 -1
- package/markdown.d.ts +3 -10
- package/package.json +1 -1
- package/src/api/bind.ts +4 -4
- package/src/combinator/process/fence.ts +22 -32
- package/src/combinator/process/line.ts +1 -1
- package/src/parser/block/codeblock.ts +1 -1
- package/src/parser/block/extension/aside.ts +1 -1
- package/src/parser/block/extension/example.ts +1 -1
- package/src/parser/block/extension/fig.ts +5 -7
- package/src/parser/block/extension/figure.ts +5 -6
- package/src/parser/block/extension/message.ts +1 -1
- package/src/parser/block/extension/placeholder.ts +1 -1
- package/src/parser/block/extension/table.ts +1 -7
- package/src/parser/block/extension.ts +1 -2
- package/src/parser/block/mathblock.ts +1 -1
- package/src/parser/context.ts +1 -1
- package/src/parser/document.ts +38 -11
- package/src/parser/repeat.ts +4 -2
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! securemark v0.300.
|
|
1
|
+
/*! securemark v0.300.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"));
|
|
@@ -2463,7 +2463,8 @@ function bind(target, settings) {
|
|
|
2463
2463
|
options.segment = sourceSegmentAttrs[index] | 1 /* Segment.write */;
|
|
2464
2464
|
for (const _ of (0, parser_1.run)(block_1.block, new context_1.Input(options, seg), output)) {
|
|
2465
2465
|
yield {
|
|
2466
|
-
type: 'break'
|
|
2466
|
+
type: 'break',
|
|
2467
|
+
value: 'block'
|
|
2467
2468
|
};
|
|
2468
2469
|
}
|
|
2469
2470
|
const es = output.pop().foldl((acc, {
|
|
@@ -2519,7 +2520,8 @@ function bind(target, settings) {
|
|
|
2519
2520
|
};
|
|
2520
2521
|
}
|
|
2521
2522
|
yield {
|
|
2522
|
-
type: 'break'
|
|
2523
|
+
type: 'break',
|
|
2524
|
+
value: 'parser'
|
|
2523
2525
|
};
|
|
2524
2526
|
if (rev !== revision) return yield {
|
|
2525
2527
|
type: 'cancel'
|
|
@@ -2529,7 +2531,8 @@ function bind(target, settings) {
|
|
|
2529
2531
|
type: 'figure',
|
|
2530
2532
|
value: el
|
|
2531
2533
|
} : yield {
|
|
2532
|
-
type: 'break'
|
|
2534
|
+
type: 'break',
|
|
2535
|
+
value: 'figure'
|
|
2533
2536
|
};
|
|
2534
2537
|
if (rev !== revision) return yield {
|
|
2535
2538
|
type: 'cancel'
|
|
@@ -2540,7 +2543,8 @@ function bind(target, settings) {
|
|
|
2540
2543
|
type: 'note',
|
|
2541
2544
|
value: el
|
|
2542
2545
|
} : yield {
|
|
2543
|
-
type: 'break'
|
|
2546
|
+
type: 'break',
|
|
2547
|
+
value: 'note'
|
|
2544
2548
|
};
|
|
2545
2549
|
if (rev !== revision) return yield {
|
|
2546
2550
|
type: 'cancel'
|
|
@@ -4256,11 +4260,10 @@ const line_1 = __webpack_require__(1599);
|
|
|
4256
4260
|
function fence(opener, write, separation = true) {
|
|
4257
4261
|
return (input, output) => {
|
|
4258
4262
|
const {
|
|
4259
|
-
source
|
|
4260
|
-
position
|
|
4263
|
+
source
|
|
4261
4264
|
} = input;
|
|
4262
|
-
if (position === source.length) return;
|
|
4263
|
-
opener.lastIndex = position;
|
|
4265
|
+
if (input.position === source.length) return;
|
|
4266
|
+
opener.lastIndex = input.position;
|
|
4264
4267
|
const matches = opener.exec(source);
|
|
4265
4268
|
if (!matches) return;
|
|
4266
4269
|
(0, clock_1.spend)(input, output, matches[0].length);
|
|
@@ -4273,34 +4276,26 @@ function fence(opener, write, separation = true) {
|
|
|
4273
4276
|
input.position -= matches[0].length;
|
|
4274
4277
|
return;
|
|
4275
4278
|
}
|
|
4279
|
+
const {
|
|
4280
|
+
position
|
|
4281
|
+
} = input;
|
|
4276
4282
|
let body = '';
|
|
4277
4283
|
let closer = '';
|
|
4278
|
-
|
|
4279
|
-
|
|
4280
|
-
if (input.position
|
|
4281
|
-
|
|
4282
|
-
|
|
4283
|
-
|
|
4284
|
-
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
if (!separation) {
|
|
4293
|
-
input.position += line.length;
|
|
4294
|
-
break;
|
|
4295
|
-
}
|
|
4296
|
-
overflow = line;
|
|
4297
|
-
}
|
|
4298
|
-
if (!overflow) {
|
|
4299
|
-
body += line;
|
|
4300
|
-
}
|
|
4301
|
-
input.position += line.length;
|
|
4284
|
+
for (input.position -= 1;;) {
|
|
4285
|
+
input.position = source.indexOf(`\n${delim}`, input.position) + 1 || source.length;
|
|
4286
|
+
if (!(0, line_1.isEmptyline)(source, input.position + delim.length)) continue;
|
|
4287
|
+
body = source.slice(position, input.position);
|
|
4288
|
+
closer = (0, line_1.firstline)(source, input.position);
|
|
4289
|
+
input.position += closer.length;
|
|
4290
|
+
break;
|
|
4291
|
+
}
|
|
4292
|
+
if (separation) for (; !(0, line_1.isEmptyline)(source, input.position);) {
|
|
4293
|
+
input.position = source.indexOf('\n', input.position) + 1 || source.length;
|
|
4294
|
+
}
|
|
4295
|
+
if (write) {
|
|
4296
|
+
const overflow = source.slice(position + body.length + closer.length, input.position);
|
|
4297
|
+
output.push(new parser_1.List([body, overflow, closer].map(str => new parser_1.Node(str))).import(new parser_1.List(matches.map(str => new parser_1.Node(str)))));
|
|
4302
4298
|
}
|
|
4303
|
-
write && output.push(new parser_1.List([body, overflow, closer].map(str => new parser_1.Node(str))).import(new parser_1.List(matches.map(str => new parser_1.Node(str)))));
|
|
4304
4299
|
return output.context;
|
|
4305
4300
|
};
|
|
4306
4301
|
}
|
|
@@ -4445,7 +4440,7 @@ exports.firstline = firstline;
|
|
|
4445
4440
|
const emptyline = /[^\S\r\n]*(?:$|\r?\n)/y;
|
|
4446
4441
|
function isEmptyline(source, position) {
|
|
4447
4442
|
emptyline.lastIndex = position;
|
|
4448
|
-
return source.length
|
|
4443
|
+
return position >= source.length || source[position] === '\n' || emptyline.test(source);
|
|
4449
4444
|
}
|
|
4450
4445
|
exports.isEmptyline = isEmptyline;
|
|
4451
4446
|
|
|
@@ -5014,7 +5009,7 @@ exports.codeblock = (0, combinator_1.block)((0, combinator_1.inits)([(0, combina
|
|
|
5014
5009
|
class: 'invalid',
|
|
5015
5010
|
translate: 'no',
|
|
5016
5011
|
...(0, util_1.invalid)('codeblock', !closer || overflow ? 'fence' : 'argument', !closer ? `Missing the closing delimiter "${delim}"` : overflow ? `Invalid trailing line after the closing delimiter "${delim}"` : params.invalid)
|
|
5017
|
-
}, `${opener}${body}${
|
|
5012
|
+
}, `${opener}${body}${closer}${overflow}`)));
|
|
5018
5013
|
return;
|
|
5019
5014
|
}
|
|
5020
5015
|
const src = body.slice(0, body.at(-2) === '\r' ? -2 : -1);
|
|
@@ -5085,7 +5080,7 @@ const message_1 = __webpack_require__(3949);
|
|
|
5085
5080
|
const aside_1 = __webpack_require__(6150);
|
|
5086
5081
|
const example_1 = __webpack_require__(6624);
|
|
5087
5082
|
const placeholder_1 = __webpack_require__(4091);
|
|
5088
|
-
exports.segment = (0, combinator_1.union)([fig_1.segment, figure_1.segment,
|
|
5083
|
+
exports.segment = (0, combinator_1.union)([fig_1.segment, figure_1.segment, placeholder_1.segment]);
|
|
5089
5084
|
exports.extension = (0, combinator_1.lazy)(() => (0, combinator_1.union)([
|
|
5090
5085
|
//figbase,
|
|
5091
5086
|
//fig,
|
|
@@ -5116,7 +5111,7 @@ exports.aside = (0, combinator_1.block)((0, combinator_1.recursion)(1 /* Recursi
|
|
|
5116
5111
|
class: 'invalid',
|
|
5117
5112
|
translate: 'no',
|
|
5118
5113
|
...(0, util_1.invalid)('aside', !closer || overflow ? 'fence' : 'argument', !closer ? `Missing the closing delimiter "${delim}"` : overflow ? `Invalid trailing line after the closing delimiter "${delim}"` : 'Invalid argument')
|
|
5119
|
-
}, `${opener}${body}${
|
|
5114
|
+
}, `${opener}${body}${closer}${overflow}`)));
|
|
5120
5115
|
return;
|
|
5121
5116
|
}
|
|
5122
5117
|
input.memory = {
|
|
@@ -5185,7 +5180,7 @@ exports.example = (0, combinator_1.block)((0, combinator_1.recursion)(1 /* Recur
|
|
|
5185
5180
|
class: 'invalid',
|
|
5186
5181
|
translate: 'no',
|
|
5187
5182
|
...(0, util_1.invalid)('example', !closer || overflow ? 'fence' : 'argument', !closer ? `Missing the closing delimiter "${delim}"` : overflow ? `Invalid trailing line after the closing delimiter "${delim}"` : 'Invalid argument')
|
|
5188
|
-
}, `${opener}${body}${
|
|
5183
|
+
}, `${opener}${body}${closer}${overflow}`)));
|
|
5189
5184
|
switch (type) {
|
|
5190
5185
|
case 'markdown':
|
|
5191
5186
|
{
|
|
@@ -5263,10 +5258,9 @@ const figure_1 = __webpack_require__(4248);
|
|
|
5263
5258
|
const label_1 = __webpack_require__(2178);
|
|
5264
5259
|
const codeblock_1 = __webpack_require__(9194);
|
|
5265
5260
|
const mathblock_1 = __webpack_require__(4903);
|
|
5266
|
-
const table_1 = __webpack_require__(3646);
|
|
5267
|
-
const blockquote_1 = __webpack_require__(5885);
|
|
5268
5261
|
const placeholder_1 = __webpack_require__(4091);
|
|
5269
|
-
|
|
5262
|
+
const blockquote_1 = __webpack_require__(5885);
|
|
5263
|
+
exports.segment = (0, combinator_1.block)((0, combinator_1.sequence)([(0, combinator_1.line)((0, combinator_1.close)(label_1.segment, /(?!\S)[^\r\n]*\r?\n/y), false), (0, combinator_1.union)([codeblock_1.segment, mathblock_1.segment, placeholder_1.segment, blockquote_1.segment, (0, combinator_1.some)(source_1.contentline)])]), true, 6 /* Segment.fig */);
|
|
5270
5264
|
exports.fig = (0, combinator_1.block)((0, combinator_1.rewrite)(exports.segment, (0, combinator_1.always)([(input, output) => {
|
|
5271
5265
|
const {
|
|
5272
5266
|
source
|
|
@@ -5333,8 +5327,8 @@ const codeblock_1 = __webpack_require__(9194);
|
|
|
5333
5327
|
const mathblock_1 = __webpack_require__(4903);
|
|
5334
5328
|
const example_1 = __webpack_require__(6624);
|
|
5335
5329
|
const table_2 = __webpack_require__(3646);
|
|
5336
|
-
const blockquote_1 = __webpack_require__(5885);
|
|
5337
5330
|
const placeholder_1 = __webpack_require__(4091);
|
|
5331
|
+
const blockquote_1 = __webpack_require__(5885);
|
|
5338
5332
|
const inline_1 = __webpack_require__(7973);
|
|
5339
5333
|
const visibility_1 = __webpack_require__(6364);
|
|
5340
5334
|
const util_1 = __webpack_require__(4992);
|
|
@@ -5342,10 +5336,10 @@ const memoize_1 = __webpack_require__(6925);
|
|
|
5342
5336
|
const dom_1 = __webpack_require__(394);
|
|
5343
5337
|
exports.segment = (0, combinator_1.block)((0, combinator_1.match)(/(~{3,})(?:figure )?(?=\[?\$)/y, (0, memoize_1.memoize)(([, fence], closer = new RegExp(String.raw`${fence}[^\S\r\n]*(?:$|\r?\n)`, 'y')) => (0, combinator_1.close)((0, combinator_1.sequence)([source_1.contentline, (0, combinator_1.inits)([
|
|
5344
5338
|
// All parsers which can include closing terms.
|
|
5345
|
-
(0, combinator_1.union)([codeblock_1.segment_, mathblock_1.segment_,
|
|
5339
|
+
(0, combinator_1.union)([codeblock_1.segment_, mathblock_1.segment_, placeholder_1.segment_, blockquote_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 - 1, [], 2 ** 4 - 1)), true, 8 /* Segment.figure */);
|
|
5346
5340
|
exports.figure = (0, combinator_1.block)((0, combinator_1.fallback)((0, combinator_1.rewrite)(exports.segment, (0, combinator_1.fmap)((0, combinator_1.scope)(({
|
|
5347
5341
|
source
|
|
5348
|
-
}) => 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)[^\r\n]*\r?\n/y)]), false), (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,
|
|
5342
|
+
}) => 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)[^\r\n]*\r?\n/y)]), false), (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, placeholder_1.placeholder, blockquote_1.blockquote, (0, combinator_1.line)(inline_1.media, false), (0, combinator_1.line)(inline_1.lineshortmedia, false)])), source_1.emptyline, (0, combinator_1.block)((0, visibility_1.visualize)((0, visibility_1.trimBlank)((0, combinator_1.some)(inline_1.inline))))])]), false), nodes => {
|
|
5349
5343
|
const [label, param, content, ...caption] = (0, util_1.unwrap)(nodes);
|
|
5350
5344
|
return new parser_1.List([new parser_1.Node((0, dom_1.html)('figure', attributes(label.getAttribute('data-label'), param, content, caption), [(0, dom_1.html)('figcaption', [(0, dom_1.html)('span', {
|
|
5351
5345
|
class: 'figindex'
|
|
@@ -5359,7 +5353,7 @@ exports.figure = (0, combinator_1.block)((0, combinator_1.fallback)((0, combinat
|
|
|
5359
5353
|
class: 'invalid',
|
|
5360
5354
|
translate: 'no',
|
|
5361
5355
|
...(0, util_1.invalid)('figure', violation[0], violation[1])
|
|
5362
|
-
}, `${opener}${body}${
|
|
5356
|
+
}, `${opener}${body}${closer}${overflow}`)));
|
|
5363
5357
|
}])));
|
|
5364
5358
|
function attributes(label, param, content, caption) {
|
|
5365
5359
|
const group = label.split('-', 1)[0];
|
|
@@ -5435,7 +5429,7 @@ exports.message = (0, combinator_1.block)((0, combinator_1.inits)([(0, combinato
|
|
|
5435
5429
|
class: 'invalid',
|
|
5436
5430
|
translate: 'no',
|
|
5437
5431
|
...(0, util_1.invalid)('message', !closer || overflow ? 'fence' : 'argument', !closer ? `Missing the closing delimiter "${delim}"` : overflow ? `Invalid trailing line after the closing delimiter "${delim}"` : 'Invalid argument')
|
|
5438
|
-
}, `${opener}${body}${
|
|
5432
|
+
}, `${opener}${body}${closer}${overflow}`)));
|
|
5439
5433
|
return;
|
|
5440
5434
|
}
|
|
5441
5435
|
switch (type) {
|
|
@@ -5503,7 +5497,7 @@ exports.placeholder = (0, combinator_1.block)((0, combinator_1.inits)([(0, combi
|
|
|
5503
5497
|
class: 'invalid',
|
|
5504
5498
|
translate: 'no',
|
|
5505
5499
|
...(0, util_1.invalid)('extension', 'fence', !closer ? `Missing the closing delimiter "${delim}"` : overflow ? `Invalid trailing line after the closing delimiter "${delim}"` : 'Invalid argument')
|
|
5506
|
-
}, `${opener}${body}${
|
|
5500
|
+
}, `${opener}${body}${closer}${overflow}`)));
|
|
5507
5501
|
}]));
|
|
5508
5502
|
|
|
5509
5503
|
/***/ },
|
|
@@ -5517,7 +5511,7 @@ exports.placeholder = (0, combinator_1.block)((0, combinator_1.inits)([(0, combi
|
|
|
5517
5511
|
Object.defineProperty(exports, "__esModule", ({
|
|
5518
5512
|
value: true
|
|
5519
5513
|
}));
|
|
5520
|
-
exports.table =
|
|
5514
|
+
exports.table = void 0;
|
|
5521
5515
|
const parser_1 = __webpack_require__(3360);
|
|
5522
5516
|
const combinator_1 = __webpack_require__(3484);
|
|
5523
5517
|
const inline_1 = __webpack_require__(7973);
|
|
@@ -5528,15 +5522,13 @@ const alias_1 = __webpack_require__(5413);
|
|
|
5528
5522
|
const array_1 = __webpack_require__(6876);
|
|
5529
5523
|
const dom_1 = __webpack_require__(394);
|
|
5530
5524
|
const opener = /(~{3,})table(?:\/(\S+))?(?!\S)([^\r\n]*)(?:$|\r?\n)/y;
|
|
5531
|
-
exports.segment = (0, combinator_1.block)((0, combinator_1.fence)(opener, false));
|
|
5532
|
-
exports.segment_ = (0, combinator_1.block)((0, combinator_1.fence)(opener, false, false), false);
|
|
5533
5525
|
exports.table = (0, combinator_1.block)((0, combinator_1.inits)([(0, combinator_1.fence)(opener, true), (_, output) => {
|
|
5534
5526
|
const [body, overflow, closer, opener, delim, type, param] = (0, util_1.unwrap)(output.pop());
|
|
5535
5527
|
if (!closer || overflow || param.trimStart()) return output.append(new parser_1.Node((0, dom_1.html)('pre', {
|
|
5536
5528
|
class: 'invalid',
|
|
5537
5529
|
translate: 'no',
|
|
5538
5530
|
...(0, util_1.invalid)('table', !closer || overflow ? 'fence' : 'argument', !closer ? `Missing the closing delimiter "${delim}"` : overflow ? `Invalid trailing line after the closing delimiter "${delim}"` : 'Invalid argument')
|
|
5539
|
-
}, `${opener}${body}${
|
|
5531
|
+
}, `${opener}${body}${closer}${overflow}`)));
|
|
5540
5532
|
switch (type) {
|
|
5541
5533
|
case undefined:
|
|
5542
5534
|
case 'grid':
|
|
@@ -5888,7 +5880,7 @@ exports.mathblock = (0, combinator_1.block)((0, combinator_1.inits)([(0, combina
|
|
|
5888
5880
|
class: 'invalid',
|
|
5889
5881
|
translate: 'no',
|
|
5890
5882
|
...(0, util_1.invalid)('mathblock', delim.length > 2 ? 'syntax' : !closer || overflow ? 'fence' : 'argument', delim.length > 2 ? 'Invalid syntax' : !closer ? `Missing the closing delimiter "${delim}"` : overflow ? `Invalid trailing line after the closing delimiter "${delim}"` : 'Invalid argument')
|
|
5891
|
-
}, `${opener}${body}${
|
|
5883
|
+
}, `${opener}${body}${closer}${overflow}`)));
|
|
5892
5884
|
}]));
|
|
5893
5885
|
|
|
5894
5886
|
/***/ },
|
|
@@ -6363,7 +6355,7 @@ class Input extends parser_1.Input {
|
|
|
6363
6355
|
this.resources ??= {
|
|
6364
6356
|
clock: -1,
|
|
6365
6357
|
interval: 200,
|
|
6366
|
-
recursions: [
|
|
6358
|
+
recursions: [20 || 0 /* Recursion.document */, 100 || 0 /* Recursion.block */, 100 || 0 /* Recursion.inline */, 100 || 0 /* Recursion.bracket */]
|
|
6367
6359
|
};
|
|
6368
6360
|
this.segment = segment ?? 0 /* Segment.unknown */;
|
|
6369
6361
|
this.header = header ?? true;
|
|
@@ -6421,29 +6413,54 @@ exports.document = (() => {
|
|
|
6421
6413
|
const loop = (0, parser_2.build)(segment_1.parser, block_1.block);
|
|
6422
6414
|
return (0, combinator_1.always)([(input, output) => {
|
|
6423
6415
|
input.id = input.id === '' ? '' : input.local ? (0, util_1.randomID)() : input.id;
|
|
6424
|
-
input.memory =
|
|
6425
|
-
interpolation:
|
|
6426
|
-
references: (0, dom_1.html)('ol', {
|
|
6416
|
+
input.memory = {
|
|
6417
|
+
interpolation: !input.notes,
|
|
6418
|
+
references: input.notes?.references ?? (0, dom_1.html)('ol', {
|
|
6427
6419
|
class: 'references'
|
|
6428
6420
|
})
|
|
6429
6421
|
};
|
|
6430
6422
|
output.push();
|
|
6431
6423
|
return output.context;
|
|
6432
6424
|
}, (0, combinator_1.recursion)(0 /* Recursion.document */, (0, combinator_1.force)(() => loop)), (input, output) => {
|
|
6433
|
-
const
|
|
6425
|
+
const {
|
|
6426
|
+
memory
|
|
6427
|
+
} = input;
|
|
6428
|
+
const doc = memory.doc = (0, dom_1.frag)((0, util_1.unwrap)(output.pop()));
|
|
6434
6429
|
output.append(new parser_1.Node(doc));
|
|
6430
|
+
if (input.test && !input.local) return output.context;
|
|
6431
|
+
memory.orphan = !memory.references.parentNode;
|
|
6432
|
+
memory.orphan && doc.appendChild(memory.references);
|
|
6433
|
+
return output.context;
|
|
6434
|
+
}, (input, output) => {
|
|
6435
|
+
if (input.test && !input.local) return output.context;
|
|
6436
|
+
const {
|
|
6437
|
+
memory
|
|
6438
|
+
} = input;
|
|
6439
|
+
return conv((0, figure_1.figure)(memory.doc, memory, input));
|
|
6440
|
+
}, (input, output) => {
|
|
6435
6441
|
if (input.test && !input.local) return output.context;
|
|
6436
6442
|
const {
|
|
6437
6443
|
memory
|
|
6438
6444
|
} = input;
|
|
6439
|
-
|
|
6440
|
-
|
|
6441
|
-
|
|
6442
|
-
|
|
6443
|
-
|
|
6445
|
+
return conv((0, note_1.note)(memory.doc, memory, input));
|
|
6446
|
+
}, (input, output) => {
|
|
6447
|
+
const {
|
|
6448
|
+
memory
|
|
6449
|
+
} = input;
|
|
6450
|
+
memory.orphan && !memory.interpolation && memory.references.remove();
|
|
6444
6451
|
return output.context;
|
|
6445
6452
|
}]);
|
|
6446
6453
|
})();
|
|
6454
|
+
function conv(iterable) {
|
|
6455
|
+
const iter = iterable[Symbol.iterator]();
|
|
6456
|
+
const cont = [(_, output) => {
|
|
6457
|
+
const {
|
|
6458
|
+
done
|
|
6459
|
+
} = iter.next();
|
|
6460
|
+
return done ? output.context : cont;
|
|
6461
|
+
}];
|
|
6462
|
+
return cont;
|
|
6463
|
+
}
|
|
6447
6464
|
|
|
6448
6465
|
/***/ },
|
|
6449
6466
|
|
|
@@ -8589,7 +8606,7 @@ function repeat(opener, after, closer, recursion, parser, cons, termination = (n
|
|
|
8589
8606
|
input.position = position;
|
|
8590
8607
|
return parser_1.Result.skip;
|
|
8591
8608
|
}
|
|
8592
|
-
|
|
8609
|
+
const depth = i / opener.length + 1 | 0;
|
|
8593
8610
|
(0, combinator_1.recur)(output, recursions, recursion, depth, true);
|
|
8594
8611
|
input.memory = {
|
|
8595
8612
|
position,
|
|
@@ -8641,6 +8658,7 @@ function repeat(opener, after, closer, recursion, parser, cons, termination = (n
|
|
|
8641
8658
|
const advance = input.position - pos;
|
|
8642
8659
|
m.i -= advance;
|
|
8643
8660
|
m.follow -= advance;
|
|
8661
|
+
(0, combinator_1.recur)(output, recursions, recursion, -(advance / closer.length | 0));
|
|
8644
8662
|
m.depth -= advance / closer.length | 0;
|
|
8645
8663
|
}
|
|
8646
8664
|
continue;
|
|
@@ -8651,7 +8669,10 @@ function repeat(opener, after, closer, recursion, parser, cons, termination = (n
|
|
|
8651
8669
|
}, parser, (input, output) => {
|
|
8652
8670
|
const {
|
|
8653
8671
|
source,
|
|
8654
|
-
memory: m
|
|
8672
|
+
memory: m,
|
|
8673
|
+
resources: {
|
|
8674
|
+
recursions
|
|
8675
|
+
}
|
|
8655
8676
|
} = input;
|
|
8656
8677
|
const {
|
|
8657
8678
|
lead
|
|
@@ -8679,6 +8700,7 @@ function repeat(opener, after, closer, recursion, parser, cons, termination = (n
|
|
|
8679
8700
|
const advance = input.position - pos;
|
|
8680
8701
|
m.i -= advance;
|
|
8681
8702
|
m.follow -= advance;
|
|
8703
|
+
(0, combinator_1.recur)(output, recursions, recursion, -(advance / closer.length | 0));
|
|
8682
8704
|
m.depth -= advance / closer.length | 0;
|
|
8683
8705
|
}
|
|
8684
8706
|
m.i -= opener.length, m.follow -= closer.length;
|
package/index.d.ts
CHANGED
|
@@ -44,7 +44,7 @@ export type Progress =
|
|
|
44
44
|
| { readonly type: 'block'; readonly value: HTMLElement; }
|
|
45
45
|
| { readonly type: 'figure'; readonly value: HTMLAnchorElement; }
|
|
46
46
|
| { readonly type: 'note'; readonly value: HTMLLIElement | HTMLElement; }
|
|
47
|
-
| { readonly type: 'break'; }
|
|
47
|
+
| { readonly type: 'break'; readonly value: 'segment' | 'block' | 'parser' | 'figure' | 'note'; }
|
|
48
48
|
| { readonly type: 'cancel'; };
|
|
49
49
|
|
|
50
50
|
export interface RenderingOptions {
|
package/markdown.d.ts
CHANGED
|
@@ -325,7 +325,6 @@ export namespace MarkdownParser {
|
|
|
325
325
|
Parser<string, Input, [
|
|
326
326
|
FigParser.SegmentParser,
|
|
327
327
|
FigureParser.SegmentParser,
|
|
328
|
-
TableParser.SegmentParser,
|
|
329
328
|
PlaceholderParser.SegmentParser,
|
|
330
329
|
]> {
|
|
331
330
|
}
|
|
@@ -350,8 +349,8 @@ export namespace MarkdownParser {
|
|
|
350
349
|
MathBlockParser,
|
|
351
350
|
ExampleParser,
|
|
352
351
|
TableParser,
|
|
353
|
-
BlockquoteParser,
|
|
354
352
|
PlaceholderParser,
|
|
353
|
+
BlockquoteParser,
|
|
355
354
|
InlineParser.MediaParser,
|
|
356
355
|
InlineParser.ShortMediaParser.LineShortMediaParser,
|
|
357
356
|
]>,
|
|
@@ -369,9 +368,8 @@ export namespace MarkdownParser {
|
|
|
369
368
|
Parser<never, Input, [
|
|
370
369
|
CodeBlockParser.SegmentParser,
|
|
371
370
|
MathBlockParser.SegmentParser,
|
|
372
|
-
TableParser.SegmentParser,
|
|
373
|
-
BlockquoteParser.SegmentParser,
|
|
374
371
|
PlaceholderParser.SegmentParser,
|
|
372
|
+
BlockquoteParser.SegmentParser,
|
|
375
373
|
SourceParser.ContentLineParser,
|
|
376
374
|
]>,
|
|
377
375
|
SourceParser.EmptyLineParser,
|
|
@@ -399,9 +397,8 @@ export namespace MarkdownParser {
|
|
|
399
397
|
Parser<never, Input, [
|
|
400
398
|
CodeBlockParser.SegmentParser,
|
|
401
399
|
MathBlockParser.SegmentParser,
|
|
402
|
-
TableParser.SegmentParser,
|
|
403
|
-
BlockquoteParser.SegmentParser,
|
|
404
400
|
PlaceholderParser.SegmentParser,
|
|
401
|
+
BlockquoteParser.SegmentParser,
|
|
405
402
|
SourceParser.ContentLineParser,
|
|
406
403
|
]>,
|
|
407
404
|
]> {
|
|
@@ -427,10 +424,6 @@ export namespace MarkdownParser {
|
|
|
427
424
|
]> {
|
|
428
425
|
}
|
|
429
426
|
export namespace TableParser {
|
|
430
|
-
export interface SegmentParser extends
|
|
431
|
-
Block<'extension/table/segment'>,
|
|
432
|
-
Parser<never, Input, []> {
|
|
433
|
-
}
|
|
434
427
|
export interface GridTableParser extends
|
|
435
428
|
Block<'extension/table/gridtable'>,
|
|
436
429
|
Parser<HTMLElement, Input, [
|
package/package.json
CHANGED
package/src/api/bind.ts
CHANGED
|
@@ -75,7 +75,7 @@ export function bind(target: DocumentFragment | HTMLElement | ShadowRoot, settin
|
|
|
75
75
|
const seg = sourceSegments[index];
|
|
76
76
|
options.segment = sourceSegmentAttrs[index] | Segment.write;
|
|
77
77
|
for (const _ of run(block, new Input(options, seg), output)) {
|
|
78
|
-
yield { type: 'break' };
|
|
78
|
+
yield { type: 'break', value: 'block' };
|
|
79
79
|
}
|
|
80
80
|
assert(output.data.length === 1);
|
|
81
81
|
const es = output.pop()
|
|
@@ -124,20 +124,20 @@ export function bind(target: DocumentFragment | HTMLElement | ShadowRoot, settin
|
|
|
124
124
|
yield { type: 'block', value: el };
|
|
125
125
|
if (rev !== revision) return yield { type: 'cancel' };
|
|
126
126
|
}
|
|
127
|
-
yield { type: 'break' };
|
|
127
|
+
yield { type: 'break', value: 'parser' };
|
|
128
128
|
if (rev !== revision) return yield { type: 'cancel' };
|
|
129
129
|
for (const el of figure(next(0)?.parentNode ?? target, settings.notes, options)) {
|
|
130
130
|
assert(rev === revision);
|
|
131
131
|
el
|
|
132
132
|
? yield { type: 'figure', value: el }
|
|
133
|
-
: yield { type: 'break' };
|
|
133
|
+
: yield { type: 'break', value: 'figure' };
|
|
134
134
|
if (rev !== revision) return yield { type: 'cancel' };
|
|
135
135
|
}
|
|
136
136
|
for (const el of note(next(0)?.parentNode ?? target, settings.notes, options, bottom)) {
|
|
137
137
|
assert(rev === revision);
|
|
138
138
|
el
|
|
139
139
|
? yield { type: 'note', value: el }
|
|
140
|
-
: yield { type: 'break' };
|
|
140
|
+
: yield { type: 'break', value: 'note' };
|
|
141
141
|
if (rev !== revision) return yield { type: 'cancel' };
|
|
142
142
|
}
|
|
143
143
|
}
|
|
@@ -5,12 +5,12 @@ import { firstline, isEmptyline } from './line';
|
|
|
5
5
|
export function fence<I extends Input, S extends SubParsers<never, I>>(opener: RegExp, write: boolean, separation = true): Parser<string, I, S> {
|
|
6
6
|
assert(!opener.flags.match(/[gm]/) && opener.sticky && !opener.source.startsWith('^'));
|
|
7
7
|
return (input, output) => {
|
|
8
|
-
const { source
|
|
9
|
-
if (position === source.length) return;
|
|
10
|
-
opener.lastIndex = position;
|
|
8
|
+
const { source } = input;
|
|
9
|
+
if (input.position === source.length) return;
|
|
10
|
+
opener.lastIndex = input.position;
|
|
11
11
|
const matches = opener.exec(source);
|
|
12
12
|
if (!matches) return;
|
|
13
|
-
assert(matches[0] === firstline(source, position));
|
|
13
|
+
assert(matches[0] === firstline(source, input.position));
|
|
14
14
|
spend(input, output, matches[0].length);
|
|
15
15
|
const delim = matches[1];
|
|
16
16
|
assert(delim && delim === delim.trim());
|
|
@@ -23,37 +23,27 @@ export function fence<I extends Input, S extends SubParsers<never, I>>(opener: R
|
|
|
23
23
|
input.position -= matches[0].length;
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
+
const { position } = input;
|
|
26
27
|
let body = '';
|
|
27
28
|
let closer = '';
|
|
28
|
-
|
|
29
|
-
for (
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
assert(!overflow);
|
|
47
|
-
overflow = line;
|
|
48
|
-
}
|
|
49
|
-
if (!overflow) {
|
|
50
|
-
body += line;
|
|
51
|
-
}
|
|
52
|
-
input.position += line.length;
|
|
29
|
+
assert(matches[0].endsWith('\n'));
|
|
30
|
+
for (input.position -= 1; ;) {
|
|
31
|
+
input.position = source.indexOf(`\n${delim}`, input.position) + 1 || source.length;
|
|
32
|
+
if (!isEmptyline(source, input.position + delim.length)) continue;
|
|
33
|
+
body = source.slice(position, input.position);
|
|
34
|
+
closer = firstline(source, input.position);
|
|
35
|
+
input.position += closer.length;
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
if (separation) for (; !isEmptyline(source, input.position);) {
|
|
39
|
+
input.position = source.indexOf('\n', input.position) + 1 || source.length;
|
|
40
|
+
}
|
|
41
|
+
if (write) {
|
|
42
|
+
const overflow = source.slice(position + body.length + closer.length, input.position);
|
|
43
|
+
output.push(
|
|
44
|
+
new List([body, overflow, closer].map(str => new Node(str)))
|
|
45
|
+
.import(new List(matches.map(str => new Node(str)))));
|
|
53
46
|
}
|
|
54
|
-
write && output.push(
|
|
55
|
-
new List([body, overflow, closer].map(str => new Node(str)))
|
|
56
|
-
.import(new List(matches.map(str => new Node(str)))));
|
|
57
47
|
return output.context;
|
|
58
48
|
};
|
|
59
49
|
}
|
|
@@ -49,7 +49,7 @@ export function firstline(source: string, position: number): string {
|
|
|
49
49
|
const emptyline = /[^\S\r\n]*(?:$|\r?\n)/y;
|
|
50
50
|
export function isEmptyline(source: string, position: number): boolean {
|
|
51
51
|
emptyline.lastIndex = position;
|
|
52
|
-
return source.length
|
|
52
|
+
return position >= source.length
|
|
53
53
|
|| source[position] === '\n'
|
|
54
54
|
|| emptyline.test(source);
|
|
55
55
|
}
|
|
@@ -64,7 +64,7 @@ export const codeblock: CodeBlockParser = block(inits([
|
|
|
64
64
|
? `Invalid trailing line after the closing delimiter "${delim}"`
|
|
65
65
|
: params.invalid!),
|
|
66
66
|
},
|
|
67
|
-
`${opener}${body}${
|
|
67
|
+
`${opener}${body}${closer}${overflow}`)));
|
|
68
68
|
return;
|
|
69
69
|
}
|
|
70
70
|
const src = body.slice(0, body.at(-2) === '\r' ? -2 : -1);
|
|
@@ -30,7 +30,7 @@ export const aside: ExtensionParser.AsideParser = block(recursion(Recursion.bloc
|
|
|
30
30
|
overflow ? `Invalid trailing line after the closing delimiter "${delim}"` :
|
|
31
31
|
'Invalid argument'),
|
|
32
32
|
},
|
|
33
|
-
`${opener}${body}${
|
|
33
|
+
`${opener}${body}${closer}${overflow}`)));
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
input.memory = {
|
|
@@ -27,7 +27,7 @@ export const example: ExtensionParser.ExampleParser = block(recursion(Recursion.
|
|
|
27
27
|
overflow ? `Invalid trailing line after the closing delimiter "${delim}"` :
|
|
28
28
|
'Invalid argument'),
|
|
29
29
|
},
|
|
30
|
-
`${opener}${body}${
|
|
30
|
+
`${opener}${body}${closer}${overflow}`)));
|
|
31
31
|
switch (type) {
|
|
32
32
|
case 'markdown': {
|
|
33
33
|
input.memory = {
|
|
@@ -1,30 +1,28 @@
|
|
|
1
1
|
import { ExtensionParser } from '../../block';
|
|
2
2
|
import { Segment } from '../../context';
|
|
3
3
|
import { Result } from '../../../combinator/parser';
|
|
4
|
-
import { union, sequence, some, always,
|
|
4
|
+
import { union, sequence, some, always, block, line, rewrite, close } from '../../../combinator';
|
|
5
5
|
import { contentline } from '../../source';
|
|
6
6
|
import { figure } from './figure';
|
|
7
7
|
import { segment as seg_label } from '../../inline/extension/label';
|
|
8
8
|
import { segment as seg_code } from '../codeblock';
|
|
9
9
|
import { segment as seg_math } from '../mathblock';
|
|
10
|
-
import { segment as seg_table } from './table';
|
|
11
|
-
import { segment as seg_blockquote } from '../blockquote';
|
|
12
10
|
import { segment as seg_placeholder } from './placeholder';
|
|
11
|
+
import { segment as seg_blockquote } from '../blockquote';
|
|
13
12
|
|
|
14
13
|
import FigParser = ExtensionParser.FigParser;
|
|
15
14
|
|
|
16
|
-
export const segment: FigParser.SegmentParser =
|
|
15
|
+
export const segment: FigParser.SegmentParser = block(
|
|
17
16
|
sequence([
|
|
18
17
|
line(close(seg_label, /(?!\S)[^\r\n]*\r?\n/y), false),
|
|
19
18
|
union([
|
|
20
19
|
seg_code,
|
|
21
20
|
seg_math,
|
|
22
|
-
seg_table,
|
|
23
|
-
seg_blockquote,
|
|
24
21
|
seg_placeholder,
|
|
22
|
+
seg_blockquote,
|
|
25
23
|
some(contentline),
|
|
26
24
|
]),
|
|
27
|
-
]), true, Segment.fig)
|
|
25
|
+
]), true, Segment.fig);
|
|
28
26
|
|
|
29
27
|
export const fig: FigParser = block(rewrite(segment, always([
|
|
30
28
|
(input, output) => {
|
|
@@ -10,9 +10,9 @@ import { table as styled_table } from '../table';
|
|
|
10
10
|
import { codeblock, segment_ as seg_code } from '../codeblock';
|
|
11
11
|
import { mathblock, segment_ as seg_math } from '../mathblock';
|
|
12
12
|
import { example } from './example';
|
|
13
|
-
import { table
|
|
14
|
-
import { blockquote, segment as seg_blockquote } from '../blockquote';
|
|
13
|
+
import { table } from './table';
|
|
15
14
|
import { placeholder, segment_ as seg_placeholder } from './placeholder';
|
|
15
|
+
import { blockquote, segment as seg_blockquote } from '../blockquote';
|
|
16
16
|
import { inline, media, lineshortmedia } from '../../inline';
|
|
17
17
|
import { visualize, trimBlank } from '../../visibility';
|
|
18
18
|
import { unwrap, invalid } from '../../util';
|
|
@@ -32,9 +32,8 @@ export const segment: FigureParser.SegmentParser = block(match(
|
|
|
32
32
|
union([
|
|
33
33
|
seg_code,
|
|
34
34
|
seg_math,
|
|
35
|
-
seg_table,
|
|
36
|
-
seg_blockquote,
|
|
37
35
|
seg_placeholder,
|
|
36
|
+
seg_blockquote,
|
|
38
37
|
some(contentline, closer),
|
|
39
38
|
]),
|
|
40
39
|
emptyline,
|
|
@@ -60,8 +59,8 @@ export const figure: FigureParser = block(fallback(rewrite(segment, fmap(
|
|
|
60
59
|
mathblock,
|
|
61
60
|
example,
|
|
62
61
|
table,
|
|
63
|
-
blockquote,
|
|
64
62
|
placeholder,
|
|
63
|
+
blockquote,
|
|
65
64
|
line(media, false),
|
|
66
65
|
line(lineshortmedia, false),
|
|
67
66
|
])),
|
|
@@ -115,7 +114,7 @@ export const figure: FigureParser = block(fallback(rewrite(segment, fmap(
|
|
|
115
114
|
translate: 'no',
|
|
116
115
|
...invalid('figure', violation[0], violation[1]),
|
|
117
116
|
},
|
|
118
|
-
`${opener}${body}${
|
|
117
|
+
`${opener}${body}${closer}${overflow}`)));
|
|
119
118
|
},
|
|
120
119
|
])));
|
|
121
120
|
|
|
@@ -36,7 +36,7 @@ export const message: MessageParser = block(inits([
|
|
|
36
36
|
overflow ? `Invalid trailing line after the closing delimiter "${delim}"` :
|
|
37
37
|
'Invalid argument'),
|
|
38
38
|
},
|
|
39
|
-
`${opener}${body}${
|
|
39
|
+
`${opener}${body}${closer}${overflow}`)));
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
switch (type) {
|
|
@@ -28,6 +28,6 @@ export const placeholder: ExtensionParser.PlaceholderParser = block(inits([
|
|
|
28
28
|
overflow ? `Invalid trailing line after the closing delimiter "${delim}"` :
|
|
29
29
|
'Invalid argument'),
|
|
30
30
|
},
|
|
31
|
-
`${opener}${body}${
|
|
31
|
+
`${opener}${body}${closer}${overflow}`)));
|
|
32
32
|
},
|
|
33
33
|
]));
|
|
@@ -17,12 +17,6 @@ import CellParser = TableParser.CellParser;
|
|
|
17
17
|
|
|
18
18
|
const opener = /(~{3,})table(?:\/(\S+))?(?!\S)([^\r\n]*)(?:$|\r?\n)/y;
|
|
19
19
|
|
|
20
|
-
export const segment: TableParser.SegmentParser = block(
|
|
21
|
-
fence(opener, false));
|
|
22
|
-
|
|
23
|
-
export const segment_: TableParser.SegmentParser = block(
|
|
24
|
-
fence(opener, false, false), false);
|
|
25
|
-
|
|
26
20
|
export const table: TableParser = block(inits([
|
|
27
21
|
fence(opener, true),
|
|
28
22
|
(_, output) => {
|
|
@@ -37,7 +31,7 @@ export const table: TableParser = block(inits([
|
|
|
37
31
|
!closer ? `Missing the closing delimiter "${delim}"` :
|
|
38
32
|
overflow ? `Invalid trailing line after the closing delimiter "${delim}"` :
|
|
39
33
|
'Invalid argument'),
|
|
40
|
-
}, `${opener}${body}${
|
|
34
|
+
}, `${opener}${body}${closer}${overflow}`)));
|
|
41
35
|
switch (type) {
|
|
42
36
|
case undefined:
|
|
43
37
|
case 'grid':
|
|
@@ -2,7 +2,7 @@ import { ExtensionParser } from '../block';
|
|
|
2
2
|
import { union, lazy } from '../../combinator';
|
|
3
3
|
import { segment as seg_fig } from './extension/fig';
|
|
4
4
|
import { figure, segment as seg_figure } from './extension/figure';
|
|
5
|
-
import { table
|
|
5
|
+
import { table } from './extension/table';
|
|
6
6
|
import { message } from './extension/message';
|
|
7
7
|
import { aside } from './extension/aside';
|
|
8
8
|
import { example } from './extension/example';
|
|
@@ -11,7 +11,6 @@ import { placeholder, segment as seg_placeholder } from './extension/placeholder
|
|
|
11
11
|
export const segment: ExtensionParser.SegmentParser = union([
|
|
12
12
|
seg_fig,
|
|
13
13
|
seg_figure,
|
|
14
|
-
seg_table,
|
|
15
14
|
seg_placeholder,
|
|
16
15
|
]);
|
|
17
16
|
|
|
@@ -32,6 +32,6 @@ export const mathblock: MathBlockParser = block(inits([
|
|
|
32
32
|
overflow ? `Invalid trailing line after the closing delimiter "${delim}"` :
|
|
33
33
|
'Invalid argument'),
|
|
34
34
|
},
|
|
35
|
-
`${opener}${body}${
|
|
35
|
+
`${opener}${body}${closer}${overflow}`)));
|
|
36
36
|
},
|
|
37
37
|
]));
|
package/src/parser/context.ts
CHANGED
package/src/parser/document.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MarkdownParser } from '../../markdown';
|
|
2
2
|
import { Input, Recursion } from './context';
|
|
3
|
-
import { Parser, Node } from '../combinator/parser';
|
|
3
|
+
import { Parser, Result, Node } from '../combinator/parser';
|
|
4
4
|
import { always, force, recursion } from '../combinator';
|
|
5
5
|
import { build } from './parser';
|
|
6
6
|
import { parser as segment } from './segment';
|
|
@@ -12,8 +12,10 @@ import { frag, html } from 'typed-dom/dom';
|
|
|
12
12
|
|
|
13
13
|
export const document: MarkdownParser = (() => {
|
|
14
14
|
interface Memory {
|
|
15
|
-
readonly interpolation
|
|
15
|
+
readonly interpolation: boolean;
|
|
16
16
|
readonly references: HTMLOListElement;
|
|
17
|
+
doc?: DocumentFragment;
|
|
18
|
+
orphan?: boolean;
|
|
17
19
|
}
|
|
18
20
|
const loop = build(segment, block);
|
|
19
21
|
return always<Parser<DocumentFragment | HTMLElement, Input<Memory>>>([
|
|
@@ -22,9 +24,9 @@ export const document: MarkdownParser = (() => {
|
|
|
22
24
|
input.id === '' ? '' :
|
|
23
25
|
input.local ? randomID() :
|
|
24
26
|
input.id;
|
|
25
|
-
input.memory =
|
|
26
|
-
interpolation:
|
|
27
|
-
references: html('ol', { class: 'references' }),
|
|
27
|
+
input.memory = {
|
|
28
|
+
interpolation: !input.notes,
|
|
29
|
+
references: input.notes?.references ?? html('ol', { class: 'references' }),
|
|
28
30
|
};
|
|
29
31
|
output.push();
|
|
30
32
|
return output.context;
|
|
@@ -32,17 +34,42 @@ export const document: MarkdownParser = (() => {
|
|
|
32
34
|
recursion(Recursion.document, force(() => loop)),
|
|
33
35
|
(input, output) => {
|
|
34
36
|
assert(input.position === input.source.length);
|
|
35
|
-
const
|
|
37
|
+
const { memory } = input;
|
|
38
|
+
const doc = memory.doc = frag(unwrap(output.pop()));
|
|
36
39
|
output.append(new Node(doc));
|
|
37
40
|
assert(input.id !== '' || !doc.querySelector('[id], .index[href], .label[href], .annotation > a[href], .reference > a[href]'));
|
|
41
|
+
if (input.test && !input.local) return output.context;
|
|
42
|
+
memory.orphan = !memory.references.parentNode;
|
|
43
|
+
memory.orphan && doc.appendChild(memory.references);
|
|
44
|
+
return output.context;
|
|
45
|
+
},
|
|
46
|
+
(input, output) => {
|
|
47
|
+
if (input.test && !input.local) return output.context;
|
|
48
|
+
const { memory } = input;
|
|
49
|
+
return conv(figure(memory.doc!, memory, input));
|
|
50
|
+
},
|
|
51
|
+
(input, output) => {
|
|
38
52
|
if (input.test && !input.local) return output.context;
|
|
39
53
|
const { memory } = input;
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
orphan && !memory.interpolation && memory.references.remove();
|
|
54
|
+
return conv(note(memory.doc!, memory, input));
|
|
55
|
+
},
|
|
56
|
+
(input, output) => {
|
|
57
|
+
const { memory } = input;
|
|
58
|
+
memory.orphan && !memory.interpolation && memory.references.remove();
|
|
45
59
|
return output.context;
|
|
46
60
|
},
|
|
47
61
|
]);
|
|
48
62
|
})();
|
|
63
|
+
|
|
64
|
+
function conv<T>(iterable: Iterable<T>): Result<never> {
|
|
65
|
+
const iter = iterable[Symbol.iterator]();
|
|
66
|
+
const cont: Result<T> = [
|
|
67
|
+
(_, output) => {
|
|
68
|
+
const { done } = iter.next();
|
|
69
|
+
return done
|
|
70
|
+
? output.context
|
|
71
|
+
: cont;
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
return cont;
|
|
75
|
+
}
|
package/src/parser/repeat.ts
CHANGED
|
@@ -51,7 +51,7 @@ export function repeat<T extends HTMLElement | string>(
|
|
|
51
51
|
input.position = position;
|
|
52
52
|
return Result.skip;
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
const depth = i / opener.length + 1 | 0;
|
|
55
55
|
recur(output, recursions, recursion, depth, true);
|
|
56
56
|
input.memory = {
|
|
57
57
|
position,
|
|
@@ -94,6 +94,7 @@ export function repeat<T extends HTMLElement | string>(
|
|
|
94
94
|
const advance = input.position - pos;
|
|
95
95
|
m.i -= advance;
|
|
96
96
|
m.follow -= advance;
|
|
97
|
+
recur(output, recursions, recursion, -(advance / closer.length | 0));
|
|
97
98
|
m.depth -= advance / closer.length | 0;
|
|
98
99
|
}
|
|
99
100
|
continue;
|
|
@@ -104,7 +105,7 @@ export function repeat<T extends HTMLElement | string>(
|
|
|
104
105
|
},
|
|
105
106
|
parser,
|
|
106
107
|
(input, output) => {
|
|
107
|
-
const { source, memory: m } = input;
|
|
108
|
+
const { source, memory: m, resources: { recursions } } = input;
|
|
108
109
|
const { lead } = m;
|
|
109
110
|
input.range = input.position - m.position - m.i + opener.length;
|
|
110
111
|
if (!output.state) return;
|
|
@@ -131,6 +132,7 @@ export function repeat<T extends HTMLElement | string>(
|
|
|
131
132
|
const advance = input.position - pos;
|
|
132
133
|
m.i -= advance;
|
|
133
134
|
m.follow -= advance;
|
|
135
|
+
recur(output, recursions, recursion, -(advance / closer.length | 0));
|
|
134
136
|
m.depth -= advance / closer.length | 0;
|
|
135
137
|
}
|
|
136
138
|
m.i -= opener.length, m.follow -= closer.length;
|