securemark 0.300.2 → 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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.300.3
4
+
5
+ - Refactoring.
6
+
3
7
  ## 0.300.2
4
8
 
5
9
  - Refactoring.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! securemark v0.300.2 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
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"));
@@ -6355,7 +6355,7 @@ class Input extends parser_1.Input {
6355
6355
  this.resources ??= {
6356
6356
  clock: -1,
6357
6357
  interval: 200,
6358
- recursions: [10 || 0 /* Recursion.document */, 100 || 0 /* Recursion.block */, 100 || 0 /* Recursion.inline */, 100 || 0 /* Recursion.bracket */]
6358
+ recursions: [20 || 0 /* Recursion.document */, 100 || 0 /* Recursion.block */, 100 || 0 /* Recursion.inline */, 100 || 0 /* Recursion.bracket */]
6359
6359
  };
6360
6360
  this.segment = segment ?? 0 /* Segment.unknown */;
6361
6361
  this.header = header ?? true;
@@ -6413,29 +6413,54 @@ exports.document = (() => {
6413
6413
  const loop = (0, parser_2.build)(segment_1.parser, block_1.block);
6414
6414
  return (0, combinator_1.always)([(input, output) => {
6415
6415
  input.id = input.id === '' ? '' : input.local ? (0, util_1.randomID)() : input.id;
6416
- input.memory = input.notes ?? {
6417
- interpolation: true,
6418
- references: (0, dom_1.html)('ol', {
6416
+ input.memory = {
6417
+ interpolation: !input.notes,
6418
+ references: input.notes?.references ?? (0, dom_1.html)('ol', {
6419
6419
  class: 'references'
6420
6420
  })
6421
6421
  };
6422
6422
  output.push();
6423
6423
  return output.context;
6424
6424
  }, (0, combinator_1.recursion)(0 /* Recursion.document */, (0, combinator_1.force)(() => loop)), (input, output) => {
6425
- const doc = (0, dom_1.frag)((0, util_1.unwrap)(output.pop()));
6425
+ const {
6426
+ memory
6427
+ } = input;
6428
+ const doc = memory.doc = (0, dom_1.frag)((0, util_1.unwrap)(output.pop()));
6426
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) => {
6427
6441
  if (input.test && !input.local) return output.context;
6428
6442
  const {
6429
6443
  memory
6430
6444
  } = input;
6431
- const orphan = !memory.references.parentNode;
6432
- orphan && doc.appendChild(memory.references);
6433
- for (const _ of (0, figure_1.figure)(doc, memory, input));
6434
- for (const _ of (0, note_1.note)(doc, memory, input));
6435
- orphan && !memory.interpolation && memory.references.remove();
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();
6436
6451
  return output.context;
6437
6452
  }]);
6438
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
+ }
6439
6464
 
6440
6465
  /***/ },
6441
6466
 
@@ -8581,7 +8606,7 @@ function repeat(opener, after, closer, recursion, parser, cons, termination = (n
8581
8606
  input.position = position;
8582
8607
  return parser_1.Result.skip;
8583
8608
  }
8584
- let depth = i / opener.length + 1 | 0;
8609
+ const depth = i / opener.length + 1 | 0;
8585
8610
  (0, combinator_1.recur)(output, recursions, recursion, depth, true);
8586
8611
  input.memory = {
8587
8612
  position,
@@ -8633,6 +8658,7 @@ function repeat(opener, after, closer, recursion, parser, cons, termination = (n
8633
8658
  const advance = input.position - pos;
8634
8659
  m.i -= advance;
8635
8660
  m.follow -= advance;
8661
+ (0, combinator_1.recur)(output, recursions, recursion, -(advance / closer.length | 0));
8636
8662
  m.depth -= advance / closer.length | 0;
8637
8663
  }
8638
8664
  continue;
@@ -8643,7 +8669,10 @@ function repeat(opener, after, closer, recursion, parser, cons, termination = (n
8643
8669
  }, parser, (input, output) => {
8644
8670
  const {
8645
8671
  source,
8646
- memory: m
8672
+ memory: m,
8673
+ resources: {
8674
+ recursions
8675
+ }
8647
8676
  } = input;
8648
8677
  const {
8649
8678
  lead
@@ -8671,6 +8700,7 @@ function repeat(opener, after, closer, recursion, parser, cons, termination = (n
8671
8700
  const advance = input.position - pos;
8672
8701
  m.i -= advance;
8673
8702
  m.follow -= advance;
8703
+ (0, combinator_1.recur)(output, recursions, recursion, -(advance / closer.length | 0));
8674
8704
  m.depth -= advance / closer.length | 0;
8675
8705
  }
8676
8706
  m.i -= opener.length, m.follow -= closer.length;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.300.2",
3
+ "version": "0.300.3",
4
4
  "description": "Secure markdown renderer working on browsers for user input data.",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/falsandtru/securemark",
@@ -28,7 +28,7 @@ export class Input<M extends object = object> extends Ipt<M> {
28
28
  clock: -1,
29
29
  interval: 200,
30
30
  recursions: [
31
- 10 || Recursion.document,
31
+ 20 || Recursion.document,
32
32
  100 || Recursion.block,
33
33
  100 || Recursion.inline,
34
34
  100 || Recursion.bracket,
@@ -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?: boolean;
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 = input.notes ?? {
26
- interpolation: true,
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 doc = frag(unwrap(output.pop()));
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
- const orphan = !memory.references.parentNode;
41
- orphan && doc.appendChild(memory.references);
42
- for (const _ of figure(doc, memory, input));
43
- for (const _ of note(doc, memory, input));
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
+ }
@@ -51,7 +51,7 @@ export function repeat<T extends HTMLElement | string>(
51
51
  input.position = position;
52
52
  return Result.skip;
53
53
  }
54
- let depth = i / opener.length + 1 | 0;
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;