securemark 0.282.0 → 0.283.1

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 (71) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/design.md +5 -9
  3. package/dist/index.js +7373 -7195
  4. package/markdown.d.ts +2 -2
  5. package/package.json +2 -2
  6. package/src/combinator/control/manipulation/convert.ts +4 -8
  7. package/src/combinator/control/manipulation/indent.ts +3 -5
  8. package/src/combinator/control/manipulation/scope.ts +6 -3
  9. package/src/combinator/control/manipulation/surround.ts +31 -7
  10. package/src/combinator/data/parser/context.test.ts +6 -6
  11. package/src/combinator/data/parser/context.ts +25 -39
  12. package/src/combinator/data/parser.ts +2 -3
  13. package/src/parser/api/bind.ts +6 -6
  14. package/src/parser/api/parse.test.ts +35 -28
  15. package/src/parser/api/parse.ts +0 -3
  16. package/src/parser/block/blockquote.ts +4 -3
  17. package/src/parser/block/dlist.test.ts +1 -1
  18. package/src/parser/block/dlist.ts +6 -6
  19. package/src/parser/block/extension/aside.ts +4 -3
  20. package/src/parser/block/extension/example.ts +4 -3
  21. package/src/parser/block/extension/table.ts +7 -7
  22. package/src/parser/block/heading.ts +3 -2
  23. package/src/parser/block/ilist.ts +2 -1
  24. package/src/parser/block/olist.ts +4 -3
  25. package/src/parser/block/reply/cite.ts +3 -3
  26. package/src/parser/block/reply/quote.ts +3 -3
  27. package/src/parser/block/sidefence.ts +2 -1
  28. package/src/parser/block/table.ts +9 -9
  29. package/src/parser/block/ulist.ts +6 -5
  30. package/src/parser/block.ts +16 -5
  31. package/src/parser/context.ts +19 -21
  32. package/src/parser/inline/annotation.test.ts +3 -1
  33. package/src/parser/inline/annotation.ts +6 -5
  34. package/src/parser/inline/autolink/email.ts +2 -1
  35. package/src/parser/inline/autolink/url.ts +6 -5
  36. package/src/parser/inline/autolink.ts +2 -2
  37. package/src/parser/inline/bracket.ts +17 -17
  38. package/src/parser/inline/code.test.ts +1 -1
  39. package/src/parser/inline/code.ts +2 -1
  40. package/src/parser/inline/deletion.ts +3 -3
  41. package/src/parser/inline/emphasis.ts +3 -3
  42. package/src/parser/inline/emstrong.ts +3 -3
  43. package/src/parser/inline/extension/index.ts +22 -10
  44. package/src/parser/inline/extension/indexee.ts +2 -2
  45. package/src/parser/inline/extension/indexer.ts +2 -1
  46. package/src/parser/inline/extension/label.ts +2 -2
  47. package/src/parser/inline/extension/placeholder.ts +4 -4
  48. package/src/parser/inline/html.ts +2 -2
  49. package/src/parser/inline/htmlentity.ts +2 -1
  50. package/src/parser/inline/insertion.ts +3 -3
  51. package/src/parser/inline/link.test.ts +2 -2
  52. package/src/parser/inline/link.ts +12 -8
  53. package/src/parser/inline/mark.ts +3 -3
  54. package/src/parser/inline/math.test.ts +3 -3
  55. package/src/parser/inline/math.ts +6 -5
  56. package/src/parser/inline/media.test.ts +1 -1
  57. package/src/parser/inline/media.ts +16 -11
  58. package/src/parser/inline/reference.test.ts +3 -0
  59. package/src/parser/inline/reference.ts +7 -6
  60. package/src/parser/inline/remark.ts +2 -2
  61. package/src/parser/inline/ruby.ts +13 -12
  62. package/src/parser/inline/strong.ts +3 -3
  63. package/src/parser/inline/template.ts +11 -9
  64. package/src/parser/inline.test.ts +1 -2
  65. package/src/parser/inline.ts +1 -0
  66. package/src/parser/source/escapable.ts +2 -1
  67. package/src/parser/source/str.ts +3 -2
  68. package/src/parser/source/text.ts +2 -1
  69. package/src/parser/source/unescapable.ts +2 -1
  70. package/src/util/quote.ts +6 -8
  71. package/src/combinator/data/parser/context/memo.ts +0 -57
@@ -1,19 +1,20 @@
1
1
  import { StrParser } from '../source';
2
2
  import { Parser, Context } from '../../combinator/data/parser';
3
3
  import { creation } from '../../combinator';
4
+ import { Recursion } from '../context';
4
5
 
5
6
  export function str(pattern: string | RegExp, not?: string): StrParser;
