securemark 0.262.2 → 0.263.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 (58) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/dist/index.js +933 -713
  3. package/index.ts +0 -1
  4. package/karma.conf.js +1 -1
  5. package/package.json +11 -11
  6. package/src/combinator/control/constraint/block.ts +1 -2
  7. package/src/combinator/control/constraint/contract.ts +3 -3
  8. package/src/combinator/control/constraint/line.ts +1 -2
  9. package/src/combinator/control/manipulation/convert.ts +4 -4
  10. package/src/combinator/control/manipulation/indent.ts +0 -1
  11. package/src/combinator/control/manipulation/match.ts +1 -2
  12. package/src/combinator/control/manipulation/scope.ts +3 -4
  13. package/src/combinator/control/manipulation/surround.ts +1 -2
  14. package/src/combinator/control/monad/bind.ts +2 -3
  15. package/src/combinator/data/parser/context.ts +0 -1
  16. package/src/combinator/data/parser/inits.ts +1 -2
  17. package/src/combinator/data/parser/sequence.ts +1 -2
  18. package/src/combinator/data/parser/some.ts +1 -2
  19. package/src/combinator/data/parser/union.ts +4 -12
  20. package/src/parser/api/bind.ts +0 -1
  21. package/src/parser/api/parse.ts +0 -1
  22. package/src/parser/block/codeblock.ts +0 -1
  23. package/src/parser/block/extension/fig.test.ts +2 -1
  24. package/src/parser/block/extension/fig.ts +14 -2
  25. package/src/parser/block/extension/figure.ts +0 -1
  26. package/src/parser/block/extension/table.ts +0 -1
  27. package/src/parser/block/mathblock.ts +0 -1
  28. package/src/parser/block/olist.ts +0 -1
  29. package/src/parser/block.ts +0 -1
  30. package/src/parser/inline/annotation.ts +0 -1
  31. package/src/parser/inline/bracket.ts +0 -1
  32. package/src/parser/inline/extension/index.ts +0 -1
  33. package/src/parser/inline/extension/indexee.ts +0 -1
  34. package/src/parser/inline/extension/label.ts +0 -1
  35. package/src/parser/inline/html.ts +0 -1
  36. package/src/parser/inline/htmlentity.ts +0 -1
  37. package/src/parser/inline/link.ts +0 -1
  38. package/src/parser/inline/media.ts +0 -1
  39. package/src/parser/inline/reference.ts +0 -1
  40. package/src/parser/inline/ruby.ts +0 -1
  41. package/src/parser/inline/template.ts +0 -1
  42. package/src/parser/processor/figure.ts +0 -1
  43. package/src/parser/processor/footnote.ts +0 -1
  44. package/src/parser/segment.ts +0 -1
  45. package/src/parser/source/line.ts +0 -1
  46. package/src/parser/source/str.ts +0 -1
  47. package/src/parser/source/text.ts +0 -1
  48. package/src/parser/visibility.ts +0 -1
  49. package/src/renderer/render/math.ts +0 -1
  50. package/src/renderer/render/media/image.ts +0 -1
  51. package/src/renderer/render/media/twitter.ts +0 -1
  52. package/src/renderer/render/media/video.ts +0 -1
  53. package/src/renderer/render/media/youtube.ts +0 -1
  54. package/src/renderer/render.ts +0 -1
  55. package/src/util/quote.ts +0 -1
  56. package/src/util/scope.ts +0 -2
  57. package/src/util/toc.ts +0 -1
  58. package/webpack.config.js +1 -1
package/index.ts CHANGED
@@ -1,4 +1,3 @@
1
- import 'spica/global';
2
1
  export * from './src/parser';
3
2
  export * from './src/util';
4
3
  export * from './src/renderer';
