securemark 0.257.1 → 0.258.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/README.md +21 -8
- package/dist/index.js +1224 -611
- package/markdown.d.ts +1 -28
- package/package.json +9 -9
- package/src/combinator/control/manipulation/convert.ts +8 -4
- package/src/combinator/control/manipulation/scope.ts +10 -2
- package/src/combinator/data/parser/context/delimiter.ts +70 -0
- package/src/combinator/data/parser/context/memo.ts +30 -0
- package/src/combinator/{control/manipulation → data/parser}/context.test.ts +9 -9
- package/src/combinator/data/parser/context.ts +161 -0
- package/src/combinator/data/parser/inits.ts +1 -1
- package/src/combinator/data/parser/sequence.test.ts +1 -1
- package/src/combinator/data/parser/sequence.ts +1 -1
- package/src/combinator/data/parser/some.test.ts +1 -1
- package/src/combinator/data/parser/some.ts +14 -37
- package/src/combinator/data/parser/subsequence.test.ts +1 -1
- package/src/combinator/data/parser/union.test.ts +1 -1
- package/src/combinator/data/parser.ts +7 -47
- package/src/combinator.ts +1 -2
- package/src/parser/api/bind.ts +5 -5
- package/src/parser/api/parse.ts +3 -1
- package/src/parser/block/blockquote.ts +1 -1
- package/src/parser/block/dlist.ts +4 -10
- package/src/parser/block/extension/figure.ts +4 -3
- package/src/parser/block/extension/table.ts +2 -2
- package/src/parser/block/heading.ts +5 -13
- package/src/parser/block/ilist.ts +3 -2
- package/src/parser/block/olist.ts +10 -7
- package/src/parser/block/paragraph.ts +1 -1
- package/src/parser/block/reply/cite.ts +1 -1
- package/src/parser/block/reply/quote.ts +1 -1
- package/src/parser/block/reply.ts +1 -1
- package/src/parser/block/sidefence.ts +1 -1
- package/src/parser/block/table.test.ts +5 -0
- package/src/parser/block/table.ts +14 -13
- package/src/parser/block/ulist.ts +4 -3
- package/src/parser/block.ts +1 -1
- package/src/parser/context.ts +32 -0
- package/src/parser/header.ts +1 -1
- package/src/parser/inline/annotation.ts +9 -17
- package/src/parser/inline/autolink/email.ts +1 -1
- package/src/parser/inline/autolink/url.ts +2 -2
- package/src/parser/inline/autolink.ts +5 -3
- package/src/parser/inline/bracket.test.ts +2 -0
- package/src/parser/inline/bracket.ts +16 -15
- package/src/parser/inline/code.ts +1 -1
- package/src/parser/inline/comment.test.ts +1 -0
- package/src/parser/inline/comment.ts +4 -3
- package/src/parser/inline/deletion.ts +5 -4
- package/src/parser/inline/emphasis.ts +5 -4
- package/src/parser/inline/emstrong.ts +5 -4
- package/src/parser/inline/extension/index.ts +8 -15
- package/src/parser/inline/extension/indexee.ts +8 -10
- package/src/parser/inline/extension/indexer.ts +4 -3
- package/src/parser/inline/extension/label.ts +3 -2
- package/src/parser/inline/extension/placeholder.ts +6 -5
- package/src/parser/inline/html.ts +5 -4
- package/src/parser/inline/htmlentity.ts +1 -1
- package/src/parser/inline/insertion.ts +5 -4
- package/src/parser/inline/link.ts +12 -21
- package/src/parser/inline/mark.ts +5 -4
- package/src/parser/inline/math.ts +8 -9
- package/src/parser/inline/media.ts +8 -7
- package/src/parser/inline/reference.ts +12 -18
- package/src/parser/inline/ruby.ts +4 -3
- package/src/parser/inline/shortmedia.ts +3 -2
- package/src/parser/inline/strong.ts +5 -4
- package/src/parser/inline/template.test.ts +1 -1
- package/src/parser/inline/template.ts +9 -6
- package/src/parser/inline.test.ts +2 -0
- package/src/parser/locale.ts +6 -7
- package/src/parser/processor/footnote.ts +5 -3
- package/src/parser/source/text.ts +1 -1
- package/src/parser/util.ts +0 -220
- package/src/parser/visibility.ts +205 -0
- package/src/util/info.ts +4 -2
- package/src/util/quote.ts +12 -15
- package/src/util/toc.ts +14 -17
- package/webpack.config.js +1 -0
- package/src/combinator/control/manipulation/context.ts +0 -70
- package/src/combinator/control/manipulation/resource.ts +0 -54
package/src/util/toc.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { html } from 'typed-dom/dom';
|
|
3
|
+
import { duffEach, duffReduce } from 'spica/duff';
|
|
3
4
|
import { push } from 'spica/array';
|
|
4
5
|
|
|
5
6
|
// Bug: Firefox
|
|
@@ -7,16 +8,15 @@ import { push } from 'spica/array';
|
|
|
7
8
|
const selector = ':is(h1, h2, h3, h4, h5, h6, aside.aside)[id]';
|
|
8
9
|
|
|
9
10
|
export function toc(source: DocumentFragment | HTMLElement | ShadowRoot): HTMLUListElement {
|
|
10
|
-
const hs =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
11
|
+
const hs = duffReduce(source.querySelectorAll(selector), (acc, el) => {
|
|
12
|
+
assert(el.parentNode === source);
|
|
13
|
+
switch (el.tagName) {
|
|
14
|
+
case 'ASIDE':
|
|
15
|
+
return push(acc, [html(el.firstElementChild!.tagName.toLowerCase() as 'h1', { id: el.id, class: 'aside' }, el.firstElementChild!.cloneNode(true).childNodes)]);
|
|
16
|
+
default:
|
|
17
|
+
return push(acc, [el as HTMLHeadingElement]);
|
|
18
|
+
}
|
|
19
|
+
}, [] as HTMLHeadingElement[]);
|
|
20
20
|
return parse(cons(hs));
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -35,7 +35,7 @@ function parse(node: Tree, index: string = ''): HTMLUListElement {
|
|
|
35
35
|
: `${index}.${i}`;
|
|
36
36
|
return html('li',
|
|
37
37
|
push(
|
|
38
|
-
[html('a', { href: `#${el.id}`, 'data-index': isHeading ? idx : undefined },
|
|
38
|
+
[html('a', { href: `#${el.id}`, 'data-index': isHeading ? idx : undefined }, unlink(el.cloneNode(true)))],
|
|
39
39
|
cs.length > 0 ? [parse(cs, idx)] : []));
|
|
40
40
|
}));
|
|
41
41
|
}
|
|
@@ -57,11 +57,8 @@ function level(h: HTMLHeadingElement): number {
|
|
|
57
57
|
return +h.tagName[1];
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
function
|
|
61
|
-
h
|
|
62
|
-
|
|
63
|
-
const el = es[i];
|
|
64
|
-
el.replaceWith(...el.childNodes);
|
|
65
|
-
}
|
|
60
|
+
function unlink(h: HTMLHeadingElement): Iterable<Node> {
|
|
61
|
+
duffEach(h.getElementsByTagName('a'), el =>
|
|
62
|
+
void el.replaceWith(...el.childNodes));
|
|
66
63
|
return h.childNodes;
|
|
67
64
|
}
|
package/webpack.config.js
CHANGED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { undefined, WeakMap } from 'spica/global';
|
|
2
|
-
import { hasOwnProperty, ObjectCreate } from 'spica/alias';
|
|
3
|
-
import { Parser, Ctx, Context } from '../../data/parser';
|
|
4
|
-
import { template } from 'spica/assign';
|
|
5
|
-
import { type } from 'spica/type';
|
|
6
|
-
import { memoize } from 'spica/memoize';
|
|
7
|
-
|
|
8
|
-
export function guard<P extends Parser<unknown>>(f: (context: Context<P>) => boolean, parser: P): P;
|
|
9
|
-
export function guard<T>(f: (context: Ctx) => boolean, parser: Parser<T>): Parser<T> {
|
|
10
|
-
return (source, context) =>
|
|
11
|
-
f(context)
|
|
12
|
-
? parser(source, context)
|
|
13
|
-
: undefined;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function reset<P extends Parser<unknown>>(base: Context<P>, parser: P): P;
|
|
17
|
-
export function reset<T>(base: Ctx, parser: Parser<T>): Parser<T> {
|
|
18
|
-
assert(Object.getPrototypeOf(base) === Object.prototype);
|
|
19
|
-
assert(Object.freeze(base));
|
|
20
|
-
return (source, context) =>
|
|
21
|
-
parser(source, inherit(ObjectCreate(context), base));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function context<P extends Parser<unknown>>(base: Context<P>, parser: P): P;
|
|
25
|
-
export function context<T>(base: Ctx, parser: Parser<T>): Parser<T> {
|
|
26
|
-
assert(Object.getPrototypeOf(base) === Object.prototype);
|
|
27
|
-
assert(Object.freeze(base));
|
|
28
|
-
const override = memoize<Ctx, Ctx>(context => inherit(ObjectCreate(context), base), new WeakMap());
|
|
29
|
-
return (source, context) =>
|
|
30
|
-
parser(source, override(context));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const inherit = template((prop, target, source) => {
|
|
34
|
-
assert(!Object.isSealed(target));
|
|
35
|
-
assert(Object.isExtensible(target));
|
|
36
|
-
//assert(Object.freeze(source));
|
|
37
|
-
if (target[prop] === source[prop]) return;
|
|
38
|
-
switch (prop) {
|
|
39
|
-
case 'resources':
|
|
40
|
-
assert(typeof source[prop] === 'object');
|
|
41
|
-
assert(target[prop] || !(prop in target));
|
|
42
|
-
if (prop in target && !hasOwnProperty(target, prop)) return;
|
|
43
|
-
return target[prop] = ObjectCreate(source[prop]);
|
|
44
|
-
}
|
|
45
|
-
assert(!target.hasOwnProperty(prop));
|
|
46
|
-
switch (type(source[prop])) {
|
|
47
|
-
case 'Object':
|
|
48
|
-
assert(Object.getPrototypeOf(source[prop]) === Object.prototype);
|
|
49
|
-
//assert(Object.freeze(source[prop]));
|
|
50
|
-
switch (type(target[prop])) {
|
|
51
|
-
case 'Object':
|
|
52
|
-
return target[prop] = inherit(ObjectCreate(target[prop]), source[prop]);
|
|
53
|
-
default:
|
|
54
|
-
return target[prop] = source[prop];
|
|
55
|
-
}
|
|
56
|
-
default:
|
|
57
|
-
return target[prop] = source[prop];
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
export function precedence<P extends Parser<unknown>>(precedence: number, parser: P): P;
|
|
62
|
-
export function precedence<T>(precedence: number, parser: Parser<T>): Parser<T> {
|
|
63
|
-
return (source, context) => {
|
|
64
|
-
const p = context.precedence;
|
|
65
|
-
context.precedence = precedence;
|
|
66
|
-
const result = parser(source, context);
|
|
67
|
-
context.precedence = p;
|
|
68
|
-
return result;
|
|
69
|
-
};
|
|
70
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { Parser } from '../../data/parser';
|
|
2
|
-
|
|
3
|
-
export function creator<P extends Parser<unknown>>(parser: P): P;
|
|
4
|
-
export function creator<P extends Parser<unknown>>(cost: number, parser: P): P;
|
|
5
|
-
export function creator(cost: number | Parser<unknown>, parser?: Parser<unknown>): Parser<unknown> {
|
|
6
|
-
if (typeof cost === 'function') return creator(1, cost);
|
|
7
|
-
assert(cost >= 0);
|
|
8
|
-
return (source, context) => {
|
|
9
|
-
const { resources = { budget: 1, recursion: 1 } } = context;
|
|
10
|
-
if (resources.budget <= 0) throw new Error('Too many creations');
|
|
11
|
-
if (resources.recursion <= 0) throw new Error('Too much recursion');
|
|
12
|
-
--resources.recursion;
|
|
13
|
-
const result = parser!(source, context);
|
|
14
|
-
++resources.recursion;
|
|
15
|
-
if (result) {
|
|
16
|
-
resources.budget -= cost;
|
|
17
|
-
}
|
|
18
|
-
return result;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function uncreator<P extends Parser<unknown>>(parser: P): P;
|
|
23
|
-
export function uncreator<P extends Parser<unknown>>(cost: number, parser: P): P;
|
|
24
|
-
export function uncreator(cost: number | Parser<unknown>, parser?: Parser<unknown>): Parser<unknown> {
|
|
25
|
-
if (typeof cost === 'function') return uncreator(1, cost);
|
|
26
|
-
assert(cost >= 0);
|
|
27
|
-
return (source, context) => {
|
|
28
|
-
const { resources = { budget: 1, recursion: 1 } } = context;
|
|
29
|
-
if (resources.budget <= 0) throw new Error('Too many creations');
|
|
30
|
-
if (resources.recursion <= 0) throw new Error('Too much recursion');
|
|
31
|
-
++resources.recursion;
|
|
32
|
-
const result = parser!(source, context);
|
|
33
|
-
--resources.recursion;
|
|
34
|
-
if (result) {
|
|
35
|
-
resources.budget += cost;
|
|
36
|
-
}
|
|
37
|
-
return result;
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function recursion<P extends Parser<unknown>>(parser: P): P;
|
|
42
|
-
export function recursion<P extends Parser<unknown>>(cost: number, parser: P): P;
|
|
43
|
-
export function recursion(cost: number | Parser<unknown>, parser?: Parser<unknown>): Parser<unknown> {
|
|
44
|
-
if (typeof cost === 'function') return recursion(1, cost);
|
|
45
|
-
assert(cost >= 0);
|
|
46
|
-
return (source, context) => {
|
|
47
|
-
const { resources = { recursion: 1 } } = context;
|
|
48
|
-
if (resources.recursion <= 0) throw new Error('Too much recursion');
|
|
49
|
-
--resources.recursion;
|
|
50
|
-
const result = parser!(source, context);
|
|
51
|
-
++resources.recursion;
|
|
52
|
-
return result;
|
|
53
|
-
};
|
|
54
|
-
}
|