6
7
  export function str(pattern: string | RegExp, not?: string): Parser<string, Context<StrParser>, []> {
7
8
  assert(pattern);
8
9
  return typeof pattern === 'string'
9
- ? creation(1, false, ({ source }) => {
10
+ ? creation(1, Recursion.ignore, ({ source }) => {
10
11
  if (source === '') return;
11
12
  if (not && source.slice(pattern.length, pattern.length + not.length) === not) return;
12
13
  return source.slice(0, pattern.length) === pattern
13
14
  ? [[pattern], source.slice(pattern.length)]
14
15
  : undefined;
15
16
  })
16
- : creation(1, false, ({ source }) => {
17
+ : creation(1, Recursion.ignore, ({ source }) => {
17
18
  if (source === '') return;
18
19
  const m = source.match(pattern);
19
20
  if (m && not && source.slice(m[0].length, m[0].length + not.length) === not) return;
@@ -1,6 +1,7 @@
1
1
  import { TextParser, TxtParser, LinebreakParser } from '../source';
2
2
  import { union, creation, focus } from '../../combinator';
3
3
  import { str } from './str';
4
+ import { Recursion } from '../context';
4
5
  import { html } from 'typed-dom/dom';
5
6
 
6
7
  export const delimiter = /[\s\x00-\x7F()[]{}“”‘’「」『』]|\S[#>]/u;
@@ -8,7 +9,7 @@ export const nonWhitespace = /[\S\n]|$/u;
8
9
  export const nonAlphanumeric = /[^0-9A-Za-z]|\S[#>]|$/u;
9
10
  const repeat = str(/^(.)\1*/);
10
11
 
11
- export const text: TextParser = creation(1, false, ({ source, context }) => {
12
+ export const text: TextParser = creation(1, Recursion.ignore, ({ source, context }) => {
12
13
  if (source === '') return;
13
14
  const i = source.search(delimiter);
14
15
  switch (i) {
@@ -1,8 +1,9 @@
1
1
  import { UnescapableSourceParser } from '../source';
2
2
  import { creation } from '../../combinator';
3
3
  import { delimiter, nonWhitespace, nonAlphanumeric, isAlphanumeric } from './text';
4
+ import { Recursion } from '../context';
4
5
 
5
- export const unescsource: UnescapableSourceParser = creation(1, false, ({ source, context }) => {
6
+ export const unescsource: UnescapableSourceParser = creation(1, Recursion.ignore, ({ source, context }) => {
6
7
  assert(source[0] !== '\x1B');
7
8
  if (source === '') return;
8
9
  const i = source.search(delimiter);
package/src/util/quote.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { exec } from '../combinator/data/parser';
2
2
  import { cite } from '../parser/block/reply/cite';
3
- //import { url } from '../parser/inline/autolink/url';
4
3
 
5
4
  export function quote(anchor: string, range: Range): string {
6
5
  if (exec(cite({ source: `>>${anchor}`, context: {} })) !== '') throw new Error(`Invalid anchor: ${anchor}`);
@@ -15,13 +14,12 @@ export function quote(anchor: string, range: Range): string {
15
14
  case el.matches('.math'):
16
15
  el.replaceWith(el.getAttribute('data-src')!);
17
16
  continue;
18
- //case el.matches('.url'):
19
- // if (exec(url({ source: el.getAttribute('href')!, context: {} })) === '') continue;
20
- // el.replaceWith(
21
- // /[\s{}]/.test(el.getAttribute('href')!)
22
- // ? `{ ${el.getAttribute('href')} }`
23
- // : `{${el.getAttribute('href')}}`);
24
- // continue;
17
+ case el.matches('.url'):
18
+ el.replaceWith(
19
+ /[\s{}]/.test(el.getAttribute('href')!)
20
+ ? `{ ${el.getAttribute('href')} }`
21
+ : `{${el.getAttribute('href')}}`);
22
+ continue;
25
23
  case el.matches('.media'):
26
24
  el.replaceWith(
27
25
  /[\s{}]/.test(el.getAttribute('data-src')!)
@@ -1,57 +0,0 @@
1
- import { max } from 'spica/alias';
2
-
3
- export class Memo {
4
- constructor(
5
- public readonly targets = ~0,
6
- public readonly margin = 0,
7
- ) {
8
- }
9
- private memory: Record<number, Record<number, Record<number, readonly [unknown[], number] | readonly []>> | undefined> = {};
10
- private count = 0;
11
- private $length = 0;
12
- public get length(): number {
13
- return this.$length;
14
- }
15
- public get(
16
- position: number,
17
- syntax: number,
18
- state: number,
19
- ): readonly [unknown[], number] | readonly [] | undefined {
20
- assert(position > 0);
21
- if (this.count === 0) return;
22
- //console.log('get', position, syntax, state, this.memory[position - 1]?.[syntax]?.[state]);
23
- const cache = this.memory[position - 1]?.[syntax]?.[state];
24
- return cache?.length === 2
25
- ? [cache[0].slice(), cache[1]]
26
- : cache;
27
- }
28
- public set(
29
- position: number,
30
- syntax: number,
31
- state: number,
32
- nodes: unknown[] | undefined,
33
- offset: number,
34
- ): void {
35
- assert(position > 0);
36
- this.$length = max(this.$length, position);
37
- const record = this.memory[position - 1] ??= (++this.count, {});
38
- assert(!record[syntax]?.[state]);
39
- (record[syntax] ??= {})[state] = nodes
40
- ? [nodes.slice(), offset]
41
- : [];
42
- //console.log('set', position, syntax, state, record[syntax]?.[state]);
43
- }
44
- public resize(position: number): void {
45
- const memory = this.memory;
46
- for (let i = this.$length; i > position; this.$length = --i) {
47
- if (!(i in memory)) continue;
48
- memory[i] &&= (--this.count, undefined);
49
- }
50
- //console.log('resize', position + 1);
51
- }
52
- public clear(): void {
53
- this.memory = {};
54
- this.count = 0;
55
- this.$length = 0;
56
- }
57
- }