securemark 0.293.0 → 0.293.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 (66) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/index.js +254 -193
  3. package/markdown.d.ts +13 -21
  4. package/package.json +1 -1
  5. package/src/combinator/control/manipulation/scope.ts +3 -4
  6. package/src/combinator/data/parser/context.ts +5 -5
  7. package/src/combinator.ts +0 -1
  8. package/src/parser/api/parse.test.ts +2 -2
  9. package/src/parser/autolink.test.ts +7 -7
  10. package/src/parser/block/blockquote.ts +2 -2
  11. package/src/parser/block/codeblock.ts +7 -7
  12. package/src/parser/block/dlist.ts +1 -2
  13. package/src/parser/block/extension/aside.ts +3 -3
  14. package/src/parser/block/extension/example.ts +3 -3
  15. package/src/parser/block/extension/fig.ts +2 -2
  16. package/src/parser/block/extension/figure.test.ts +1 -1
  17. package/src/parser/block/extension/figure.ts +2 -2
  18. package/src/parser/block/extension/message.ts +3 -3
  19. package/src/parser/block/extension/placeholder.ts +7 -7
  20. package/src/parser/block/extension/table.ts +26 -16
  21. package/src/parser/block/extension.ts +3 -3
  22. package/src/parser/block/ilist.ts +3 -3
  23. package/src/parser/block/mathblock.ts +7 -7
  24. package/src/parser/block/mediablock.ts +6 -6
  25. package/src/parser/block/olist.ts +3 -3
  26. package/src/parser/block/paragraph.test.ts +1 -2
  27. package/src/parser/block/paragraph.ts +1 -2
  28. package/src/parser/block/reply/cite.ts +3 -5
  29. package/src/parser/block/reply/quote.ts +2 -3
  30. package/src/parser/block/sidefence.ts +2 -2
  31. package/src/parser/block/table.ts +5 -5
  32. package/src/parser/block/ulist.ts +2 -3
  33. package/src/parser/block.ts +2 -2
  34. package/src/parser/context.ts +4 -4
  35. package/src/parser/inline/annotation.ts +1 -1
  36. package/src/parser/inline/autolink/url.test.ts +7 -7
  37. package/src/parser/inline/autolink/url.ts +1 -2
  38. package/src/parser/inline/autolink.ts +1 -1
  39. package/src/parser/inline/bracket.test.ts +2 -2
  40. package/src/parser/inline/extension/index.ts +5 -4
  41. package/src/parser/inline/extension/indexer.test.ts +0 -1
  42. package/src/parser/inline/extension/indexer.ts +1 -1
  43. package/src/parser/inline/html.ts +7 -6
  44. package/src/parser/inline/htmlentity.ts +3 -3
  45. package/src/parser/inline/italic.test.ts +11 -11
  46. package/src/parser/inline/link.ts +1 -6
  47. package/src/parser/inline/mark.test.ts +5 -5
  48. package/src/parser/inline/math.ts +3 -3
  49. package/src/parser/inline/media.ts +3 -8
  50. package/src/parser/inline/reference.ts +1 -1
  51. package/src/parser/inline/remark.test.ts +14 -18
  52. package/src/parser/inline/remark.ts +17 -19
  53. package/src/parser/inline/ruby.ts +3 -3
  54. package/src/parser/inline/shortmedia.ts +1 -1
  55. package/src/parser/inline.test.ts +25 -24
  56. package/src/parser/inline.ts +21 -9
  57. package/src/parser/segment.ts +23 -5
  58. package/src/parser/source/escapable.test.ts +1 -1
  59. package/src/parser/source/escapable.ts +4 -12
  60. package/src/parser/source/text.test.ts +40 -40
  61. package/src/parser/source/text.ts +77 -24
  62. package/src/parser/source/unescapable.test.ts +3 -3
  63. package/src/parser/source/unescapable.ts +4 -12
  64. package/src/parser/visibility.ts +32 -32
  65. package/src/combinator/control/manipulation/trim.test.ts +0 -23
  66. package/src/combinator/control/manipulation/trim.ts +0 -17
