securemark 0.298.2 → 0.298.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 (34) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/index.js +100 -93
  3. package/package.json +1 -1
  4. package/src/combinator/control/constraint/line.ts +1 -1
  5. package/src/combinator/control/manipulation/match.ts +1 -1
  6. package/src/combinator/data/delimiter.ts +42 -37
  7. package/src/combinator/data/parser/context.ts +4 -2
  8. package/src/combinator/data/parser/inits.ts +1 -1
  9. package/src/combinator/data/parser/sequence.ts +1 -1
  10. package/src/combinator/data/parser/some.ts +4 -3
  11. package/src/parser/api/bind.ts +6 -8
  12. package/src/parser/api/header.ts +1 -1
  13. package/src/parser/api/parse.ts +5 -6
  14. package/src/parser/block/codeblock.ts +1 -1
  15. package/src/parser/block/extension/fig.ts +1 -1
  16. package/src/parser/block/extension/figure.ts +1 -1
  17. package/src/parser/block/extension/message.ts +1 -1
  18. package/src/parser/block/extension/placeholder.ts +1 -1
  19. package/src/parser/block/extension/table.ts +1 -1
  20. package/src/parser/block/heading.ts +1 -1
  21. package/src/parser/block/mathblock.ts +1 -1
  22. package/src/parser/block.ts +4 -5
  23. package/src/parser/header.test.ts +1 -0
  24. package/src/parser/header.ts +3 -3
  25. package/src/parser/inline/autolink.ts +3 -3
  26. package/src/parser/inline/bracket.ts +5 -6
  27. package/src/parser/inline/html.test.ts +5 -1
  28. package/src/parser/inline/html.ts +61 -53
  29. package/src/parser/inline.ts +7 -1
  30. package/src/parser/processor/note.ts +1 -1
  31. package/src/parser/segment.ts +7 -6
  32. package/src/parser/source/escapable.ts +0 -1
  33. package/src/parser/source/line.ts +6 -4
  34. package/src/parser/source/text.ts +4 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.298.2",
3
+ "version": "0.298.3",
4
4
  "description": "Secure markdown renderer working on browsers for user input data.",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/falsandtru/securemark",
@@ -27,7 +27,7 @@ export function firstline(source: string, position: number): string {
27
27
  : source.slice(position, i + 1);
28
28
  }
29
29
 
