securemark 0.289.2 → 0.289.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/design.md +2 -1
  3. package/dist/index.js +94 -78
  4. package/package.json +1 -1
  5. package/src/combinator/control/constraint/block.ts +1 -1
  6. package/src/combinator/control/constraint/contract.ts +7 -7
  7. package/src/combinator/control/constraint/line.ts +1 -1
  8. package/src/combinator/control/manipulation/clear.ts +7 -0
  9. package/src/combinator/control/manipulation/convert.ts +1 -1
  10. package/src/combinator/control/manipulation/duplicate.ts +4 -4
  11. package/src/combinator/control/manipulation/fallback.ts +3 -3
  12. package/src/combinator/control/manipulation/indent.ts +3 -3
  13. package/src/combinator/control/manipulation/lazy.ts +2 -2
  14. package/src/combinator/control/manipulation/match.ts +1 -1
  15. package/src/combinator/control/manipulation/recovery.ts +3 -3
  16. package/src/combinator/control/manipulation/reverse.ts +1 -1
  17. package/src/combinator/control/manipulation/scope.ts +3 -3
  18. package/src/combinator/control/manipulation/surround.ts +59 -61
  19. package/src/combinator/control/manipulation/trim.ts +3 -3
  20. package/src/combinator/control/monad/bind.ts +6 -6
  21. package/src/combinator/control/monad/fmap.ts +6 -6
  22. package/src/combinator/data/parser/context/delimiter.ts +21 -19
  23. package/src/combinator/data/parser/context.ts +8 -8
  24. package/src/combinator/data/parser/inits.ts +4 -4
  25. package/src/combinator/data/parser/sequence.ts +4 -4
  26. package/src/combinator/data/parser/some.ts +3 -3
  27. package/src/combinator/data/parser/subsequence.ts +3 -3
  28. package/src/combinator/data/parser/tails.ts +3 -3
  29. package/src/combinator/data/parser/union.ts +3 -3
  30. package/src/combinator/data/parser.ts +13 -13
  31. package/src/combinator.ts +1 -0
  32. package/src/parser/block/extension/figure.ts +1 -1
  33. package/src/parser/block/extension/table.ts +3 -3
  34. package/src/parser/block/olist.ts +4 -4
  35. package/src/parser/block/reply/cite.ts +3 -3
  36. package/src/parser/block/ulist.ts +1 -1
  37. package/src/parser/inline/autolink/hashnum.ts +5 -1
  38. package/src/parser/inline/code.ts +2 -1
  39. package/src/parser/inline/extension/label.ts +1 -1
  40. package/src/parser/util.ts +10 -10
  41. package/src/parser/visibility.ts +11 -11
  42. package/src/util/quote.ts +1 -1
