securemark 0.258.9 → 0.259.2

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 (145) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/design.md +6 -5
  3. package/dist/index.js +535 -278
  4. package/markdown.d.ts +4 -3
  5. package/package.json +1 -1
  6. package/src/combinator/control/constraint/block.test.ts +5 -5
  7. package/src/combinator/control/constraint/block.ts +3 -2
  8. package/src/combinator/control/constraint/contract.ts +7 -5
  9. package/src/combinator/control/constraint/line.test.ts +6 -6
  10. package/src/combinator/control/constraint/line.ts +6 -5
  11. package/src/combinator/control/manipulation/convert.ts +6 -5
  12. package/src/combinator/control/manipulation/fence.ts +2 -1
  13. package/src/combinator/control/manipulation/indent.test.ts +14 -14
  14. package/src/combinator/control/manipulation/indent.ts +5 -5
  15. package/src/combinator/control/manipulation/lazy.ts +2 -2
  16. package/src/combinator/control/manipulation/match.ts +3 -2
  17. package/src/combinator/control/manipulation/recovery.ts +6 -6
  18. package/src/combinator/control/manipulation/scope.ts +13 -10
  19. package/src/combinator/control/manipulation/surround.ts +9 -8
  20. package/src/combinator/control/manipulation/trim.test.ts +9 -9
  21. package/src/combinator/control/monad/bind.ts +3 -2
  22. package/src/combinator/data/parser/context/memo.ts +3 -4
  23. package/src/combinator/data/parser/context.test.ts +9 -9
  24. package/src/combinator/data/parser/context.ts +38 -34
  25. package/src/combinator/data/parser/inits.ts +3 -2
  26. package/src/combinator/data/parser/sequence.test.ts +10 -10
  27. package/src/combinator/data/parser/sequence.ts +3 -2
  28. package/src/combinator/data/parser/some.test.ts +13 -13
  29. package/src/combinator/data/parser/some.ts +3 -2
  30. package/src/combinator/data/parser/subsequence.test.ts +14 -14
  31. package/src/combinator/data/parser/union.test.ts +10 -10
  32. package/src/combinator/data/parser/union.ts +2 -2
  33. package/src/combinator/data/parser.ts +6 -1
  34. package/src/parser/api/bind.ts +3 -3
  35. package/src/parser/api/header.ts +1 -1
  36. package/src/parser/api/normalize.ts +1 -1
  37. package/src/parser/api/parse.ts +3 -3
  38. package/src/parser/autolink.test.ts +1 -1
  39. package/src/parser/autolink.ts +2 -2
  40. package/src/parser/block/blockquote.test.ts +1 -1
  41. package/src/parser/block/blockquote.ts +1 -1
  42. package/src/parser/block/codeblock.test.ts +1 -1
  43. package/src/parser/block/codeblock.ts +1 -1
  44. package/src/parser/block/dlist.test.ts +1 -1
  45. package/src/parser/block/extension/aside.test.ts +1 -1
  46. package/src/parser/block/extension/example.test.ts +1 -1
  47. package/src/parser/block/extension/example.ts +1 -1
  48. package/src/parser/block/extension/fig.test.ts +1 -1
  49. package/src/parser/block/extension/figbase.test.ts +1 -1
  50. package/src/parser/block/extension/figure.test.ts +1 -1
  51. package/src/parser/block/extension/figure.ts +1 -1
  52. package/src/parser/block/extension/message.test.ts +1 -1
  53. package/src/parser/block/extension/message.ts +1 -1
  54. package/src/parser/block/extension/placeholder.test.ts +1 -1
  55. package/src/parser/block/extension/table.test.ts +1 -1
  56. package/src/parser/block/extension/table.ts +1 -1
  57. package/src/parser/block/extension.test.ts +1 -1
  58. package/src/parser/block/heading.test.ts +3 -3
  59. package/src/parser/block/heading.ts +1 -1
  60. package/src/parser/block/horizontalrule.test.ts +1 -1
  61. package/src/parser/block/ilist.test.ts +1 -1
  62. package/src/parser/block/mathblock.test.ts +1 -1
  63. package/src/parser/block/olist.test.ts +1 -1
  64. package/src/parser/block/olist.ts +5 -5
  65. package/src/parser/block/paragraph.test.ts +1 -1
  66. package/src/parser/block/reply/cite.test.ts +4 -2
  67. package/src/parser/block/reply/cite.ts +2 -1
  68. package/src/parser/block/reply/quote.test.ts +1 -1
  69. package/src/parser/block/reply/quote.ts +2 -2
  70. package/src/parser/block/reply.test.ts +1 -1
  71. package/src/parser/block/sidefence.test.ts +1 -1
  72. package/src/parser/block/table.test.ts +1 -1
  73. package/src/parser/block/table.ts +1 -1
  74. package/src/parser/block/ulist.test.ts +1 -1
  75. package/src/parser/block/ulist.ts +1 -1
  76. package/src/parser/block.ts +2 -2
  77. package/src/parser/context.ts +15 -6
  78. package/src/parser/header.test.ts +1 -1
  79. package/src/parser/header.ts +3 -3
  80. package/src/parser/inline/annotation.test.ts +1 -1
  81. package/src/parser/inline/annotation.ts +3 -4
  82. package/src/parser/inline/autolink/account.test.ts +1 -1
  83. package/src/parser/inline/autolink/anchor.test.ts +1 -1
  84. package/src/parser/inline/autolink/channel.test.ts +1 -1
  85. package/src/parser/inline/autolink/email.test.ts +1 -1
  86. package/src/parser/inline/autolink/email.ts +1 -1
  87. package/src/parser/inline/autolink/hashnum.test.ts +1 -1
  88. package/src/parser/inline/autolink/hashtag.test.ts +1 -1
  89. package/src/parser/inline/autolink/url.test.ts +1 -1
  90. package/src/parser/inline/autolink.ts +1 -1
  91. package/src/parser/inline/bracket.test.ts +1 -1
  92. package/src/parser/inline/bracket.ts +8 -8
  93. package/src/parser/inline/code.test.ts +1 -1
  94. package/src/parser/inline/code.ts +2 -2
  95. package/src/parser/inline/comment.test.ts +1 -1
  96. package/src/parser/inline/comment.ts +2 -2
  97. package/src/parser/inline/deletion.test.ts +1 -1
  98. package/src/parser/inline/deletion.ts +2 -2
  99. package/src/parser/inline/emphasis.test.ts +1 -1
  100. package/src/parser/inline/emphasis.ts +2 -2
  101. package/src/parser/inline/emstrong.ts +4 -4
  102. package/src/parser/inline/escape.ts +3 -3
  103. package/src/parser/inline/extension/index.test.ts +1 -1
  104. package/src/parser/inline/extension/index.ts +3 -4
  105. package/src/parser/inline/extension/indexer.test.ts +1 -1
  106. package/src/parser/inline/extension/label.test.ts +1 -1
  107. package/src/parser/inline/extension/placeholder.test.ts +1 -1
  108. package/src/parser/inline/extension/placeholder.ts +2 -2
  109. package/src/parser/inline/html.test.ts +1 -1
  110. package/src/parser/inline/html.ts +2 -2
  111. package/src/parser/inline/htmlentity.test.ts +1 -1
  112. package/src/parser/inline/htmlentity.ts +1 -1
  113. package/src/parser/inline/insertion.test.ts +1 -1
  114. package/src/parser/inline/insertion.ts +2 -2
  115. package/src/parser/inline/link.test.ts +1 -1
  116. package/src/parser/inline/link.ts +14 -22
  117. package/src/parser/inline/mark.test.ts +1 -1
  118. package/src/parser/inline/mark.ts +2 -2
  119. package/src/parser/inline/math.test.ts +1 -1
  120. package/src/parser/inline/math.ts +1 -1
  121. package/src/parser/inline/media.test.ts +1 -1
  122. package/src/parser/inline/media.ts +3 -3
  123. package/src/parser/inline/reference.test.ts +1 -1
  124. package/src/parser/inline/reference.ts +3 -4
  125. package/src/parser/inline/ruby.test.ts +1 -1
  126. package/src/parser/inline/ruby.ts +5 -5
  127. package/src/parser/inline/shortmedia.test.ts +1 -1
  128. package/src/parser/inline/strong.test.ts +1 -1
  129. package/src/parser/inline/strong.ts +2 -2
  130. package/src/parser/inline/template.test.ts +1 -1
  131. package/src/parser/inline/template.ts +2 -2
  132. package/src/parser/inline.test.ts +1 -1
  133. package/src/parser/locale.test.ts +1 -1
  134. package/src/parser/segment.ts +1 -1
  135. package/src/parser/source/escapable.test.ts +1 -1
  136. package/src/parser/source/escapable.ts +1 -1
  137. package/src/parser/source/line.test.ts +1 -1
  138. package/src/parser/source/line.ts +2 -2
  139. package/src/parser/source/str.ts +4 -4
  140. package/src/parser/source/text.test.ts +1 -1
  141. package/src/parser/source/text.ts +4 -4
  142. package/src/parser/source/unescapable.test.ts +1 -1
  143. package/src/parser/source/unescapable.ts +1 -1
  144. package/src/parser/visibility.ts +13 -13
  145. package/src/util/quote.ts +1 -1