30
- const emptyline = /[^\S\n]*(?:$|\n)/y;
30
+ const emptyline = /[^\S\r\n]*(?:$|\r?\n)/y;
31
31
  export function isEmptyline(source: string, position: number): boolean {
32
32
  emptyline.lastIndex = position;
33
33
  return source.length === position
@@ -5,7 +5,7 @@ export function match<P extends Parser>(pattern: RegExp, f: (matched: RegExpMatc
5
5
  export function match<N>(pattern: RegExp, f: (matched: RegExpMatchArray) => Parser<N>): Parser<N> {
6
6
  assert(!pattern.flags.match(/[gm]/) && pattern.sticky && !pattern.source.startsWith('^'));
7
7
  const count = typeof pattern === 'object'
8
- ? /[^^\\*+][*+]/.test(pattern.source)
8
+ ? /[^^\\*+][*+]|{\d+,}/.test(pattern.source)
9
9
  : false;
10
10
  return failsafe(input => {
11
11
  const context = input;
@@ -4,30 +4,43 @@ import { consume } from './parser/context';
4
4
  interface Delimiter {
5
5
  readonly memory: Delimiter[];
6
6
  readonly index: number;
7
- readonly signature: number | string;
8
- readonly matcher: (input: Input) => boolean | undefined;
7
+ readonly tester: (input: Input) => boolean | undefined;
9
8
  readonly precedence: number;
10
9
  state: boolean;
11
10
  }
12
11
 
12
+ const indexes = new Map();
13
+ function index(source: string): number {
14
+ let x = 0;
15
+ for (let i = 0; i < source.length; ++i) {
16
+ const c = source.charCodeAt(i);
17
+ x = x ^ c << 1 || ~x ^ c << 1; // 16+1bit
18
+ assert(x !== 0);
19
+ x ^= x << 13; // shift <= 32-17bit
20
+ x ^= x >>> 17;
21
+ x ^= x << 15;
22
+ }
23
+ x >>>= 3;
24
+ x &= ~0 >>> 32 - 4;
25
+ assert(x !== 0);
26
+ assert(indexes.has(source) ? indexes.get(source) === x : indexes.set(source, x));
27
+ return x;
28
+ }
29
+
13
30
  export class Delimiters {
14
31
  // 手間を惜しまなければ規定のパターンはすべて配列のインデクスに変換可能。
15
- public static signature(pattern: string | RegExp | undefined): number | string {
32
+ public static signature(pattern: undefined | string | RegExp): number {
16
33
  switch (typeof pattern) {
17
34
  case 'undefined':
18
- return 1 << 7;
35
+ return 0;
19
36
  case 'string':
20
- assert(pattern !== '\x00');
21
- if (pattern.length === 1) {
22
- const code = pattern.charCodeAt(0);
23
- return code;
24
- }
25
- return `s:${pattern}`;
37
+ assert(pattern !== '');
38
+ return index(`'${pattern}`);
26
39
  case 'object':
27
- return `r/${pattern.source}`;
40
+ return index(`/${pattern.source}`);
28
41
  }
29
42
  }
30
- public static matcher(pattern: string | RegExp | undefined, after?: string | RegExp): (input: Input<Context>) => true | undefined {
43
+ public static tester(pattern: string | RegExp | undefined, after?: string | RegExp): (input: Input<Context>) => true | undefined {
31
44
  switch (typeof pattern) {
32
45
  case 'undefined':
33
46
  return () => undefined;
@@ -40,27 +53,20 @@ export class Delimiters {
40
53
  : input => test(input) !== undefined || undefined;
41
54
  }
42
55
  }
43
- private readonly tree: Record<number, Delimiter[]> = {};
44
- private readonly map: Map<string, Delimiter[]> = new Map();
45
- private registry(signature: number | string): Delimiter[] {
46
- if (typeof signature === 'number') {
47
- return this.tree[signature] ??= [];
48
- }
49
- else {
50
- const ds = this.map.get(signature);
51
- if (ds) return ds;
52
- const blank: Delimiter[] = [];
53
- this.map.set(signature, blank);
54
- return blank;
55
- }
56
+ private readonly memories: Delimiter[][] = [];
57
+ private registry(signature: number): Delimiter[] {
58
+ assert(signature >= 0);
59
+ assert(signature >>> 0 === signature);
60
+ assert(signature >>> 16 === 0);
61
+ return this.memories[signature] ??= [];
56
62
  }
57
63
  private readonly delimiters: Delimiter[] = [];
58
64
  private readonly stack: number[] = [];
59
65
  private readonly states: (readonly number[])[] = [];
60
66
  public push(
61
67
  delims: readonly {
62
- readonly signature: number | string;
63
- readonly matcher: (input: Input) => boolean | undefined;
68
+ readonly signature: number;
69
+ readonly tester: (input: Input) => boolean | undefined;
64
70
  readonly precedence: number;
65
71
  }[]
66
72
  ): void {
@@ -68,7 +74,7 @@ export class Delimiters {
68
74
  // シグネチャ数以下
69
75
  assert(delimiters.length < 100);
70
76
  for (let i = 0; i < delims.length; ++i) {
71
- const { signature, matcher, precedence } = delims[i];
77
+ const { signature, tester, precedence } = delims[i];
72
78
  const memory = this.registry(signature);
73
79
  const index = memory[0]?.index ?? delimiters.length;
74
80
  assert(memory.length === 0 || precedence === delimiters[index].precedence);
@@ -76,8 +82,7 @@ export class Delimiters {
76
82
  const delimiter: Delimiter = {
77
83
  memory,
78
84
  index,
79
- signature,
80
- matcher,
85
+ tester,
81
86
  precedence,
82
87
  state: true,
83
88
  };
@@ -86,10 +91,10 @@ export class Delimiters {
86
91
  stack.push(index);
87
92
  }
88
93
  else {
94
+ // 現状各優先順位は固定
95
+ assert(memory.length === 1);
89
96
  stack.push(-1);
90
97
  }
91
- // 現状各優先順位は固定
92
- assert(memory.length === 1);
93
98
  }
94
99
  }
95
100
  public pop(count: number): void {
@@ -121,7 +126,7 @@ export class Delimiters {
121
126
  const delimiter = delimiters[i];
122
127
  if (delimiter.precedence >= precedence || !delimiter.state) continue;
123
128
  delimiter.state = false;
124
- indexes.push(i)
129
+ indexes.push(i);
125
130
  }
126
131
  this.states.push(indexes);
127
132
  }
@@ -132,13 +137,13 @@ export class Delimiters {
132
137
  delimiters[indexes[i]].state = true;
133
138
  }
134
139
  }
135
- public match(input: Input): boolean {
140
+ public test(input: Input): boolean {
136
141
  const { precedence } = input;
137
142
  const { delimiters } = this;
138
143
  for (let i = delimiters.length; i--;) {
139
144
  const delimiter = delimiters[i];
140
145
  if (delimiter.precedence <= precedence || !delimiter.state) continue;
141
- switch (delimiter.matcher(input)) {
146
+ switch (delimiter.tester(input)) {
142
147
  case true:
143
148
  return true;
144
149
  case false:
@@ -154,7 +159,7 @@ export class Delimiters {
154
159
  export function matcher(pattern: string | RegExp, advance: boolean, after?: Parser<string>): Parser<string> {
155
160
  assert(pattern instanceof RegExp ? !pattern.flags.match(/[gm]/) && pattern.sticky && !pattern.source.startsWith('^') : true);
156
161
  const count = typeof pattern === 'object'
157
- ? /[^^\\*+][*+]/.test(pattern.source)
162
+ ? /[^^\\*+][*+]|{\d+,}/.test(pattern.source)
158
163
  : false;
159
164
  switch (typeof pattern) {
160
165
  case 'string':
@@ -194,7 +199,7 @@ export function matcher(pattern: string | RegExp, advance: boolean, after?: Pars
194
199
  export function tester(pattern: string | RegExp, advance: boolean, after?: Parser<unknown>): Parser<never> {
195
200
  assert(pattern instanceof RegExp ? !pattern.flags.match(/[gm]/) && pattern.sticky && !pattern.source.startsWith('^') : true);
196
201
  const count = typeof pattern === 'object'
197
- ? /[^^\\*+][*+]/.test(pattern.source)
202
+ ? /[^^\\*+][*+]|{\d+,}/.test(pattern.source)
198
203
  : false;
199
204
  switch (typeof pattern) {
200
205
  case 'string':
@@ -4,12 +4,14 @@ import { clone } from 'spica/assign';
4
4
 
5
5
  export function reset<P extends Parser>(base: Options, parser: P): P;
6
6
  export function reset<N>(base: Context, parser: Parser<N>): Parser<N> {
7
+ const clock = base.resources?.clock;
8
+ const recursions = base.resources?.recursions;
7
9
  return input => {
8
10
  const context = input;
9
11
  // @ts-expect-error
10
12
  context.resources ??= {
11
- clock: base.resources?.clock,
12
- recursions: base.resources?.recursions.slice(),
13
+ clock,
14
+ recursions: recursions?.slice(),
13
15
  };
14
16
  context.backtracks = {};
15
17
  return parser(input);
@@ -10,7 +10,7 @@ export function inits<N, D extends Parser<N>[]>(parsers: D): Parser<N, Context,
10
10
  let nodes: List<Node<N>> | undefined;
11
11
  for (let len = parsers.length, i = 0; i < len; ++i) {
12
12
  if (context.position === source.length) break;
13
- if (context.delimiters.match(input)) break;
13
+ if (context.delimiters.test(input)) break;
14
14
  const result = parsers[i](input);
15
15
  if (result === undefined) break;
16
16
  nodes = nodes?.import(result) ?? result;
@@ -10,7 +10,7 @@ export function sequence<N, D extends Parser<N>[]>(parsers: D): Parser<N, Contex
10
10
  let nodes: List<Node<N>> | undefined;
11
11
  for (let len = parsers.length, i = 0; i < len; ++i) {
12
12
  if (context.position === source.length) return;
13
- if (context.delimiters.match(input)) return;
13
+ if (context.delimiters.test(input)) return;
14
14
  const result = parsers[i](input);
15
15
  if (result === undefined) return;
16
16
  nodes = nodes?.import(result) ?? result;
@@ -21,10 +21,11 @@ export function some<N>(parser: Parser<N>, delimiter?: number | string | RegExp
21
21
  after = undefined;
22
22
  }
23
23
  assert(parser);
24
- const match = Delimiters.matcher(delimiter as string, after as string);
24
+ assert(delimiter !== '');
25
+ const match = Delimiters.tester(delimiter as string, after as string);
25
26
  const delims = delimiters?.map(([delimiter, precedence]) => ({
26
27
  signature: Delimiters.signature(delimiter),
27
- matcher: Delimiters.matcher(delimiter),
28
+ tester: Delimiters.tester(delimiter),
28
29
  precedence,
29
30
  }));
30
31
  return input => {
@@ -36,7 +37,7 @@ export function some<N>(parser: Parser<N>, delimiter?: number | string | RegExp
36
37
  // whileは数倍遅い
37
38
  for (const len = source.length; context.position < len;) {
38
39
  if (match(input)) break;
39
- if (context.delimiters.match(input)) break;
40
+ if (context.delimiters.test(input)) break;
40
41
  const result = parser(input);
41
42
  if (result === undefined) break;
42
43
  nodes = nodes?.import(result) ?? result;
@@ -3,7 +3,6 @@ import { Context, Segment } from '../context';
3
3
  import { input } from '../../combinator/data/parser';
4
4
  import { segment } from '../segment';
5
5
  import { block } from '../block';
6
- import { normalize } from './normalize';
7
6
  import { headers } from './header';
8
7
  import { figure } from '../processor/figure';
9
8
  import { note } from '../processor/note';
@@ -42,13 +41,12 @@ export function bind(target: DocumentFragment | HTMLElement | ShadowRoot, settin
42
41
  function* parse(source: string): Generator<Progress, undefined, undefined> {
43
42
  if (settings.chunk && revision) throw new Error('Chunks cannot be updated');
44
43
  const url = headers(source).find(field => field.toLowerCase().startsWith('url:'))?.slice(4).trim() ?? '';
45
- source = normalize(source);
46
44
  // @ts-expect-error
47
45
  context.url = url ? new ReadonlyURL(url as ':') : undefined;
48
46
  const rev = revision = Symbol();
49
47
  const sourceSegments: string[] = [];
50
48
  const sourceSegmentAttrs: Segment[] = [];
51
- for (const [seg, attr] of segment(source)) {
49
+ for (const [seg, attr] of segment(source, !context.local)) {
52
50
  sourceSegments.push(seg);
53
51
  sourceSegmentAttrs.push(attr);
54
52
  yield { type: 'segment', value: seg };
@@ -76,15 +74,15 @@ export function bind(target: DocumentFragment | HTMLElement | ShadowRoot, settin
76
74
  context.header = true;
77
75
  for (; index < sourceSegments.length - last; ++index) {
78
76
  assert(rev === revision);
79
- const src = sourceSegments[index];
77
+ const seg = sourceSegments[index];
80
78
  context.segment = sourceSegmentAttrs[index] | Segment.write;
81
- const es = block(input(src, new Context(context)))
82
- ?.foldl<HTMLElement[]>((acc, { value }) => void acc.push(value) || acc, []) ?? [];
79
+ const es = block(input(seg, new Context(context)))!
80
+ .foldl<HTMLElement[]>((acc, { value }) => void acc.push(value) || acc, []);
83
81
  // @ts-expect-error
84
82
  context.header = false;
85
83
  blocks.length === index
86
- ? blocks.push([src, es, url])
87
- : blocks.splice(index, 0, [src, es, url]);
84
+ ? blocks.push([seg, es, url])
85
+ : blocks.splice(index, 0, [seg, es, url]);
88
86
  if (es.length === 0) continue;
89
87
  // All deletion processes always run after all addition processes have done.
90
88
  // Therefore any `base` node will never be unavailable by deletions until all the dependent `el` nodes are added.
@@ -8,7 +8,7 @@ export function header(source: string): string {
8
8
 
9
9
  export function headers(source: string): string[] {
10
10
  const [el] = parse(source);
11
- return el?.textContent!.trimEnd().slice(el.firstChild!.firstChild!.textContent!.length).split('\n') ?? [];
11
+ return el?.textContent!.trimEnd().slice(el.firstChild!.firstChild!.textContent!.length).split(/\r?\n/) ?? [];
12
12
  }
13
13
 
14
14
  function parse(source: string): [HTMLElement, number] | [] {
@@ -3,7 +3,6 @@ import { input } from '../../combinator/data/parser';
3
3
  import { Context, Segment } from '../context';
4
4
  import { segment } from '../segment';
5
5
  import { block } from '../block';
6
- import { normalize } from './normalize';
7
6
  import { headers } from './header';
8
7
  import { figure } from '../processor/figure';
9
8
  import { note } from '../processor/note';
@@ -17,7 +16,6 @@ interface Options extends ParserOptions {
17
16
 
18
17
  export function parse(source: string, options: Options = {}, context?: Context): DocumentFragment {
19
18
  const url = headers(source).find(field => field.toLowerCase().startsWith('url:'))?.slice(4).trim() ?? '';
20
- source = !context ? normalize(source) : source;
21
19
  context = new Context({
22
20
  host: options.host ?? context?.host ?? new ReadonlyURL(location.pathname, location.origin),
23
21
  url: url ? new ReadonlyURL(url as ':') : context?.url,
@@ -34,13 +32,14 @@ export function parse(source: string, options: Options = {}, context?: Context):
34
32
  const node = frag();
35
33
  // @ts-expect-error
36
34
  context.header = true;
37
- for (const [seg, attr] of segment(source)) {
35
+ for (const [seg, attr] of segment(source, !context.local)) {
38
36
  context.segment = attr | Segment.write;
39
- node.append(
40
- ...block(input(seg, new Context(context)))
41
- ?.foldl<HTMLElement[]>((acc, { value }) => void acc.push(value) || acc, []) ?? []);
37
+ const es = block(input(seg, new Context(context)))!
38
+ .foldl<HTMLElement[]>((acc, { value }) => void acc.push(value) || acc, [])
42
39
  // @ts-expect-error
43
40
  context.header = false;
41
+ if (es.length === 0) continue;
42
+ node.append(...es);
44
43
  }
45
44
  assert(options.id !== '' || !node.querySelector('[id], .index[href], .label[href], .annotation > a[href], .reference > a[href]'));
46
45
  if (options.test) return node;
@@ -5,7 +5,7 @@ import { autolink } from '../autolink';
5
5
  import { unwrap, invalid } from '../util';
6
6
  import { html, defrag } from 'typed-dom/dom';
7
7
 
8
- const opener = /(`{3,})(?!`)([^\n]*)(?:$|\n)/y;
8
+ const opener = /(`{3,})(?!`)([^\r\n]*)(?:$|\r?\n)/y;
9
9
  const language = /^[0-9a-z]+(?:-[a-z][0-9a-z]*)*$/i;
10
10
 
11
11
  export const segment: CodeBlockParser.SegmentParser = block(
@@ -15,7 +15,7 @@ import FigParser = ExtensionParser.FigParser;
15
15
 
16
16
  export const segment: FigParser.SegmentParser = block(
17
17
  sequence([
18
- line(close(seg_label, /(?!\S).*\n/y)),
18
+ line(close(seg_label, /(?!\S).*\r?\n/y)),
19
19
  union([
20
20
  seg_code,
21
21
  seg_math,
@@ -24,7 +24,7 @@ import FigureParser = ExtensionParser.FigureParser;
24
24
  export const segment: FigureParser.SegmentParser = block(match(
25
25
  /(~{3,})(?:figure )?(?=\[?\$)/y,
26
26
  memoize(
27
- ([, fence], closer = new RegExp(String.raw`${fence}[^\S\n]*(?:$|\n)`, 'y')) => close(
27
+ ([, fence], closer = new RegExp(String.raw`${fence}[^\S\r\n]*(?:$|\r?\n)`, 'y')) => close(
28
28
  sequence([
29
29
  contentline,
30
30
  inits([
@@ -56,7 +56,7 @@ export const message: MessageParser = block(fmap(
56
56
  class: `message`,
57
57
  'data-type': type,
58
58
  },
59
- [...segment(body)].reduce(
59
+ [...segment(body, false)].reduce(
60
60
  (acc, [seg]) =>
61
61
  push(acc, unwrap(content(subinput(seg, context)))),
62
62
  [html('h1', title(type))])))
@@ -4,7 +4,7 @@ import { block, fence, clear, fmap } from '../../../combinator';
4
4
  import { unwrap, invalid } from '../../util';
5
5
  import { html } from 'typed-dom/dom';
6
6
 
7
- const opener = /(~{3,})(?!~)[^\n]*(?:$|\n)/y;
7
+ const opener = /(~{3,})(?!~)[^\r\n]*(?:$|\r?\n)/y;
8
8
 
9
9
  export const segment: ExtensionParser.PlaceholderParser.SegmentParser = block(
10
10
  clear(fence(opener, 300)));
@@ -14,7 +14,7 @@ import RowParser = TableParser.RowParser;
14
14
  import AlignParser = TableParser.AlignParser;
15
15
  import CellParser = TableParser.CellParser;
16
16
 
17
- const opener = /(~{3,})table(?:\/(\S+))?(?!\S)([^\n]*)(?:$|\n)/y;
17
+ const opener = /(~{3,})table(?:\/(\S+))?(?!\S)([^\r\n]*)(?:$|\r?\n)/y;
18
18
 
19
19
  export const segment: TableParser.SegmentParser = block(
20
20
  clear(fence(opener, 10000)));
@@ -9,7 +9,7 @@ import { unwrap, invalid } from '../util';
9
9
  import { html, defrag } from 'typed-dom/dom';
10
10
 
11
11
  export const segment: HeadingParser.SegmentParser = block(focus(
12
- /#+ +\S[^\n]*(?:\n#+(?=$|[ \n])[^\n]*)*(?:$|\n)/y,
12
+ /#+ +\S[^\r\n]*(?:\r?\n#+(?=$| |\r?\n)[^\r\n]*)*(?:$|\r?\n)/y,
13
13
  input => {
14
14
  const context = input;
15
15
  const { source, range } = context;
@@ -4,7 +4,7 @@ import { block, fence, clear, fmap } from '../../combinator';
4
4
  import { unwrap, invalid } from '../util';
5
5
  import { html } from 'typed-dom/dom';
6
6
 
7
- const opener = /(\${2,})(?!\$)([^\n]*)(?:$|\n)/y;
7
+ const opener = /(\${2,})(?!\$)([^\r\n]*)(?:$|\r?\n)/y;
8
8
 
9
9
  export const segment: MathBlockParser.SegmentParser = block(
10
10
  clear(fence(opener, 300)));
@@ -58,7 +58,6 @@ export const block: BlockParser = reset(
58
58
  20 || Recursion.terminal,
59
59
  ],
60
60
  },
61
- backtracks: {},
62
61
  },
63
62
  error(union([
64
63
  emptysegment,
@@ -73,8 +72,8 @@ export const block: BlockParser = reset(
73
72
  case Segment.figure:
74
73
  return figure(input);
75
74
  }
76
- const fst = source[position];
77
- switch (fst) {
75
+ const char = source[position];
76
+ switch (char) {
78
77
  case Command.Error:
79
78
  throw new Error(firstline(source, position + 1).trimEnd());
80
79
  case '=':
@@ -117,14 +116,14 @@ export const block: BlockParser = reset(
117
116
  case '(':
118
117
  return olist(input);
119
118
  default:
120
- if ('0' <= fst && fst <= '9') return olist(input);
119
+ if ('0' <= char && char <= '9') return olist(input);
121
120
  }
122
121
  },
123
122
  paragraph
124
123
  ])));
125
124
 
126
125
  function error(parser: BlockParser): BlockParser {
127
- const reg = new RegExp(String.raw`^${Command.Error}[^\n]*\n`)
126
+ const reg = new RegExp(String.raw`^${Command.Error}[^\r\n]*\r?\n`)
128
127
  return recover<BlockParser>(
129
128
  parser,
130
129
  ({ source, position, id }, reason) => new List([
@@ -27,6 +27,7 @@ describe('Unit: parser/header', () => {
27
27
  assert.deepStrictEqual(inspect(parser, input('---\na: b\n---', new Context())), [['<aside class="header"><details open=""><summary>Header</summary><span class="field" data-name="a" data-value="b"><span class="field-name">a</span>: <span class="field-value">b</span>\n</span></details></aside>'], '']);
28
28
  assert.deepStrictEqual(inspect(parser, input('---\na: b\n---\n', new Context())), [['<aside class="header"><details open=""><summary>Header</summary><span class="field" data-name="a" data-value="b"><span class="field-name">a</span>: <span class="field-value">b</span>\n</span></details></aside>'], '']);
29
29
  assert.deepStrictEqual(inspect(parser, input('---\na: b\nC: D e\n---\n', new Context())), [['<aside class="header"><details open=""><summary>Header</summary><span class="field" data-name="a" data-value="b"><span class="field-name">a</span>: <span class="field-value">b</span>\n</span><span class="field" data-name="c" data-value="D e"><span class="field-name">C</span>: <span class="field-value">D e</span>\n</span></details></aside>'], '']);
30
+ assert.deepStrictEqual(inspect(parser, input('---\r\na: b\r\nC: D e\r\n---\r\n', new Context())), [['<aside class="header"><details open=""><summary>Header</summary><span class="field" data-name="a" data-value="b"><span class="field-name">a</span>: <span class="field-value">b</span>\n</span><span class="field" data-name="c" data-value="D e"><span class="field-name">C</span>: <span class="field-value">D e</span>\n</span></details></aside>'], '']);
30
31
  assert.deepStrictEqual(inspect(parser, input('----\na: b\n----', new Context())), [['<aside class="header"><details open=""><summary>Header</summary><span class="field" data-name="a" data-value="b"><span class="field-name">a</span>: <span class="field-value">b</span>\n</span></details></aside>'], '']);
31
32
  });
32
33
 
@@ -7,12 +7,12 @@ import { normalize } from './api/normalize';
7
7
  import { html, defrag } from 'typed-dom/dom';
8
8
 
9
9
  export const header: MarkdownParser.HeaderParser = lazy(() => validate(
10
- /---+[^\S\n]*\n(?=\S)/y,
10
+ /---+[^\S\r\n]*\r?\n(?=\S)/y,
11
11
  inits([
12
12
  block(
13
13
  union([
14
14
  validate(context => context.header,
15
- focus(/(---+)[^\S\n]*\n(?:[a-z][0-9a-z]*(?:-[0-9a-z]+)*:[ \t]+\S[^\n]*\n){1,100}\1[^\S\n]*(?:$|\n)/yi,
15
+ focus(/(---+)[^\S\r\n]*\r?\n(?:[a-z][0-9a-z]*(?:-[0-9a-z]+)*:[ \t]+\S[^\r\n]*\r?\n){1,100}\1[^\S\r\n]*(?:$|\r?\n)/yi,
16
16
  convert(source =>
17
17
  normalize(source.slice(source.indexOf('\n') + 1, source.trimEnd().lastIndexOf('\n'))),
18
18
  fmap(
@@ -36,7 +36,7 @@ export const header: MarkdownParser.HeaderParser = lazy(() => validate(
36
36
  ]);
37
37
  },
38
38
  ])),
39
- clear(str(/[^\S\n]*\n/y)),
39
+ clear(str(/[^\S\r\n]*\r?\n/y)),
40
40
  ])));
41
41
 
42
42
  const field: MarkdownParser.HeaderParser.FieldParser = line(({ source, position }) => {
@@ -14,8 +14,8 @@ export const autolink: AutolinkParser = lazy(() =>
14
14
  input => {
15
15
  const { source, position } = input;
16
16
  if (position === source.length) return;
17
- const fst = source[position];
18
- switch (fst) {
17
+ const char = source[position];
18
+ switch (char) {
19
19
  case '@':
20
20
  return account(input);
21
21
  case '#':
@@ -41,6 +41,6 @@ export const autolink: AutolinkParser = lazy(() =>
41
41
  }
42
42
  return url(input) || email(input);
43
43
  default:
44
- if (isAlphanumeric(fst)) return email(input);
44
+ if (isAlphanumeric(char)) return email(input);
45
45
  }
46
46
  }));
@@ -8,19 +8,18 @@ import { str } from '../source';
8
8
  import { unwrap } from '../util';
9
9
  import { html, defrag } from 'typed-dom/dom';
10
10
 
11
- export const indexA = /[0-9A-Za-z]+(?:(?:[.-]|, )[0-9A-Za-z]+)*/y;
11
+ export const indexA = /^[0-9A-Za-z]+(?:(?:[.-]|, )[0-9A-Za-z]+)*$/;
12
12
  const indexF = new RegExp(
13
13
  indexA.source.replace(', ', '[,、]')
14
14
  .replace(/[09AZaz.]|\-(?!\w)/g, c => String.fromCodePoint(c.codePointAt(0)! + 0xFEE0)),
15
- 'y');
15
+ '');
16
16
  export function bracketname(context: Context, syntax: RegExp, opener: number, closer: number): string {
17
17
  const { source, position, range, linebreak } = context;
18
18
  syntax.lastIndex = position - range + opener;
19
19
  return range - opener - closer === 0
20
- || linebreak === 0
21
- && range - opener - closer <= 16
22
- && syntax.test(source)
23
- && syntax.lastIndex === position - closer
20
+ || linebreak === 0 &&
21
+ range - opener - closer <= 16 &&
22
+ syntax.test(source.slice(position - range + opener, position - closer))
24
23
  ? 'paren'
25
24
  : 'bracket';
26
25
  }
@@ -1,4 +1,4 @@
1
- import { html } from './html';
1
+ import { html, TAGS } from './html';
2
2
  import { some } from '../../combinator';
3
3
  import { input } from '../../combinator/data/parser';
4
4
  import { Context } from '../context';
@@ -8,6 +8,10 @@ describe('Unit: parser/inline/html', () => {
8
8
  describe('html', () => {
9
9
  const parser = some(html);
10
10
 
11
+ it('hash', () => {
12
+ assert(TAGS.every(tag => parser(input(`<${tag}>`, new Context()))));
13
+ });
14
+
11
15
  it('xss', () => {
12
16
  assert.deepStrictEqual(inspect(parser, input('<script>', new Context())), [['<span class="invalid">&lt;script&gt;</span>'], '']);
13
17
  assert.deepStrictEqual(inspect(parser, input('<script>alert()<script>', new Context())), [['<span class="invalid">&lt;script&gt;alert()&lt;script&gt;</span>'], '']);