@@ -15,7 +15,7 @@ describe('Unit: parser/source/unescapable', () => {
15
15
  it('basic', () => {
16
16
  assert.deepStrictEqual(inspect(parser('a'), ctx), [['a'], '']);
17
17
  assert.deepStrictEqual(inspect(parser('ab'), ctx), [['ab'], '']);
18
- assert.deepStrictEqual(inspect(parser('09あいAZaz'), ctx), [['09', 'あい', 'AZaz'], '']);
18
+ assert.deepStrictEqual(inspect(parser('09あいAZaz'), ctx), [['09', 'あいAZaz'], '']);
19
19
  });
20
20
 
21
21
  it('space', () => {
@@ -37,8 +37,8 @@ describe('Unit: parser/source/unescapable', () => {
37
37
  assert.deepStrictEqual(inspect(parser('\\\\\\'), ctx), [['\\', '\\', '\\'], '']);
38
38
  assert.deepStrictEqual(inspect(parser('\\ '), ctx), [['\\', ' '], '']);
39
39
  assert.deepStrictEqual(inspect(parser('\\_'), ctx), [['\\', '_'], '']);
40
- assert.deepStrictEqual(inspect(parser('\\0'), ctx), [['\\', '0'], '']);
41
- assert.deepStrictEqual(inspect(parser('\\a'), ctx), [['\\', 'a'], '']);
40
+ assert.deepStrictEqual(inspect(parser('\\0'), ctx), [['\\0'], '']);
41
+ assert.deepStrictEqual(inspect(parser('\\a'), ctx), [['\\a'], '']);
42
42
  assert.deepStrictEqual(inspect(parser('\\`'), ctx), [['\\', '`'], '']);
43
43
  assert.deepStrictEqual(inspect(parser('\\ '), ctx), [['\\', ' '], '']);
44
44
  assert.deepStrictEqual(inspect(parser('\\\n'), ctx), [['\\', '<br>'], '']);
@@ -1,9 +1,11 @@
1
1
  import { UnescapableSourceParser } from '../source';
2
2
  import { Command } from '../context';
3
3
  import { consume } from '../../combinator';
4
- import { nonWhitespace, nonAlphanumeric, ASCII, isBlank, isAlphanumeric, isASCII } from './text';
4
+ import { nonWhitespace, isBlank, next } from './text';
5
5
  import { html } from 'typed-dom/dom';
6
6
 
7
+ export const delimiter = /(?=(?=[\x00-\x7F])[^0-9A-Za-z]|(?<=[\x00-\x7F])[^\x00-\x7F])/g;
8
+
7
9
  export const unescsource: UnescapableSourceParser = ({ context }) => {
8
10
  const { source, position } = context;
9
11
  if (position === source.length) return;
@@ -25,23 +27,13 @@ export const unescsource: UnescapableSourceParser = ({ context }) => {
25
27
  default:
26
28
  assert(char !== '\n');
27
29
  if (context.sequential) return [[char]];
28
- nonAlphanumeric.lastIndex = position + 1;
29
30
  nonWhitespace.lastIndex = position + 1;
30
- ASCII.lastIndex = position + 1;
31
31
  const b = isBlank(source, position);
32
32
  let i = b
33
33
  ? nonWhitespace.test(source)
34
34
  ? nonWhitespace.lastIndex - 1
35
35
  : source.length
36
- : isAlphanumeric(char)
37
- ? nonAlphanumeric.test(source)
38
- ? nonAlphanumeric.lastIndex - 1
39
- : source.length
40
- : !isASCII(char)
41
- ? ASCII.test(source)
42
- ? ASCII.lastIndex - 1
43
- : source.length
44
- : position + 1;
36
+ : next(source, position, delimiter);
45
37
  assert(i > position);
46
38
  i -= position;
47
39
  consume(i - 1, context);
@@ -1,15 +1,15 @@
1
1
  import { MarkdownParser } from '../../markdown';
2
2
  import { Command } from './context';
3
3
  import { Parser, Input, eval, failsafe } from '../combinator/data/parser';
4
- import { union, some, verify, convert, fmap } from '../combinator';
4
+ import { convert, fmap } from '../combinator';
5
5
  import { unsafehtmlentity } from './inline/htmlentity';
6
- import { linebreak, unescsource } from './source';
7
6
  import { invisibleHTMLEntityNames } from './api/normalize';
8
7
  import { push } from 'spica/array';
9
8
 
10
9
  export namespace blank {
11
10
  export const line = new RegExp(
12
- /^(?:\\?[^\S\r\n]|&IHN;|<wbr[^\S\n]*>|\\$)+$/.source
11
+ // TODO: 行全体をエスケープ
12
+ /^(?:[^\S\r\n])*(?!\s)(\\?[^\S\r\n]|&IHN;|<wbr[^\S\n]*>|\\$)+$/mg.source
13
13
  .replace('IHN', `(?:${invisibleHTMLEntityNames.join('|')})`),
14
14
  'gm');
15
15
  export const start = new RegExp(
@@ -19,31 +19,28 @@ export namespace blank {
19
19
 
20
20
  export function visualize<P extends Parser<HTMLElement | string>>(parser: P): P;
21
21
  export function visualize<N extends HTMLElement | string>(parser: Parser<N>): Parser<N> {
22
- return union([
23
- convert(
24
- source => source.replace(blank.line, line => line.replace(/[\\&<]/g, `${Command.Escape}$&`)),
25
- verify(parser, (ns, { source, position }) => position === source.length && hasVisible(ns)),
26
- false),
27
- some(union([linebreak, unescsource])),
28
- ]);
29
- }
30
- function hasVisible(
31
- nodes: readonly (HTMLElement | string)[],
32
- ): boolean {
33
- for (let i = 0; i < nodes.length; ++i) {
34
- const node = nodes[i];
35
- if (typeof node === 'string') {
36
- if (node && node.trimStart()) return true;
37
- }
38
- else {
39
- if (node.innerText.trimStart()) return true;
40
- if (node.classList.contains('reference')) return true;
41
- //if (state & State.media ^ State.media &&
42
- // (node.classList.contains('media') || node.getElementsByClassName('media')[0])) return true;
43
- }
44
- }
45
- return false;
22
+ return convert(
23
+ source => source.replace(blank.line, `${Command.Escape}$1`),
24
+ parser,
25
+ false);
46
26
  }
27
+ //function hasVisible(
28
+ // nodes: readonly (HTMLElement | string)[],
29
+ //): boolean {
30
+ // for (let i = 0; i < nodes.length; ++i) {
31
+ // const node = nodes[i];
32
+ // if (typeof node === 'string') {
33
+ // if (node && node.trimStart()) return true;
34
+ // }
35
+ // else {
36
+ // if (node.innerText.trimStart()) return true;
37
+ // if (node.classList.contains('reference')) return true;
38
+ // //if (state & State.media ^ State.media &&
39
+ // // (node.classList.contains('media') || node.getElementsByClassName('media')[0])) return true;
40
+ // }
41
+ // }
42
+ // return false;
43
+ //}
47
44
 
48
45
  export function blankWith(delimiter: string | RegExp): RegExp;
49
46
  export function blankWith(starts: '' | '\n', delimiter: string | RegExp): RegExp;
@@ -79,6 +76,7 @@ export function tightStart<N>(parser: Parser<N>, except?: string): Parser<N> {
79
76
  ? parser(input)
80
77
  : undefined;
81
78
  }
79
+ const wbr = /<wbr[^\S\n]*>/y;
82
80
  function isTightStart(input: Input<MarkdownParser.Context>, except?: string): boolean {
83
81
  const { context } = input;
84
82
  const { source, position } = context;
@@ -103,10 +101,11 @@ function isTightStart(input: Input<MarkdownParser.Context>, except?: string): bo
103
101
  context.position = position;
104
102
  return true;
105
103
  case '<':
104
+ wbr.lastIndex = position;
106
105
  switch (true) {
107
106
  case source.length - position >= 5
108
107
  && source.startsWith('<wbr', position)
109
- && (source[position + 5] === '>' || /^<wbr[^\S\n]*>/.test(source.slice(position))):
108
+ && (source[position + 5] === '>' || wbr.test(source)):
110
109
  return false;
111
110
  }
112
111
  return true;
@@ -168,18 +167,19 @@ export function trimBlankStart<N>(parser: Parser<N>): Parser<N> {
168
167
  return failsafe(input => {
169
168
  const { context } = input;
170
169
  const { source, position } = context;
170
+ if (position === source.length) return;
171
171
  const reg = blank.start;
172
172
  reg.lastIndex = position;
173
173
  reg.test(source);
174
174
  context.position = reg.lastIndex || position;
175
- return parser(input);
175
+ return context.position === source.length
176
+ ? [[]]
177
+ : parser(input);
176
178
  });
177
179
  }
178
180
  export function trimBlankEnd<P extends Parser<HTMLElement | string>>(parser: P): P;
179
181
  export function trimBlankEnd<N extends HTMLElement | string>(parser: Parser<N>): Parser<N> {
180
- return fmap(
181
- parser,
182
- trimBlankNodeEnd);
182
+ return fmap(parser, trimBlankNodeEnd);
183
183
  }
184
184
  //export function trimBlankNode<N extends HTMLElement | string>(nodes: N[]): N[] {
185
185
  // return trimBlankNodeStart(trimBlankNodeEnd(nodes));
@@ -1,23 +0,0 @@
1
- import { trim } from './trim';
2
- import { input } from '../../data/parser';
3
- import { inspect } from '../../../debug.test';
4
-
5
- describe('Unit: combinator/trim', () => {
6
- describe('trim', () => {
7
- const { context: ctx } = input('', {});
8
-
9
- it('', () => {
10
- const parser = trim(({ context }) => { context.position = context.source.length; return [[context.source]]; });
11
- assert.deepStrictEqual(inspect(parser(input('', ctx)), ctx), undefined);
12
- assert.deepStrictEqual(inspect(parser(input('a', ctx)), ctx), [['a'], '']);
13
- assert.deepStrictEqual(inspect(parser(input('a\n', ctx)), ctx), [['a'], '']);
14
- assert.deepStrictEqual(inspect(parser(input('a ', ctx)), ctx), [['a'], '']);
15
- assert.deepStrictEqual(inspect(parser(input('a \n', ctx)), ctx), [['a'], '']);
16
- assert.deepStrictEqual(inspect(parser(input(' a', ctx)), ctx), [['a'], '']);
17
- assert.deepStrictEqual(inspect(parser(input(' a ', ctx)), ctx), [['a'], '']);
18
- assert.deepStrictEqual(inspect(parser(input(' a \n b \n', ctx)), ctx), [['a \n b'], '']);
19
- });
20
-
21
- });
22
-
23
- });
@@ -1,17 +0,0 @@
1
- import { Parser } from '../../data/parser';
2
- import { convert } from './convert';
3
-
4
- export function trim<P extends Parser<unknown>>(parser: P): P;
5
- export function trim<N>(parser: Parser<N>): Parser<N> {
6
- return convert(source => source.trim(), parser, false);
7
- }
8
-
9
- export function trimStart<P extends Parser<unknown>>(parser: P): P;
10
- export function trimStart<N>(parser: Parser<N>): Parser<N> {
11
- return convert(source => source.trimStart(), parser, true);
12
- }
13
-
14
- export function trimEnd<P extends Parser<unknown>>(parser: P): P;
15
- export function trimEnd<N>(parser: Parser<N>): Parser<N> {
16
- return convert(source => source.trimEnd(), parser, false);
17
- }