package/karma.conf.js CHANGED
@@ -6,7 +6,7 @@ module.exports = function (config) {
6
6
  { pattern: 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.js', watched: false, served: false, included: true, integrity: 'sha512-2iwCHjuj+PmdCyvb88rMOch0UcKQxVHi/gsAml1fN3eg82IDaO/cdzzeXX4iF2VzIIes7pODE1/G0ts3QBwslA==' },
7
7
  { pattern: 'https://cdnjs.cloudflare.com/ajax/libs/benchmark/2.1.4/benchmark.js', watched: false, served: false, included: true, integrity: 'sha512-XnVGk21Ij51MbU8XezQpkwZ1/GA8b5qmoVGIOdJLBYycutjkaeemipzRJP7P6mEJl99OfnweA7M3e4WLfuG7Aw==' },
8
8
  { pattern: 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.js', watched: false, served: false, included: true, integrity: 'sha512-n/4gHW3atM3QqRcbCn6ewmpxcLAHGaDjpEBu4xZd47N0W2oQ+6q7oc3PXstrJYXcbNU1OHdQ1T7pAP+gi5Yu8g==' },
9
- { pattern: 'https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/prism.min.js', watched: false, served: false, included: true, integrity: 'https://cdnjs.cloudflare.com/ajax/libs/prism/1.22.0/prism.js' },
9
+ { pattern: 'https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/prism.min.js', watched: false, served: false, included: true, integrity: 'sha512-RDQSW3KoqJMiX0L/UBgwBmH1EmRYp8LBOiLaA8rBHIy+7OGP/7Gxg8vbt8wG4ZYd29P0Fnoq6+LOytCqx3cyoQ==' },
10
10
  { pattern: 'https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/plugins/autoloader/prism-autoloader.min.js', watched: false, served: false, included: true, integrity: 'sha512-fTl/qcO1VgvKtOMApX2PdZzkziyr2stM65GYPLGuYMnuMm1z2JLJG6XVU7C/mR+E7xBUqCivykuhlzfqxXBXbg==' },
11
11
  { pattern: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.0/es5/tex-chtml.min.js', watched: false, served: false, included: true, integrity: 'sha512-93xLZnNMlYI6xaQPf/cSdXoBZ23DThX7VehiGJJXB76HTTalQKPC5CIHuFX8dlQ5yzt6baBQRJ4sDXhzpojRJA==' },
12
12
  { pattern: 'https://cdnjs.cloudflare.com/ajax/libs/dompurify/2.3.8/purify.js', watched: false, served: false, included: true, integrity: 'sha512-QaF+0tDlqVmwZaQSc0kImgYmw+Cd66TxA5D9X70I5V9BNSqk6yBTbyqw2VEUsVYV5OTbxw8HD9d45on1wvYv7g==' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.262.2",
3
+ "version": "0.263.1",
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",
@@ -31,30 +31,30 @@
31
31
  "@types/dompurify": "2.3.4",
32
32
  "@types/jquery": "3.5.14",
33
33
  "@types/mathjax": "0.0.37",
34
- "@types/mocha": "9.1.1",
34
+ "@types/mocha": "10.0.0",
35
35
  "@types/power-assert": "1.5.8",
36
36
  "@types/prismjs": "1.26.0",
37
- "@typescript-eslint/parser": "^5.37.0",
37
+ "@typescript-eslint/parser": "^5.39.0",
38
38
  "babel-loader": "^8.2.5",
39
39
  "babel-plugin-unassert": "^3.2.0",
40
40
  "concurrently": "^7.4.0",
41
- "eslint": "^8.23.1",
41
+ "eslint": "^8.25.0",
42
42
  "eslint-plugin-redos": "^4.4.1",
43
43
  "eslint-webpack-plugin": "^3.2.0",
44
44
  "glob": "^8.0.3",
45
- "karma": "^6.4.0",
45
+ "karma": "^6.4.1",
46
46
  "karma-chrome-launcher": "^3.1.1",
47
47
  "karma-coverage": "^2.2.0",
48
48
  "karma-firefox-launcher": "^2.1.2",
49
49
  "karma-mocha": "^2.0.1",
50
50
  "karma-power-assert": "^1.0.0",
51
51
  "mocha": "^10.0.0",
52
- "npm-check-updates": "^16.1.3",
53
- "semver": "^7.3.7",
54
- "spica": "0.0.626",
55
- "ts-loader": "^9.3.1",
56
- "typed-dom": "^0.0.309",
57
- "typescript": "4.8.3",
52
+ "npm-check-updates": "^16.3.10",
53
+ "semver": "^7.3.8",
54
+ "spica": "0.0.656",
55
+ "ts-loader": "^9.4.1",
56
+ "typed-dom": "^0.0.312",
57
+ "typescript": "4.8.4",
58
58
  "webpack": "^5.74.0",
59
59
  "webpack-cli": "^4.10.0",
60
60
  "webpack-merge": "^5.8.0"
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { Parser, exec } from '../../data/parser';
3
2
  import { Memo } from '../../data/parser/context/memo';
4
3
  import { firstline, isEmpty } from './line';
@@ -10,7 +9,7 @@ export function block<T>(parser: Parser<T>, separation = true): Parser<T> {
10
9
  if (source === '') return;
11
10
  context.memo ??= new Memo();
12
11
  const result = parser({ source, context });
13
- if (!result) return;
12
+ if (result === undefined) return;
14
13
  const rest = exec(result);
15
14
  if (separation && !isEmpty(firstline(rest))) return;
16
15
  assert(rest === '' || source[source.length - rest.length - 1] === '\n');
@@ -1,4 +1,4 @@
1
- import { global, undefined } from 'spica/global';
1
+ import 'spica/global';
2
2
  import { isArray } from 'spica/alias';
3
3
  import { Parser, Ctx, Tree, Context, eval, exec, check } from '../../data/parser';
4
4
 
@@ -27,7 +27,7 @@ export function validate<T>(patterns: string | RegExp | (string | RegExp)[], has
27
27
  if (!match(source)) return;
28
28
  const result = parser!({ source, context });
29
29
  assert(check(source, result));
30
- if (!result) return;
30
+ if (result === undefined) return;
31
31
  assert(exec(result).length < source.length);
32
32
  return exec(result).length < source.length
33
33
  ? result
@@ -42,7 +42,7 @@ export function verify<T>(parser: Parser<T>, cond: (results: readonly T[], rest:
42
42
  if (source === '') return;
43
43
  const result = parser({ source, context });
44
44
  assert(check(source, result));
45
- if (!result) return;
45
+ if (result === undefined) return;
46
46
  if (!cond(eval(result), exec(result), context)) return;
47
47
  assert(exec(result).length < source.length);
48
48
  return exec(result).length < source.length
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { Parser, eval, exec, check } from '../../data/parser';
3
2
  import { Memo } from '../../data/parser/context/memo';
4
3
 
@@ -14,7 +13,7 @@ export function line<T>(parser: Parser<T>): Parser<T> {
14
13
  const result = parser({ source: line, context });
15
14
  assert(check(line, result));
16
15
  context.offset -= source.length - line.length;
17
- if (!result) return;
16
+ if (result === undefined) return;
18
17
  return isEmpty(exec(result))
19
18
  ? [eval(result), source.slice(line.length)]
20
19
  : undefined;
@@ -1,11 +1,11 @@
1
- import { Parser, check } from '../../data/parser';
1
+ import { Parser, Ctx, Context, check } from '../../data/parser';
2
2
 
3
- export function convert<P extends Parser<unknown>>(conv: (source: string) => string, parser: P): P;
4
- export function convert<T>(conv: (source: string) => string, parser: Parser<T>): Parser<T> {
3
+ export function convert<P extends Parser<unknown>>(conv: (source: string, context: Context<P>) => string, parser: P): P;
4
+ export function convert<T>(conv: (source: string, context: Ctx) => string, parser: Parser<T>): Parser<T> {
5
5
  assert(parser);
6
6
  return ({ source, context }) => {
7
7
  if (source === '') return;
8
- const src = conv(source);
8
+ const src = conv(source, context);
9
9
  if (src === '') return [[], ''];
10
10
  context.offset ??= 0;
11
11
  context.offset += source.length - src.length;
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { Parser, eval, exec } from '../../data/parser';
3
2
  import { some } from '../../data/parser/some';
4
3
  import { block } from '../constraint/block';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { Parser, exec, check } from '../../data/parser';
3
2
 
4
3
  export function match<P extends Parser<unknown>>(pattern: RegExp, f: (matched: RegExpMatchArray) => P): P;
@@ -11,7 +10,7 @@ export function match<T>(pattern: RegExp, f: (matched: RegExpMatchArray) => Pars
11
10
  assert(source.startsWith(param[0]));
12
11
  const result = f(param)({ source, context });
13
12
  assert(check(source, result, false));
14
- if (!result) return;
13
+ if (result === undefined) return;
15
14
  return exec(result).length < source.length && exec(result).length <= source.length
16
15
  ? result
17
16
  : undefined;
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { Parser, Context, eval, exec, check } from '../../data/parser';
3
2
 
4
3
  export function focus<P extends Parser<unknown>>(scope: string | RegExp, parser: P): P;
@@ -18,7 +17,7 @@ export function focus<T>(scope: string | RegExp, parser: Parser<T>): Parser<T> {
18
17
  const result = parser({ source: src, context });
19
18
  assert(check(src, result));
20
19
  context.offset -= source.length - src.length;
21
- if (!result) return;
20
+ if (result === undefined) return;
22
21
  assert(exec(result).length < src.length);
23
22
  return exec(result).length < src.length
24
23
  ? [eval(result), exec(result) + source.slice(src.length)]
@@ -38,7 +37,7 @@ export function rewrite<T>(scope: Parser<unknown>, parser: Parser<T>): Parser<T>
38
37
  const res1 = scope({ source, context });
39
38
  assert(check(source, res1));
40
39
  context.memo = memo;
41
- if (!res1 || exec(res1).length >= source.length) return;
40
+ if (res1 === undefined || exec(res1).length >= source.length) return;
42
41
  const src = source.slice(0, source.length - exec(res1).length);
43
42
  assert(src !== '');
44
43
  assert(source.startsWith(src));
@@ -47,7 +46,7 @@ export function rewrite<T>(scope: Parser<unknown>, parser: Parser<T>): Parser<T>
47
46
  const res2 = parser({ source: src, context });
48
47
  assert(check(src, res2));
49
48
  context.offset -= source.length - src.length;
50
- if (!res2) return;
49
+ if (res2 === undefined) return;
51
50
  assert(exec(res2) === '');
52
51
  return exec(res2).length < src.length
53
52
  ? [eval(res2), exec(res2) + exec(res1)]
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { Parser, Input, Result, Ctx, Tree, Context, SubParsers, SubTree, IntermediateParser, eval, exec, check } from '../../data/parser';
3
2
  import { fmap } from '../monad/fmap';
4
3
  import { unshift, push } from 'spica/array';
@@ -43,7 +42,7 @@ export function surround<T>(
43
42
  if (lmr_ === '') return;
44
43
  const res1 = opener({ source: lmr_, context });
45
44
  assert(check(lmr_, res1, false));
46
- if (!res1) return;
45
+ if (res1 === undefined) return;
47
46
  const rl = eval(res1);
48
47
  const mr_ = exec(res1);
49
48
  const res2 = mr_ !== '' ? parser({ source: mr_, context }) : undefined;
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { Parser, Result, Ctx, Tree, Context, SubParsers, SubTree, IntermediateParser, eval, exec, check } from '../../data/parser';
3
2
 
4
3
  export function bind<P extends Parser<unknown>>(parser: IntermediateParser<P>, f: (nodes: SubTree<P>[], rest: string, context: Context<P>) => Result<Tree<P>, Context<P>, SubParsers<P>>): P;
@@ -11,11 +10,11 @@ export function bind<T, U>(parser: Parser<T>, f: (nodes: T[], rest: string, cont
11
10
  if (source === '') return;
12
11
  const res1 = parser({ source, context });
13
12
  assert(check(source, res1));
14
- if (!res1) return;
13
+ if (res1 === undefined) return;
15
14
  const res2 = f(eval(res1), exec(res1), context);
16
15
  assert(check(source, res2));
17
16
  assert(check(exec(res1), res2, false));
18
- if (!res2) return;
17
+ if (res2 === undefined) return;
19
18
  return exec(res2).length <= exec(res1).length
20
19
  ? res2
21
20
  : undefined;
@@ -1,4 +1,3 @@
1
- import { undefined, Array, Object } from 'spica/global';
2
1
  import { hasOwnProperty, ObjectCreate } from 'spica/alias';
3
2
  import { Parser, Result, Ctx, Context, eval, exec, Tree } from '../../data/parser';
4
3
  import { Memo } from './context/memo';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { Parser, Ctx, Tree, Context, SubParsers, SubTree, eval, exec, check } from '../parser';
3
2
  import { push } from 'spica/array';
4
3
 
@@ -14,7 +13,7 @@ export function inits<T, D extends Parser<T>[]>(parsers: D, resume?: (nodes: T[]
14
13
  if (context.delimiters?.match(rest, context.precedence)) break;
15
14
  const result = parsers[i]({ source: rest, context });
16
15
  assert(check(rest, result));
17
- if (!result) break;
16
+ if (result === undefined) break;
18
17
  nodes = nodes
19
18
  ? push(nodes, eval(result))
20
19
  : eval(result);
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { Parser, Ctx, Tree, Context, SubParsers, SubTree, eval, exec, check } from '../parser';
3
2
  import { push } from 'spica/array';
4
3
 
@@ -14,7 +13,7 @@ export function sequence<T, D extends Parser<T>[]>(parsers: D, resume?: (nodes:
14
13
  if (context.delimiters?.match(rest, context.precedence)) return;
15
14
  const result = parsers[i]({ source: rest, context });
16
15
  assert(check(rest, result));
17
- if (!result) return;
16
+ if (result === undefined) return;
18
17
  nodes = nodes
19
18
  ? push(nodes, eval(result))
20
19
  : eval(result);
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { Parser, eval, exec, check } from '../parser';
3
2
  import { Delimiters } from './context/delimiter';
4
3
  import { unshift, push } from 'spica/array';
@@ -30,7 +29,7 @@ export function some<T>(parser: Parser<T>, end?: string | RegExp | number, delim
30
29
  if (context.delimiters?.match(rest, context.precedence)) break;
31
30
  const result = parser({ source: rest, context });
32
31
  assert.doesNotThrow(() => limit < 0 && check(rest, result));
33
- if (!result) break;
32
+ if (result === undefined) break;
34
33
  nodes = nodes
35
34
  ? nodes.length < eval(result).length
36
35
  ? unshift(nodes, eval(result))
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { Parser, Ctx, Tree, Context, SubParsers, SubTree } from '../parser';
3
2
 
4
3
  export function union<P extends Parser<unknown>>(parsers: SubParsers<P>): SubTree<P> extends Tree<P> ? P : Parser<SubTree<P>, Context<P>, SubParsers<P>>;
@@ -9,17 +8,10 @@ export function union<T, D extends Parser<T>[]>(parsers: D): Parser<T, Ctx, D> {
9
8
  return () => undefined;
10
9
  case 1:
11
10
  return parsers[0];
12
- case 2:
13
- return input => parsers[0](input) ?? parsers[1](input);
14
- case 3:
15
- return input => parsers[0](input) ?? parsers[1](input) ?? parsers[2](input);
16
11
  default:
17
- return input => {
18
- for (let i = 0; i < parsers.length; ++i) {
19
- const parser = parsers[i];
20
- const result = parser(input);
21
- if (result) return result;
22
- }
23
- };
12
+ return eval([
13
+ 'input =>',
14
+ parsers.map((_, i) => `|| parsers[${i}](input)`).join('').slice(2),
15
+ ].join(''));
24
16
  }
25
17
  }
@@ -1,4 +1,3 @@
1
- import { undefined, location } from 'spica/global';
2
1
  import { ParserSettings, Progress } from '../../..';
3
2
  import { MarkdownParser } from '../../../markdown';
4
3
  import { eval } from '../../combinator/data/parser';
@@ -1,4 +1,3 @@
1
- import { location } from 'spica/global';
2
1
  import { ParserOptions } from '../../..';
3
2
  import { MarkdownParser } from '../../../markdown';
4
3
  import { eval } from '../../combinator/data/parser';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { CodeBlockParser } from '../block';
3
2
  import { eval } from '../../combinator/data/parser';
4
3
  import { some, block, validate, fence, clear, fmap } from '../../combinator';
@@ -10,7 +10,6 @@ describe('Unit: parser/block/extension/fig', () => {
10
10
  assert.deepStrictEqual(inspect(parser('\n!https://host\n')), undefined);
11
11
  assert.deepStrictEqual(inspect(parser('[$group-name]\nhttps://host')), undefined);
12
12
  assert.deepStrictEqual(inspect(parser('[$group-name]\nhttps://host\n')), undefined);
13
- assert.deepStrictEqual(inspect(parser('[$group-name]\n!https://host\na')), undefined);
14
13
  assert.deepStrictEqual(inspect(parser('[$group-name]\n !https://host')), undefined);
15
14
  assert.deepStrictEqual(inspect(parser('[$group-name]\n\n!https://host')), undefined);
16
15
  assert.deepStrictEqual(inspect(parser('[$group-name]a\nhttps://host')), undefined);
@@ -43,6 +42,8 @@ describe('Unit: parser/block/extension/fig', () => {
43
42
  assert.deepStrictEqual(inspect(parser('[$group-name]\n!> _a_')), [['<figure data-type="quote" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><blockquote><section><p><em>a</em></p><h2>References</h2><ol class="references"></ol></section></blockquote></div></figure>'], '']);
44
43
  assert.deepStrictEqual(inspect(parser('[$group-name]\n![]{https://host}')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure>'], '']);
45
44
  assert.deepStrictEqual(inspect(parser('[$group-name]\n![]{https://host}\n')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure>'], '']);
45
+ assert.deepStrictEqual(inspect(parser('[$group-name]\n!https://host\ncaption')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext">caption</span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure>'], '']);
46
+ assert.deepStrictEqual(inspect(parser('[$group-name]\n!https://host\ncaption\n')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext">caption</span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure>'], '']);
46
47
  assert.deepStrictEqual(inspect(parser('$group-name\n!https://host')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure>'], '']);
47
48
  });
48
49
 
@@ -8,6 +8,7 @@ import { segment as seg_math } from '../mathblock';
8
8
  import { segment as seg_table } from './table';
9
9
  import { segment as seg_blockquote } from '../blockquote';
10
10
  import { segment as seg_placeholder } from './placeholder';
11
+ import { media, shortmedia } from '../../inline';
11
12
 
12
13
  import FigParser = ExtensionParser.FigParser;
13
14
 
@@ -25,10 +26,21 @@ export const segment: FigParser.SegmentParser = block(validate(['[$', '$'],
25
26
  ])));
26
27
 
27
28
  export const fig: FigParser = block(rewrite(segment, verify(convert(
28
- source => {
29
+ (source, context) => {
29
30
  const fence = (/^[^\n]*\n!?>+\s/.test(source) && source.match(/^~{3,}(?=[^\S\n]*$)/mg) || [])
30
31
  .reduce((max, fence) => fence > max ? fence : max, '~~') + '~';
31
- return `${fence}figure ${source}\n\n${fence}`;
32
+ return parser({ source, context })
33
+ ? `${fence}figure ${source.replace(/^(.+\n.+\n)([\S\s]+?)\n?$/, '$1\n$2')}\n${fence}`
34
+ : `${fence}figure ${source}\n\n${fence}`;
32
35
  },
33
36
  union([figure])),
34
37
  ([el]) => el.tagName === 'FIGURE')));
38
+
39
+ const parser = sequence([
40
+ line(close(seg_label, /^(?=\s).*\n/)),
41
+ line(union([
42
+ media,
43
+ shortmedia,
44
+ ])),
45
+ some(contentline),
46
+ ]);
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { ExtensionParser } from '../../block';
3
2
  import { union, inits, sequence, some, state, block, line, fence, rewrite, close, match, convert, trimEnd, fallback, fmap } from '../../../combinator';
4
3
  import { str, contentline, emptyline } from '../../source';
@@ -1,4 +1,3 @@
1
- import { undefined, BigInt, Array } from 'spica/global';
2
1
  import { max, min, isArray } from 'spica/alias';
3
2
  import { ExtensionParser } from '../../block';
4
3
  import { Tree, eval } from '../../../combinator/data/parser';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { MathBlockParser } from '../block';
3
2
  import { block, validate, fence, clear, fmap } from '../../combinator';
4
3
  import { html } from 'typed-dom/dom';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { OListParser } from '../block';
3
2
  import { Parser } from '../../combinator/data/parser';
4
3
  import { union, inits, subsequence, some, creation, state, block, line, validate, indent, focus, rewrite, open, match, fallback, lazy, fmap } from '../../combinator';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { MarkdownParser } from '../../markdown';
3
2
  import { union, reset, creation, open, fallback, recover } from '../combinator';
4
3
  import { emptyline } from './source';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { AnnotationParser } from '../inline';
3
2
  import { union, some, context, syntax, constraint, surround, lazy } from '../../combinator';
4
3
  import { inline } from '../inline';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { BracketParser } from '../inline';
3
2
  import { union, some, syntax, surround, lazy } from '../../combinator';
4
3
  import { inline } from '../inline';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { ExtensionParser } from '../../inline';
3
2
  import { union, some, syntax, creation, precedence, constraint, validate, surround, open, lazy, fmap } from '../../../combinator';
4
3
  import { inline } from '../../inline';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { MarkdownParser } from '../../../../markdown';
3
2
  import { Parser } from '../../../combinator/data/parser';
4
3
  import { fmap } from '../../../combinator';
@@ -1,4 +1,3 @@
1
- import { Array } from 'spica/global';
2
1
  import { ExtensionParser } from '../../inline';
3
2
  import { union, constraint, creation, validate, surround, clear, fmap } from '../../../combinator';
4
3
  import { str } from '../../source';
@@ -1,4 +1,3 @@
1
- import { undefined, Object } from 'spica/global';
2
1
  import { HTMLParser } from '../inline';
3
2
  import { union, subsequence, some, syntax, validate, focus, surround, open, match, lazy } from '../../combinator';
4
3
  import { inline } from '../inline';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { HTMLEntityParser, UnsafeHTMLEntityParser } from '../inline';
3
2
  import { union, creation, validate, focus, fmap } from '../../combinator';
4
3
  import { html } from 'typed-dom/dom';
@@ -1,4 +1,3 @@
1
- import { undefined, location, encodeURI, decodeURI, Location } from 'spica/global';
2
1
  import { MarkdownParser } from '../../../markdown';
3
2
  import { LinkParser } from '../inline';
4
3
  import { Result, eval, exec } from '../../combinator/data/parser';
@@ -1,4 +1,3 @@
1
- import { undefined, location } from 'spica/global';
2
1
  import { MediaParser } from '../inline';
3
2
  import { union, inits, tails, some, syntax, creation, precedence, constraint, validate, verify, surround, open, dup, lazy, fmap, bind } from '../../combinator';
4
3
  import { unsafelink, uri, option as linkoption, resolve } from './link';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { ReferenceParser } from '../inline';
3
2
  import { union, subsequence, some, context, syntax, creation, constraint, surround, open, lazy, bind } from '../../combinator';
4
3
  import { inline } from '../inline';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { RubyParser } from '../inline';
3
2
  import { eval, exec } from '../../combinator/data/parser';
4
3
  import { sequence, syntax, creation, validate, verify, surround, lazy, fmap } from '../../combinator';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { TemplateParser } from '../inline';
3
2
  import { union, some, syntax, creation, precedence, surround, lazy } from '../../combinator';
4
3
  import { escsource, str } from '../source';
@@ -1,4 +1,3 @@
1
- import { Infinity, Set, Map } from 'spica/global';
2
1
  import { number as calculate, isFixed } from '../inline/extension/label';
3
2
  import { MultiQueue } from 'spica/queue';
4
3
  import { push } from 'spica/array';
@@ -1,4 +1,3 @@
1
- import { undefined, Infinity, Map, Node } from 'spica/global';
2
1
  import { text } from '../inline/extension/indexee';
3
2
  import { MultiQueue } from 'spica/queue';
4
3
  import { frag, html, define } from 'typed-dom/dom';
@@ -1,4 +1,3 @@
1
- import { Blob } from 'spica/global';
2
1
  import { MarkdownParser } from '../../markdown';
3
2
  import { eval, exec } from '../combinator/data/parser';
4
3
  import { union, some } from '../combinator';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { AnyLineParser, EmptyLineParser, ContentLineParser } from '../source';
3
2
  import { line, isEmpty } from '../../combinator';
4
3
 
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { StrParser } from '../source';
3
2
  import { Parser, Context } from '../../combinator/data/parser';
4
3
  import { creation } from '../../combinator';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { TextParser, TxtParser, LinebreakParser } from '../source';
3
2
  import { union, creation, focus } from '../../combinator';
4
3
  import { str } from './str';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { MarkdownParser } from '../../markdown';
3
2
  import { Parser, Input, eval } from '../combinator/data/parser';
4
3
  import { union, some, verify, convert, fmap } from '../combinator';
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { Dict } from 'spica/dict';
3
2
  import { html, define } from 'typed-dom/dom';
4
3
 
@@ -1,4 +1,3 @@
1
- import { Object } from 'spica/global';
2
1
  import { Dict } from 'spica/dict';
3
2
  import { define } from 'typed-dom/dom';
4
3
 
@@ -1,4 +1,3 @@
1
- import { window, document } from 'spica/global';
2
1
  import { parse } from '../../../parser';
3
2
  import { html as h, define } from 'typed-dom/dom';
4
3
  import DOMPurify from 'dompurify';
@@ -1,4 +1,3 @@
1
- import { undefined, Object } from 'spica/global';
2
1
  import { html } from 'typed-dom/dom';
3
2
 
4
3
  const extensions = [
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { html } from 'typed-dom/dom';
3
2
 
4
3
  export function youtube(source: HTMLImageElement, url: URL): HTMLElement | undefined {
@@ -1,4 +1,3 @@
1
- import { location } from 'spica/global';
2
1
  import { RenderingOptions } from '../../';
3
2
  import { code } from './render/code';
4
3
  import { math } from './render/math';
package/src/util/quote.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { Element } from 'spica/global';
2
1
  import { exec } from '../combinator/data/parser';
3
2
  import { cite } from '../parser/block/reply/cite';
4
3
  import { define } from 'typed-dom/dom';
package/src/util/scope.ts CHANGED
@@ -1,5 +1,3 @@
1
- import { undefined, WeakMap } from 'spica/global';
2
-
3
1
  export function scope(
4
2
  base: DocumentFragment | HTMLElement | ShadowRoot,
5
3
  filter: string = '',
package/src/util/toc.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { undefined } from 'spica/global';
2
1
  import { push } from 'spica/array';
3
2
  import { html } from 'typed-dom/dom';
4
3
 
package/webpack.config.js CHANGED
@@ -6,7 +6,7 @@ const { mergeWithRules } = require('webpack-merge');
6
6
  const ESLintPlugin = require('eslint-webpack-plugin');
7
7
  const pkg = require('./package.json');
8
8
 
9
- shell('rm -rf coverage');
9
+ shell('rm -rf dist coverage');
10
10
 
11
11
  module.exports = env => {
12
12
  const merge = mergeWithRules({