securemark 0.268.2 → 0.269.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.
@@ -1,4 +1,4 @@
1
- import { text } from '../inline/extension/indexee';
1
+ import { identity, text } from '../inline/extension/indexee';
2
2
  import { frag, html, define } from 'typed-dom/dom';
3
3
 
4
4
  export function* footnote(
@@ -44,13 +44,15 @@ function build(
44
44
  }
45
45
  const refs = target.querySelectorAll(`sup.${syntax}:not(.disabled)`);
46
46
  const titles = new Map<string, string>();
47
- const contents = new Map<string, DocumentFragment>();
47
+ const contents = new Map<string, HTMLSpanElement>();
48
48
  for (let len = refs.length, i = 0; i < len; ++i) {
49
49
  if (i % 10 === 9) yield;
50
50
  const ref = refs[i];
51
51
  const identifier = ref.getAttribute('data-abbr') || ` ${ref.firstElementChild!.innerHTML}`;
52
52
  if (titles.has(identifier)) continue;
53
- const content = frag(ref.firstElementChild!.cloneNode(true).childNodes);
53
+ const content = html('span',
54
+ { id: identity(opts.id, text(ref.firstElementChild!), 'note') },
55
+ ref.firstElementChild!.cloneNode(true).childNodes);
54
56
  const title = text(content).trim();
55
57
  if (!title) continue;
56
58
  titles.set(identifier, title);
@@ -100,7 +102,6 @@ function build(
100
102
  const title = titles.get(identifier);
101
103
  assert(title !== '');
102
104
  assert(syntax !== 'annotation' || title);
103
- const content = frag(ref.firstElementChild!.cloneNode(true).childNodes);
104
105
  const refIndex = ++count;
105
106
  const refId = opts.id !== ''
106
107
  ? `${syntax}:${opts.id ?? ''}:ref:${refIndex}`
@@ -134,7 +135,7 @@ function build(
134
135
  html('a',
135
136
  {
136
137
  href: refId && `#${refId}`,
137
- title: abbr && text(content).trim() || undefined,
138
+ title: abbr && text(frag(ref.firstElementChild!.cloneNode(true).childNodes)).trim() || undefined,
138
139
  },
139
140
  `^${refIndex}`));
140
141
  }
@@ -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(1, false, ({ source }) => {
7
+ export const escsource: EscapableSourceParser = creation(1, false, ({ source, context }) => {
8
8
  if (source === '') return;
9
9
  const i = source.search(delimiter);
10
10
  switch (i) {
@@ -12,6 +12,10 @@ export const escsource: EscapableSourceParser = creation(1, false, ({ source })
12
12
  return [[source], ''];
13
13
  case 0:
14
14
  switch (source[0]) {
15
+ case '\r':
16
+ assert(!source.includes('\r', 1));
17
+ context.resources && ++context.resources.clock;
18
+ return [[], source.slice(1)];
15
19
  case '\x1B':
16
20
  return [[source.slice(1, 2)], source.slice(2)];
17
21
  case '\\':
@@ -16,6 +16,10 @@ export const text: TextParser = creation(1, false, ({ source, context }) => {
16
16
  return [[source], ''];
17
17
  case 0:
18
18
  switch (source[0]) {
19
+ case '\r':
20
+ assert(!source.includes('\r', 1));
21
+ context.resources && ++context.resources.clock;
22
+ return [[], source.slice(1)];
19
23
  case '\x1B':
20
24
  case '\\':
21
25
  switch (source[1]) {
@@ -60,7 +64,7 @@ export const txt: TxtParser = union([
60
64
  text,
61
65
  ]) as TxtParser;
62
66
 
63
- export const linebreak: LinebreakParser = focus('\n', union([
67
+ export const linebreak: LinebreakParser = focus(/^[\r\n]/, union([
64
68
  text,
65
69
  ])) as LinebreakParser;
66
70
 
@@ -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(1, false, ({ source }) => {
5
+ export const unescsource: UnescapableSourceParser = creation(1, false, ({ source, context }) => {
6
6
  assert(source[0] !== '\x1B');
7
7
  if (source === '') return;
8
8
  const i = source.search(delimiter);
@@ -10,6 +10,12 @@ export const unescsource: UnescapableSourceParser = creation(1, false, ({ source
10
10
  case -1:
11
11
  return [[source], ''];
12
12
  case 0: {
13
+ switch (source[0]) {
14
+ case '\r':
15
+ assert(!source.includes('\r', 1));
16
+ context.resources && ++context.resources.clock;
17
+ return [[], source.slice(1)];
18
+ }
13
19
  const b = source[0] !== '\n' && source[0].trimStart() === '';
14
20
  const i = b || isAlphanumeric(source[0])
15
21
  ? source.search(b ? nonWhitespace : nonAlphanumeric) || 1
@@ -1,13 +1,3 @@
1
- import { Parser } from '../combinator/data/parser';
2
- import { convert } from '../combinator';
3
-
4
- export function format<P extends Parser<HTMLElement | string>>(parser: P): P;
5
- export function format<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
6
- return convert(
7
- source => source.replace(/(?<=^!?)https?:\/\/(?:[[]|[^\p{C}\p{S}\p{P}\s])\S*(?=[^\S\n]*(?:$|\n))/gm, '{ $& }'),
8
- parser);
9
- }
10
-
11
1
  export function stringify(nodes: readonly (HTMLElement | string)[]): string {
12
2
  let acc = '';
13
3
  for (let i = 0; i < nodes.length; ++i) {
@@ -4,7 +4,6 @@ import { union, some, verify, convert, fmap } from '../combinator';
4
4
  import { unsafehtmlentity } from './inline/htmlentity';
5
5
  import { linebreak, unescsource } from './source';
6
6
  import { State } from './context';
7
- import { format } from './util';
8
7
  import { invisibleHTMLEntityNames } from './api/normalize';
9
8
  import { reduce } from 'spica/memoize';
10
9
  import { push } from 'spica/array';
@@ -17,7 +16,7 @@ export function visualize<T extends HTMLElement | string>(parser: Parser<T>): Pa
17
16
  return union([
18
17
  convert(
19
18
  source => source.replace(blankline, line => line.replace(/[\\&<]/g, '\x1B$&')),
20
- verify(format(parser), (ns, rest, context) => !rest && hasVisible(ns, context))),
19
+ verify(parser, (ns, rest, context) => !rest && hasVisible(ns, context))),
21
20
  some(union([linebreak, unescsource])),
22
21
  ]);
23
22
  }
@@ -5,10 +5,10 @@ describe('Unit: util/quote', () => {
5
5
  describe('quote', () => {
6
6
  it('basic', () => {
7
7
  const range = document.createRange();
8
- const el = parse('>>1\n>2\n> a\n>>4 `b` ${c}$ !{d}\n [e](f) ').firstElementChild!;
8
+ const el = parse('>>1\n>2\n> a\n>>4 `b` ${c}$\n!{d}\n [e](f) ').firstElementChild!;
9
9
  range.setStart(el.firstChild!.firstChild!, 0);
10
10
  range.setEnd(el.lastChild!.lastChild!.lastChild!, 1);
11
- assert(quote('3', range) === `>>>1\n> >2\n>> a\n>>3\n> >>4 \`b\` \${c}$ !{d}\n> e`);
11
+ assert(quote('3', range) === `>>>1\n> >2\n>> a\n>>3\n> >>4 \`b\` \${c}$\n> !{d}\n> e`);
12
12
  });
13
13
 
14
14
  it('adjustment', () => {