securemark 0.266.0 → 0.268.0

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 (46) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/dist/index.js +75 -79
  4. package/index.d.ts +7 -8
  5. package/markdown.d.ts +26 -9
  6. package/package.json +7 -7
  7. package/src/combinator/control/constraint/block.ts +2 -2
  8. package/src/combinator/control/constraint/line.ts +2 -2
  9. package/src/combinator/control/manipulation/fence.ts +4 -4
  10. package/src/parser/api/bind.ts +1 -1
  11. package/src/parser/api/parse.test.ts +0 -2
  12. package/src/parser/api/parse.ts +1 -1
  13. package/src/parser/autolink.ts +15 -22
  14. package/src/parser/block/blockquote.ts +1 -1
  15. package/src/parser/block/codeblock.ts +2 -2
  16. package/src/parser/block/olist.test.ts +2 -2
  17. package/src/parser/block/olist.ts +2 -2
  18. package/src/parser/block/pagebreak.test.ts +31 -0
  19. package/src/parser/block/pagebreak.ts +7 -0
  20. package/src/parser/block/paragraph.test.ts +3 -0
  21. package/src/parser/block/reply/cite.ts +1 -2
  22. package/src/parser/block/reply/quote.test.ts +3 -0
  23. package/src/parser/block/reply/quote.ts +15 -9
  24. package/src/parser/block/sidefence.ts +1 -1
  25. package/src/parser/block/ulist.test.ts +2 -2
  26. package/src/parser/block/ulist.ts +2 -2
  27. package/src/parser/block.ts +3 -3
  28. package/src/parser/inline/autolink/account.ts +3 -5
  29. package/src/parser/inline/autolink/anchor.test.ts +2 -2
  30. package/src/parser/inline/autolink/anchor.ts +4 -3
  31. package/src/parser/inline/autolink/channel.test.ts +0 -2
  32. package/src/parser/inline/autolink/channel.ts +0 -1
  33. package/src/parser/inline/autolink/hashnum.test.ts +1 -1
  34. package/src/parser/inline/autolink/hashtag.test.ts +2 -6
  35. package/src/parser/inline/autolink/hashtag.ts +7 -20
  36. package/src/parser/inline/extension/index.ts +1 -1
  37. package/src/parser/inline/extension/indexee.ts +1 -0
  38. package/src/parser/inline/link.ts +1 -0
  39. package/src/parser/inline.test.ts +5 -2
  40. package/src/parser/source/line.ts +3 -3
  41. package/src/parser/source/str.ts +1 -1
  42. package/src/parser/util.ts +10 -0
  43. package/src/parser/visibility.ts +2 -1
  44. package/src/util/quote.ts +9 -2
  45. package/src/parser/block/horizontalrule.test.ts +0 -31
  46. package/src/parser/block/horizontalrule.ts +0 -7
@@ -31,7 +31,7 @@ export function stropt(pattern: string | RegExp): Parser<string, Context<StrPars
31
31
  if (source === '') return;
32
32
  return source.slice(0, pattern.length) === pattern
33
33
  ? [[pattern], source.slice(pattern.length)]
34
- : undefined;
34
+ : [[''], source];
35
35
  })
36
36
  : creation(1, false, ({ source }) => {
37
37
  if (source === '') return;
@@ -1,3 +1,13 @@
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
+
1
11
  export function stringify(nodes: readonly (HTMLElement | string)[]): string {
2
12
  let acc = '';
3
13
  for (let i = 0; i < nodes.length; ++i) {
@@ -4,6 +4,7 @@ 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';
7
8
  import { invisibleHTMLEntityNames } from './api/normalize';
8
9
  import { reduce } from 'spica/memoize';
9
10
  import { push } from 'spica/array';
@@ -16,7 +17,7 @@ export function visualize<T extends HTMLElement | string>(parser: Parser<T>): Pa
16
17
  return union([
17
18
  convert(
18
19
  source => source.replace(blankline, line => line.replace(/[\\&<]/g, '\x1B$&')),
19
- verify(parser, (ns, rest, context) => !rest && hasVisible(ns, context))),
20
+ verify(format(parser), (ns, rest, context) => !rest && hasVisible(ns, context))),
20
21
  some(union([linebreak, unescsource])),
21
22
  ]);
22
23
  }
package/src/util/quote.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { exec } from '../combinator/data/parser';
2
2
  import { cite } from '../parser/block/reply/cite';
3
- import { define } from 'typed-dom/dom';
3
+ //import { url } from '../parser/inline/autolink/url';
4
4
 
5
5
  export function quote(anchor: string, range: Range): string {
6
6
  if (exec(cite({ source: `>>${anchor}`, context: {} })) !== '') throw new Error(`Invalid anchor: ${anchor}`);
@@ -13,8 +13,15 @@ export function quote(anchor: string, range: Range): string {
13
13
  switch (true) {
14
14
  case el.matches('code'):
15
15
  case el.matches('.math'):
16
- define(el, el.getAttribute('data-src')!);
16
+ el.replaceWith(el.getAttribute('data-src')!);
17
17
  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;
18
25
  case el.matches('.media'):
19
26
  el.replaceWith(
20
27
  /[\s{}]/.test(el.getAttribute('data-src')!)
@@ -1,31 +0,0 @@
1
- import { horizontalrule } from './horizontalrule';
2
- import { some } from '../../combinator';
3
- import { inspect } from '../../debug.test';
4
-
5
- describe('Unit: parser/block/horizontalrule', () => {
6
- describe('horizontalrule', () => {
7
- const parser = (source: string) => some(horizontalrule)({ source, context: {} });
8
-
9
- it('invalid', () => {
10
- assert.deepStrictEqual(inspect(parser('')), undefined);
11
- assert.deepStrictEqual(inspect(parser('\n')), undefined);
12
- assert.deepStrictEqual(inspect(parser('-')), undefined);
13
- assert.deepStrictEqual(inspect(parser('--')), undefined);
14
- assert.deepStrictEqual(inspect(parser('--\n-')), undefined);
15
- assert.deepStrictEqual(inspect(parser('---a')), undefined);
16
- assert.deepStrictEqual(inspect(parser('---\na')), undefined);
17
- assert.deepStrictEqual(inspect(parser('- - -')), undefined);
18
- assert.deepStrictEqual(inspect(parser(' ---')), undefined);
19
- assert.deepStrictEqual(inspect(parser('***')), undefined);
20
- });
21
-
22
- it('valid', () => {
23
- assert.deepStrictEqual(inspect(parser('---')), [['<hr>'], '']);
24
- assert.deepStrictEqual(inspect(parser('--- ')), [['<hr>'], '']);
25
- assert.deepStrictEqual(inspect(parser('---\n')), [['<hr>'], '']);
26
- assert.deepStrictEqual(inspect(parser('----')), [['<hr>'], '']);
27
- });
28
-
29
- });
30
-
31
- });
@@ -1,7 +0,0 @@
1
- import { HorizontalRuleParser } from '../block';
2
- import { block, line, focus } from '../../combinator';
3
- import { html } from 'typed-dom/dom';
4
-
5
- export const horizontalrule: HorizontalRuleParser = block(line(focus(
6
- /^-{3,}[^\S\n]*(?:$|\n)/,
7
- () => [[html('hr')], ''])));