@@ -4,7 +4,7 @@ import { inspect } from '../debug.test';
4
4
 
5
5
  describe('Unit: parser/locale', () => {
6
6
  describe('locale', () => {
7
- const parser = (source: string) => some(block)(source, {});
7
+ const parser = (source: string) => some(block)({ source, context: {} });
8
8
 
9
9
  it('basic', () => {
10
10
  assert.deepStrictEqual(inspect(parser('。\\\n0')), [['<p>。<span class="linebreak"></span>0</p>'], '']);
@@ -26,7 +26,7 @@ export function* segment(source: string): Generator<string, undefined, undefined
26
26
  if (!validate(source, MAX_INPUT_SIZE)) return yield `\x07Too large input over ${MAX_INPUT_SIZE.toLocaleString('en')} bytes.\n${source.slice(0, 1001)}`;
27
27
  assert(source.length < Number.MAX_SAFE_INTEGER);
28
28
  while (source !== '') {
29
- const result = parser(source, {})!;
29
+ const result = parser({ source, context: {} })!;
30
30
  assert(result);
31
31
  const rest = exec(result);
32
32
  const segs = eval(result).length ? eval(result) : [source.slice(0, source.length - rest.length)];
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
4
4
 
5
5
  describe('Unit: parser/source/escsource', () => {
6
6
  describe('escsource', () => {
7
- const parser = (source: string) => some(escsource)(source, {});
7
+ const parser = (source: string) => some(escsource)({ source, context: {} });
8
8
 
9
9
  it('invalid', () => {
10
10
  assert.deepStrictEqual(inspect(parser('')), undefined);
@@ -4,7 +4,7 @@ import { nonWhitespace } from './text';
4
4
 
5
5
  const delimiter = /[\s\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]/;
6
6
 
7
- export const escsource: EscapableSourceParser = creation(source => {
7
+ export const escsource: EscapableSourceParser = creation(({ source }) => {
8
8
  if (source === '') return;
9
9
  const i = source.search(delimiter);
10
10
  switch (i) {
@@ -3,7 +3,7 @@ import { inspect } from '../../debug.test';
3
3
 
4
4
  describe('Unit: parser/source/line', () => {
5
5
  describe('contentline', () => {
6
- const parser = (source: string) => contentline(source, {});
6
+ const parser = (source: string) => contentline({ source, context: {} });
7
7
 
8
8
  it('invalid', () => {
9
9
  assert.deepStrictEqual(inspect(parser('')), undefined);
@@ -3,5 +3,5 @@ import { AnyLineParser, EmptyLineParser, ContentLineParser } from '../source';
3
3
  import { line, isEmpty } from '../../combinator';
4
4
 
5
5
  export const anyline: AnyLineParser = line(() => [[], '']);
6
- export const emptyline: EmptyLineParser = line(s => isEmpty(s) ? [[], ''] : undefined);
7
- export const contentline: ContentLineParser = line(s => !isEmpty(s) ? [[], ''] : undefined);
6
+ export const emptyline: EmptyLineParser = line(i => isEmpty(i.source) ? [[], ''] : undefined);
7
+ export const contentline: ContentLineParser = line(i => !isEmpty(i.source) ? [[], ''] : undefined);
@@ -7,13 +7,13 @@ export function str(pattern: string | RegExp): StrParser;
7
7
  export function str(pattern: string | RegExp): Parser<string, Context<StrParser>, []> {
8
8
  assert(pattern);
9
9
  return typeof pattern === 'string'
10
- ? creation(source => {
10
+ ? creation(({ source }) => {
11
11
  if (source === '') return;
12
12
  return source.slice(0, pattern.length) === pattern
13
13
  ? [[pattern], source.slice(pattern.length)]
14
14
  : undefined;
15
15
  })
16
- : creation(source => {
16
+ : creation(({ source }) => {
17
17
  if (source === '') return;
18
18
  const m = source.match(pattern);
19
19
  return m && m[0].length > 0
@@ -26,13 +26,13 @@ export function stropt(pattern: string | RegExp): StrParser;
26
26
  export function stropt(pattern: string | RegExp): Parser<string, Context<StrParser>, []> {
27
27
  assert(pattern);
28
28
  return typeof pattern === 'string'
29
- ? creation(source => {
29
+ ? creation(({ source }) => {
30
30
  if (source === '') return;
31
31
  return source.slice(0, pattern.length) === pattern
32
32
  ? [[pattern], source.slice(pattern.length)]
33
33
  : undefined;
34
34
  })
35
- : creation(source => {
35
+ : creation(({ source }) => {
36
36
  if (source === '') return;
37
37
  const m = source.match(pattern);
38
38
  return m
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
4
4
 
5
5
  describe('Unit: parser/text/text', () => {
6
6
  describe('text', () => {
7
- const parser = (source: string) => some(text)(source, {});
7
+ const parser = (source: string) => some(text)({ source, context: {} });
8
8
 
9
9
  it('invalid', () => {
10
10
  assert.deepStrictEqual(inspect(parser('')), undefined);
@@ -2,7 +2,7 @@ import { undefined } from 'spica/global';
2
2
  import { TextParser, TxtParser, LinebreakParser } from '../source';
3
3
  import { union, syntax, focus } from '../../combinator';
4
4
  import { str } from './str';
5
- import { Syntax } from '../context';
5
+ import { Syntax, State } from '../context';
6
6
  import { html } from 'typed-dom/dom';
7
7
 
8
8
  export const delimiter = /[\s\x00-\x7F]|\S[#>]|[()、。!?][^\S\n]*(?=\\\n)/;
@@ -10,7 +10,7 @@ export const nonWhitespace = /[\S\n]|$/;
10
10
  export const nonAlphanumeric = /[^0-9A-Za-z]|\S[#>]|$/;
11
11
  const repeat = str(/^(.)\1*/);
12
12
 
13
- export const text: TextParser = syntax(Syntax.none, 1, 1, (source, context) => {
13
+ export const text: TextParser = syntax(Syntax.none, 1, 1, State.none, ({ source, context }) => {
14
14
  if (source === '') return;
15
15
  const i = source.search(delimiter);
16
16
  switch (i) {
@@ -26,7 +26,7 @@ export const text: TextParser = syntax(Syntax.none, 1, 1, (source, context) => {
26
26
  case '!':
27
27
  case '?':
28
28
  assert(source[0] !== '\x1B');
29
- return text(source.slice(1), context);
29
+ return text({ source: source.slice(1), context });
30
30
  }
31
31
  break;
32
32
  case '、':
@@ -57,7 +57,7 @@ export const text: TextParser = syntax(Syntax.none, 1, 1, (source, context) => {
57
57
  case '=':
58
58
  case '`':
59
59
  return source[1] === source[0]
60
- ? repeat(source, context)
60
+ ? repeat({ source, context })
61
61
  : [[source[0]], source.slice(1)];
62
62
  default:
63
63
  assert(source[0] !== '\n');
@@ -4,7 +4,7 @@ import { inspect } from '../../debug.test';
4
4
 
5
5
  describe('Unit: parser/source/unescapable', () => {
6
6
  describe('unescsource', () => {
7
- const parser = (source: string) => some(unescsource)(source, {});
7
+ const parser = (source: string) => some(unescsource)({ source, context: {} });
8
8
 
9
9
  it('invalid', () => {
10
10
  assert.deepStrictEqual(inspect(parser('')), undefined);
@@ -2,7 +2,7 @@ import { UnescapableSourceParser } from '../source';
2
2
  import { creation } from '../../combinator';
3
3
  import { delimiter, nonWhitespace, nonAlphanumeric, isAlphanumeric } from './text';
4
4
 
5
- export const unescsource: UnescapableSourceParser = creation(source => {
5
+ export const unescsource: UnescapableSourceParser = creation(({ source }) => {
6
6
  assert(source[0] !== '\x1B');
7
7
  if (source === '') return;
8
8
  const i = source.search(delimiter);
@@ -1,6 +1,6 @@
1
1
  import { undefined } from 'spica/global';
2
2
  import { MarkdownParser } from '../../markdown';
3
- import { Parser, eval } from '../combinator/data/parser';
3
+ import { Parser, Input, eval } from '../combinator/data/parser';
4
4
  import { union, some, verify, convert, fmap } from '../combinator';
5
5
  import { unsafehtmlentity } from './inline/htmlentity';
6
6
  import { linebreak, unescsource } from './source';
@@ -56,23 +56,23 @@ export function blankWith(starting: '' | '\n', delimiter?: string | RegExp): Reg
56
56
 
57
57
  export function startLoose<P extends Parser<HTMLElement | string>>(parser: P, except?: string): P;
58
58
  export function startLoose<T extends HTMLElement | string>(parser: Parser<T>, except?: string): Parser<T> {
59
- return (source, context) =>
60
- isStartLoose(source, context, except)
61
- ? parser(source, context)
59
+ return input =>
60
+ isStartLoose(input, except)
61
+ ? parser(input)
62
62
  : undefined;
63
63
  }
64
- const isStartLoose = reduce((source: string, context: MarkdownParser.Context, except?: string): boolean => {
65
- return isStartTight(source.replace(regBlankStart, ''), context, except);
66
- }, (source, _, except = '') => `${source}\x1E${except}`);
64
+ const isStartLoose = reduce(({ source, context }: Input<MarkdownParser.Context>, except?: string): boolean => {
65
+ return isStartTight({ source: source.replace(regBlankStart, ''), context }, except);
66
+ }, ({ source }, except = '') => `${source}\x1E${except}`);
67
67
 
68
68
  export function startTight<P extends Parser<unknown>>(parser: P, except?: string): P;
69
69
  export function startTight<T>(parser: Parser<T>, except?: string): Parser<T> {
70
- return (source, context) =>
71
- isStartTight(source, context, except)
72
- ? parser(source, context)
70
+ return input =>
71
+ isStartTight(input, except)
72
+ ? parser(input)
73
73
  : undefined;
74
74
  }
75
- const isStartTight = reduce((source: string, context: MarkdownParser.Context, except?: string): boolean => {
75
+ const isStartTight = reduce(({ source, context }: Input<MarkdownParser.Context>, except?: string): boolean => {
76
76
  if (source === '') return true;
77
77
  if (except && source.slice(0, except.length) === except) return false;
78
78
  switch (source[0]) {
@@ -87,7 +87,7 @@ const isStartTight = reduce((source: string, context: MarkdownParser.Context, ex
87
87
  switch (true) {
88
88
  case source.length > 2
89
89
  && source[1] !== ' '
90
- && eval(unsafehtmlentity(source, context))?.[0]?.trimStart() === '':
90
+ && eval(unsafehtmlentity({ source, context }))?.[0]?.trimStart() === '':
91
91
  return false;
92
92
  }
93
93
  return true;
@@ -102,7 +102,7 @@ const isStartTight = reduce((source: string, context: MarkdownParser.Context, ex
102
102
  default:
103
103
  return source[0].trimStart() !== '';
104
104
  }
105
- }, (source, _, except = '') => `${source}\x1E${except}`);
105
+ }, ({ source }, except = '') => `${source}\x1E${except}`);
106
106
 
107
107
  export function isStartLooseNodes(nodes: readonly (HTMLElement | string)[]): boolean {
108
108
  if (nodes.length === 0) return true;
package/src/util/quote.ts CHANGED
@@ -5,7 +5,7 @@ import { define } from 'typed-dom/dom';
5
5
  import { duffEach } from 'spica/duff';
6
6
 
7
7
  export function quote(anchor: string, range: Range): string {
8
- if (exec(cite(`>>${anchor}`, {})) !== '') throw new Error(`Invalid anchor: ${anchor}`);
8
+ if (exec(cite({ source: `>>${anchor}`, context: {} })) !== '') throw new Error(`Invalid anchor: ${anchor}`);
9
9
  fit(range);
10
10
  const node = trim(range.cloneContents());
11
11
  if (!node.firstChild) return '';