@@ -24,10 +24,10 @@ export const olist: OListParser = lazy(() => block(validate(
24
24
  export const olist_: OListParser = lazy(() => block(union([
25
25
  match(
26
26
  openers['.'],
27
- memoize(ms => list(type(ms[1]), '.'), ms => idx(ms[1]), []), false),
27
+ memoize(ms => list(type(ms[1]), '.'), ms => idx(ms[1]), [])),
28
28
  match(
29
29
  openers['('],
30
- memoize(ms => list(type(ms[1]), '('), ms => idx(ms[1]), []), false),
30
+ memoize(ms => list(type(ms[1]), '('), ms => idx(ms[1]), [])),
31
31
  ])));
32
32
 
33
33
  const list = (type: string, form: string): OListParser.ListParser => fmap(
@@ -47,10 +47,10 @@ const list = (type: string, form: string): OListParser.ListParser => fmap(
47
47
  const heads = {
48
48
  '.': focus(
49
49
  openers['.'],
50
- ({ source }) => [[source.trimEnd().split('.', 1)[0] + '.'], ''], false),
50
+ ({ source }) => [[source.trimEnd().split('.', 1)[0] + '.'], '']),
51
51
  '(': focus(
52
52
  openers['('],
53
- ({ source }) => [[source.trimEnd().replace(/^\($/, '(1)').replace(/^\((\w+)$/, '($1)')], ''], false),
53
+ ({ source }) => [[source.trimEnd().replace(/^\($/, '(1)').replace(/^\((\w+)$/, '($1)')], '']),
54
54
  } as const;
55
55
 
56
56
  function idx(value: string): number {
@@ -15,9 +15,9 @@ export const cite: ReplyParser.CiteParser = line(fmap(validate(
15
15
  anchor,
16
16
  // Subject page representation.
17
17
  // リンクの実装は後で検討
18
- focus(/^>>#\S*(?=\s*$)/, ({ source }) => [[html('a', { class: 'anchor' }, source)], ''], false),
19
- focus(/^>>https?:\/\/\S+(?=\s*$)/, ({ source }) => [[html('a', { class: 'anchor', href: source.slice(2).trimEnd(), target: '_blank' }, source)], ''], false),
20
- focus(/^>>.+(?=\s*$)/, ({ source }) => [[source], ''], false),
18
+ focus(/^>>#\S*(?=\s*$)/, ({ source }) => [[html('a', { class: 'anchor' }, source)], '']),
19
+ focus(/^>>https?:\/\/\S+(?=\s*$)/, ({ source }) => [[html('a', { class: 'anchor', href: source.slice(2).trimEnd(), target: '_blank' }, source)], '']),
20
+ focus(/^>>.+(?=\s*$)/, ({ source }) => [[source], '']),
21
21
  ]),
22
22
  )),
23
23
  ([quotes, node]: [string, HTMLElement | string]) => [
@@ -33,7 +33,7 @@ export const checkbox = focus(
33
33
  /^\[[xX ]\](?=$|\s)/,
34
34
  ({ source }) => [[
35
35
  html('span', { class: 'checkbox' }, source[1].trimStart() ? '☑' : '☐'),
36
- ], ''], false);
36
+ ], '']);
37
37
 
38
38
  export function fillFirstLine(ns: (HTMLElement | string)[]): (HTMLElement | string)[] {
39
39
  return ns.length === 1
@@ -7,7 +7,11 @@ import { str } from '../../source';
7
7
  import { define } from 'typed-dom/dom';
8
8
 
9
9
  export const hashnum: AutolinkParser.HashnumParser = lazy(() => rewrite(
10
- open('#', str(new RegExp(/^[0-9]{1,9}(?![^\p{C}\p{S}\p{P}\s]|emoji)/u.source.replace(/emoji/, emoji), 'u'))),
10
+ open(
11
+ '#',
12
+ str(new RegExp([
13
+ /^[0-9]{1,9}(?![^\p{C}\p{S}\p{P}\s]|emoji)/u.source,
14
+ ].join('').replace(/emoji/, emoji), 'u'))),
11
15
  union([
12
16
  constraint(State.autolink, false, state(State.autolink, fmap(convert(
13
17
  source => `[${source}]{ ${source.slice(1)} }`,
@@ -5,7 +5,8 @@ import { html } from 'typed-dom/dom';
5
5
  export const code: CodeParser = match(
6
6
  /^(`+)(?!`)([^\n]*?[^`\n])\1(?!`)/,
7
7
  ([whole, , body]) => ({ source }) =>
8
- [[html('code', { 'data-src': whole }, format(body))], source.slice(whole.length)]);
8
+ [[html('code', { 'data-src': whole }, format(body))], source.slice(whole.length)],
9
+ true);
9
10
 
10
11
  function format(text: string): string {
11
12
  assert(text.length > 0);
@@ -1,6 +1,6 @@
1
1
  import { ExtensionParser } from '../../inline';
2
2
  import { State, Backtrack } from '../../context';
3
- import { union, constraint, surround, clear, fmap } from '../../../combinator';
3
+ import { union, constraint, clear, surround, fmap } from '../../../combinator';
4
4
  import { str } from '../../source';
5
5
  import { html } from 'typed-dom/dom';
6
6
 
@@ -1,19 +1,19 @@
1
1
  import { min } from 'spica/alias';
2
2
  import { Command } from './context';
3
- import { Parser, Result, Ctx, Tree, Context, eval, exec } from '../combinator/data/parser';
3
+ import { Parser, Result, Ctx, Node, Context, eval, exec } from '../combinator/data/parser';
4
4
  import { convert } from '../combinator';
5
5
  import { define } from 'typed-dom/dom';
6
6
 
7
7
  export function lineable<P extends Parser<HTMLElement | string>>(parser: P, fillTrailingLinebreak?: boolean): P;
8
- export function lineable<T extends HTMLElement | string>(parser: Parser<T>, fillTrailingLinebreak = false): Parser<T> {
8
+ export function lineable<N extends HTMLElement | string>(parser: Parser<N>, fillTrailingLinebreak = false): Parser<N> {
9
9
  return convert(
10
10
  source => `\r${source}${fillTrailingLinebreak && source.at(-1) !== '\n' ? '\n' : ''}`,
11
11
  parser,
12
12
  !fillTrailingLinebreak);
13
13
  }
14
14
 
15
- export function repeat<P extends Parser<HTMLElement | string>>(symbol: string, parser: P, cons: (nodes: Tree<P>[], context: Context<P>) => Tree<P>[], termination?: (acc: Tree<P>[][], rest: string, prefix: number, postfix: number, state: boolean) => Result<string | Tree<P>>): P;
16
- export function repeat<T extends HTMLElement | string>(symbol: string, parser: Parser<T>, cons: (nodes: T[], context: Ctx) => T[], termination: (acc: T[][], rest: string, prefix: number, postfix: number, state: boolean) => Result<string | T> = (acc, rest, prefix, postfix) => {
15
+ export function repeat<P extends Parser<HTMLElement | string>>(symbol: string, parser: P, cons: (nodes: Node<P>[], context: Context<P>) => Node<P>[], termination?: (acc: Node<P>[][], rest: string, prefix: number, postfix: number, state: boolean) => Result<string | Node<P>>): P;
16
+ export function repeat<N extends HTMLElement | string>(symbol: string, parser: Parser<N>, cons: (nodes: N[], context: Ctx) => N[], termination: (acc: N[][], rest: string, prefix: number, postfix: number, state: boolean) => Result<string | N> = (acc, rest, prefix, postfix) => {
17
17
  const nodes = [];
18
18
  if (prefix > 0) {
19
19
  nodes.push(symbol[0].repeat(prefix));
@@ -26,11 +26,11 @@ export function repeat<T extends HTMLElement | string>(symbol: string, parser: P
26
26
  rest = rest.slice(postfix);
27
27
  }
28
28
  return [nodes, rest];
29
- }): Parser<string | T> {
29
+ }): Parser<string | N> {
30
30
  return input => {
31
31
  const { source, context } = input;
32
32
  assert(source.startsWith(symbol));
33
- let acc: T[][] = [];
33
+ let acc: N[][] = [];
34
34
  let i = symbol.length;
35
35
  while (source[i] === source[0]) ++i;
36
36
  let rest = source.slice(i);
@@ -87,12 +87,12 @@ export function invalid(
87
87
  };
88
88
  }
89
89
 
90
- export function markInvalid<T extends Element>(
91
- el: T,
90
+ export function markInvalid<N extends HTMLElement>(
91
+ el: N,
92
92
  syntax: string,
93
93
  type: string,
94
94
  message: string,
95
- ): T {
95
+ ): N {
96
96
  assert(!message.endsWith('.'));
97
97
  return define(el, {
98
98
  class: void el.classList.add('invalid'),
@@ -102,7 +102,7 @@ export function markInvalid<T extends Element>(
102
102
  });
103
103
  }
104
104
 
105
- export function unmarkInvalid<T extends Element>(el: T): T {
105
+ export function unmarkInvalid<N extends HTMLElement>(el: N): N {
106
106
  return define(el, {
107
107
  class: void el.classList.remove('invalid'),
108
108
  'data-invalid-syntax': null,
@@ -18,7 +18,7 @@ export namespace blank {
18
18
  }
19
19
 
20
20
  export function visualize<P extends Parser<HTMLElement | string>>(parser: P): P;
21
- export function visualize<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
21
+ export function visualize<N extends HTMLElement | string>(parser: Parser<N>): Parser<N> {
22
22
  return union([
23
23
  convert(
24
24
  source => source.replace(blank.line, line => line.replace(/[\\&<]/g, `${Command.Escape}$&`)),
@@ -60,7 +60,7 @@ export function blankWith(starts: '' | '\n', delimiter?: string | RegExp): RegEx
60
60
  }
61
61
 
62
62
  //export function looseStart<P extends Parser<HTMLElement | string>>(parser: P, except?: string): P;
63
- //export function looseStart<T extends HTMLElement | string>(parser: Parser<T>, except?: string): Parser<T> {
63
+ //export function looseStart<N extends HTMLElement | string>(parser: Parser<N>, except?: string): Parser<N> {
64
64
  // return input =>
65
65
  // isLooseStart(input, except)
66
66
  // ? parser(input)
@@ -71,7 +71,7 @@ export function blankWith(starts: '' | '\n', delimiter?: string | RegExp): RegEx
71
71
  //}, ({ source }, except = '') => `${source}${Command.Separator}${except}`);
72
72
 
73
73
  export function tightStart<P extends Parser<unknown>>(parser: P, except?: string): P;
74
- export function tightStart<T>(parser: Parser<T>, except?: string): Parser<T> {
74
+ export function tightStart<N>(parser: Parser<N>, except?: string): Parser<N> {
75
75
  return input =>
76
76
  isTightStart(input, except)
77
77
  ? parser(input)
@@ -155,31 +155,31 @@ function isVisible(node: HTMLElement | string, strpos?: number): boolean {
155
155
 
156
156
  // デフラグ前の非効率な後方トリムを避けるため必要のない限りtrimBlankStart+trimNodeEndで処理する。
157
157
  export function trimBlank<P extends Parser<HTMLElement | string>>(parser: P): P;
158
- export function trimBlank<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
158
+ export function trimBlank<N extends HTMLElement | string>(parser: Parser<N>): Parser<N> {
159
159
  return trimBlankStart(trimBlankEnd(parser));
160
160
  }
161
161
  export function trimBlankStart<P extends Parser<unknown>>(parser: P): P;
162
- export function trimBlankStart<T>(parser: Parser<T>): Parser<T> {
162
+ export function trimBlankStart<N>(parser: Parser<N>): Parser<N> {
163
163
  return convert(
164
164
  source => source.replace(blank.start, ''),
165
165
  parser,
166
166
  true);
167
167
  }
168
168
  export function trimBlankEnd<P extends Parser<HTMLElement | string>>(parser: P): P;
169
- export function trimBlankEnd<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
169
+ export function trimBlankEnd<N extends HTMLElement | string>(parser: Parser<N>): Parser<N> {
170
170
  return fmap(
171
171
  parser,
172
172
  trimBlankNodeEnd);
173
173
  }
174
- //export function trimBlankNode<T extends HTMLElement | string>(nodes: T[]): T[] {
174
+ //export function trimBlankNode<N extends HTMLElement | string>(nodes: N[]): N[] {
175
175
  // return trimBlankNodeStart(trimBlankNodeEnd(nodes));
176
176
  //}
177
- //function trimBlankNodeStart<T extends HTMLElement | string>(nodes: T[]): T[] {
177
+ //function trimBlankNodeStart<N extends HTMLElement | string>(nodes: N[]): N[] {
178
178
  // for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[0], 0);) {
179
179
  // if (typeof node === 'string') {
180
180
  // const pos = node.trimStart().length;
181
181
  // if (pos > 0) {
182
- // nodes[0] = node.slice(-pos) as T;
182
+ // nodes[0] = node.slice(-pos) as N;
183
183
  // break;
184
184
  // }
185
185
  // }
@@ -190,7 +190,7 @@ export function trimBlankEnd<T extends HTMLElement | string>(parser: Parser<T>):
190
190
  // }
191
191
  // return nodes;
192
192
  //}
193
- export function trimBlankNodeEnd<T extends HTMLElement | string>(nodes: T[]): T[] {
193
+ export function trimBlankNodeEnd<N extends HTMLElement | string>(nodes: N[]): N[] {
194
194
  const skip = nodes.length > 0 &&
195
195
  typeof nodes.at(-1) === 'object' &&
196
196
  nodes.at(-1)!['className'] === 'indexer'
@@ -200,7 +200,7 @@ export function trimBlankNodeEnd<T extends HTMLElement | string>(nodes: T[]): T[
200
200
  if (typeof node === 'string') {
201
201
  const len = node.trimEnd().length;
202
202
  if (len > 0) {
203
- nodes[nodes.length - 1] = node.slice(0, len) as T;
203
+ nodes[nodes.length - 1] = node.slice(0, len) as N;
204
204
  break;
205
205
  }
206
206
  }
package/src/util/quote.ts CHANGED
@@ -82,7 +82,7 @@ function fit(range: Range): void {
82
82
  }
83
83
  }
84
84
 
85
- function trim<T extends Node>(node: T): T {
85
+ function trim<N extends Node>(node: N): N {
86
86
  for (let child: ChildNode & Node | null; child = node.firstChild;) {
87
87
  if (child.textContent) break;
88
88
  child.remove();