securemark 0.253.0 → 0.254.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.
package/.eslintrc.json CHANGED
@@ -15,8 +15,14 @@
15
15
  "error",
16
16
  {
17
17
  "ignoreErrors": false,
18
+ "maxPatternSize": 3000,
19
+ "maxRepeatCount": 256,
20
+ "maxSimpleRepeatCount": 256,
18
21
  "attackTimeout": null,
19
- "timeout": 30000
22
+ "incubationTimeout": null,
23
+ "recallTimeout": null,
24
+ "seedingTimeout": null,
25
+ "timeout": 1e6
20
26
  }
21
27
  ]
22
28
  },
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.254.0
4
+
5
+ - Remove `sup`, `sub`, and `small` HTML tags.
6
+
7
+ ## 0.253.2
8
+
9
+ - Refactoring.
10
+
11
+ ## 0.253.1
12
+
13
+ - Refactoring.
14
+
3
15
  ## 0.253.0
4
16
 
5
17
  - Change annotation processing.
package/README.md CHANGED
@@ -43,7 +43,7 @@ https://falsandtru.github.io/securemark/
43
43
  - Preformattedtext (```)
44
44
  - HorizontalRule (---)
45
45
  - Inline markups (*, `, []{}, {}, ![]{}, !{}, \[](), ++, ~~, (()), ...)
46
- - Inline HTML tags (\<small>, \<bdi>, ...)
46
+ - Inline HTML tags (\<bdi>, \<bdo>)
47
47
  - Autolink (https://host, user@host, @user)
48
48
  - Shortmedia (!https://host/image.png, !https://youtu.be/...)
49
49
  - Syntex highlight (```lang filename)
package/design.md CHANGED
@@ -307,3 +307,9 @@ MarkdownはGFMのように最初から高機能で完成度の高い拡張不要
307
307
 
308
308
  Data URIは保存および転送容量削減ならびにユーザーおよび管理者双方の集約的管理のためサポートしない。
309
309
  特に規制および公開レベルの媒体別設定の実現のためテキストとメディアの分離が必須となる。
310
+
311
+ ### HTML
312
+
313
+ - \<small>: 法的表記を縮小表示すべきでないため削除。
314
+ - \<sub>: \<small>の代わりに使用されないよう削除。他の構文との相性も悪い。
315
+ - \<sup>: 同上。
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! securemark v0.253.0 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
1
+ /*! securemark v0.254.0 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
2
2
  (function webpackUniversalModuleDefinition(root, factory) {
3
3
  if(typeof exports === 'object' && typeof module === 'object')
4
4
  module.exports = factory(require("DOMPurify"), require("Prism"));
@@ -758,7 +758,26 @@ function run() {
758
758
 
759
759
  /***/ }),
760
760
 
761
- /***/ 413:
761
+ /***/ 5529:
762
+ /***/ ((__unused_webpack_module, exports) => {
763
+
764
+ "use strict";
765
+
766
+
767
+ Object.defineProperty(exports, "__esModule", ({
768
+ value: true
769
+ }));
770
+ exports.equal = void 0;
771
+
772
+ function equal(a, b) {
773
+ return a === a ? a === b : b !== b;
774
+ }
775
+
776
+ exports.equal = equal;
777
+
778
+ /***/ }),
779
+
780
+ /***/ 5084:
762
781
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
763
782
 
764
783
  "use strict";
@@ -863,25 +882,6 @@ exports.MultiMap = MultiMap;
863
882
 
864
883
  /***/ }),
865
884
 
866
- /***/ 5529:
867
- /***/ ((__unused_webpack_module, exports) => {
868
-
869
- "use strict";
870
-
871
-
872
- Object.defineProperty(exports, "__esModule", ({
873
- value: true
874
- }));
875
- exports.equal = void 0;
876
-
877
- function equal(a, b) {
878
- return a === a ? a === b : b !== b;
879
- }
880
-
881
- exports.equal = equal;
882
-
883
- /***/ }),
884
-
885
885
  /***/ 7822:
886
886
  /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
887
887
 
@@ -1417,7 +1417,7 @@ Object.defineProperty(exports, "__esModule", ({
1417
1417
  value: true
1418
1418
  }));
1419
1419
 
1420
- __exportStar(__webpack_require__(413), exports);
1420
+ __exportStar(__webpack_require__(5084), exports);
1421
1421
 
1422
1422
  /***/ }),
1423
1423
 
@@ -3314,7 +3314,7 @@ function bind(target, settings) {
3314
3314
  };
3315
3315
  }
3316
3316
 
3317
- for (const el of (0, footnote_1.footnote)(next(0)?.parentNode ?? target, settings.footnotes, context)) {
3317
+ for (const el of (0, footnote_1.footnote)(next(0)?.parentNode ?? target, settings.footnotes, context, bottom)) {
3318
3318
  el ? yield {
3319
3319
  type: 'footnote',
3320
3320
  value: el
@@ -4289,10 +4289,10 @@ exports.message = (0, combinator_1.block)((0, combinator_1.validate)('~~~', (0,
4289
4289
  }, `${opener}${body}${closer}`)];
4290
4290
  }
4291
4291
 
4292
- return [(0, dom_1.html)('div', {
4292
+ return [(0, dom_1.html)('section', {
4293
4293
  class: `message`,
4294
4294
  'data-type': type
4295
- }, (0, array_1.unshift)([(0, dom_1.html)('h6', title(type))], [...(0, segment_1.segment)(body)].reduce((acc, seg) => (0, array_1.push)(acc, (0, parser_1.eval)(content(seg, context), [])), [])))];
4295
+ }, (0, array_1.unshift)([(0, dom_1.html)('h1', title(type))], [...(0, segment_1.segment)(body)].reduce((acc, seg) => (0, array_1.push)(acc, (0, parser_1.eval)(content(seg, context), [])), [])))];
4296
4296
  })));
4297
4297
 
4298
4298
  function title(type) {
@@ -4514,7 +4514,8 @@ function format(rows) {
4514
4514
  let lHeadCellIdx;
4515
4515
  let rHeadCellIdx;
4516
4516
 
4517
- for (let j = 0, jn = 0n; j < cells.length; jn = (0, global_1.BigInt)(++j)) {
4517
+ for (let j = 0; j < cells.length; ++j) {
4518
+ const jn = (0, global_1.BigInt)(j);
4518
4519
  const isVirtual = !!ranges[i]?.[j];
4519
4520
  const cell = isVirtual ? (0, array_1.splice)(cells, j, 0, global_1.undefined) && ranges[i][j] : cells[j];
4520
4521
  const isHeadCell = cell.tagName === 'TH';
@@ -4545,8 +4546,8 @@ function format(rows) {
4545
4546
 
4546
4547
  if (colSpan > 1) {
4547
4548
  (0, array_1.splice)(cells, j + 1, 0, ...(0, global_1.Array)(colSpan - 1));
4548
- heads |= (0, global_1.BigInt)(+`0b${`${heads & 1n << jn && 1}`.repeat(colSpan)}`) << jn;
4549
- highlights |= (0, global_1.BigInt)(+`0b${`${highlights & 1n << jn && 1}`.repeat(colSpan)}`) << jn;
4549
+ heads |= heads & 1n << jn && ~(~0n << (0, global_1.BigInt)(colSpan)) << jn;
4550
+ highlights |= highlights & 1n << jn && ~(~0n << (0, global_1.BigInt)(colSpan)) << jn;
4550
4551
  j += colSpan - 1;
4551
4552
  }
4552
4553
 
@@ -6209,20 +6210,24 @@ const cache_1 = __webpack_require__(9210);
6209
6210
 
6210
6211
  const array_1 = __webpack_require__(8112);
6211
6212
 
6212
- const tags = global_1.Object.freeze(['wbr', 'sup', 'sub', 'small', 'bdo', 'bdi']);
6213
- const attrspec = {
6213
+ const tags = global_1.Object.freeze(['bdo', 'bdi']);
6214
+ const attrspecs = {
6214
6215
  bdo: {
6215
6216
  dir: global_1.Object.freeze(['ltr', 'rtl'])
6216
6217
  }
6217
6218
  };
6218
- global_1.Object.setPrototypeOf(attrspec, null);
6219
- global_1.Object.values(attrspec).forEach(o => global_1.Object.setPrototypeOf(o, null));
6220
- exports.html = (0, combinator_1.lazy)(() => (0, combinator_1.creator)((0, combinator_1.validate)('<', (0, combinator_1.validate)(/^<[a-z]+(?=[^\S\n]|>)/, (0, combinator_1.union)([(0, combinator_1.match)(/^<(wbr)(?=[^\S\n]|>)/, (0, memoize_1.memoize)(([, tag]) => (0, combinator_1.surround)(`<${tag}`, (0, combinator_1.some)((0, combinator_1.union)([exports.attribute])), /^\s*>/, true, ([, bs = []], rest) => [[(0, dom_1.html)(tag, attributes('html', [], attrspec[tag], bs))], rest]), ([, tag]) => tags.indexOf(tag), [])), (0, combinator_1.match)(/^<(sup|sub|small|bdo|bdi)(?=[^\S\n]|>)/, (0, memoize_1.memoize)(([, tag]) => (0, combinator_1.surround)((0, combinator_1.surround)((0, source_1.str)(`<${tag}`), (0, combinator_1.some)(exports.attribute), (0, source_1.str)(/^\s*>/), true), (0, util_1.startLoose)((0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.open)(/^\n?/, (0, combinator_1.some)(inline_1.inline, (0, util_1.blankWith)('\n', `</${tag}>`)), true)])), `</${tag}>`), (0, source_1.str)(`</${tag}>`), false, ([as, bs, cs], rest) => [[elem(tag, as, bs, cs)], rest]), ([, tag]) => tags.indexOf(tag), [])), (0, combinator_1.match)(/^<([a-z]+)(?=[^\S\n]|>)/, (0, memoize_1.memoize)(([, tag]) => (0, combinator_1.surround)((0, combinator_1.surround)((0, source_1.str)(`<${tag}`), (0, combinator_1.some)(exports.attribute), (0, source_1.str)(/^\s*>/), true), (0, util_1.startLoose)((0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.open)(/^\n?/, (0, combinator_1.some)(inline_1.inline, (0, util_1.blankWith)('\n', `</${tag}>`)), true)])), `</${tag}>`), (0, source_1.str)(`</${tag}>`), false, ([as, bs, cs], rest) => [[elem(tag, as, bs, cs)], rest]), ([, tag]) => tag, new cache_1.Cache(10000)))])))));
6221
- exports.attribute = (0, combinator_1.union)([(0, source_1.str)(/^[^\S\n]+[a-z]+(?:-[a-z]+)*(?:="(?:\\[^\n]|[^\\\n"])*")?(?=[^\S\n]|>)/)]);
6219
+ global_1.Object.setPrototypeOf(attrspecs, null);
6220
+ global_1.Object.values(attrspecs).forEach(o => global_1.Object.setPrototypeOf(o, null));
6221
+ exports.html = (0, combinator_1.lazy)(() => (0, combinator_1.creator)((0, combinator_1.validate)('<', (0, combinator_1.validate)(/^<[a-z]+(?=[^\S\n]|>)/, (0, combinator_1.union)([(0, combinator_1.focus)('<wbr>', () => [[(0, dom_1.html)('wbr')], '']), (0, combinator_1.focus)( // https://html.spec.whatwg.org/multipage/syntax.html#void-elements
6222
+ /^<(?:area|base|br|col|embed|hr|img|input|link|meta|source|track|wbr)(?=[^\S\n]|>)/, source => [[source], '']), (0, combinator_1.match)(new RegExp(String.raw`^<(${TAGS.join('|')})(?=[^\S\n]|>)`), (0, memoize_1.memoize)(([, tag]) => (0, combinator_1.surround)((0, combinator_1.surround)((0, source_1.str)(`<${tag}`), (0, combinator_1.some)(exports.attribute), (0, source_1.str)(/^[^\S\n]*>/), true), (0, util_1.startLoose)((0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.open)(/^\n?/, (0, combinator_1.some)(inline_1.inline, (0, util_1.blankWith)('\n', `</${tag}>`)), true)])), `</${tag}>`), (0, source_1.str)(`</${tag}>`), false, ([as, bs, cs], rest) => [[elem(tag, as, bs, cs)], rest]), ([, tag]) => TAGS.indexOf(tag), [])), (0, combinator_1.match)(/^<([a-z]+)(?=[^\S\n]|>)/, (0, memoize_1.memoize)(([, tag]) => (0, combinator_1.surround)((0, combinator_1.surround)((0, source_1.str)(`<${tag}`), (0, combinator_1.some)(exports.attribute), (0, source_1.str)(/^[^\S\n]*>/), true), (0, util_1.startLoose)((0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.open)(/^\n?/, (0, combinator_1.some)(inline_1.inline, (0, util_1.blankWith)('\n', `</${tag}>`)), true)])), `</${tag}>`), (0, source_1.str)(`</${tag}>`), false, ([as, bs, cs], rest) => [[elem(tag, as, bs, cs)], rest]), ([, tag]) => tag, new cache_1.Cache(10000)))])))));
6223
+ exports.attribute = (0, combinator_1.union)([(0, source_1.str)(/^[^\S\n]+[a-z]+(?:-[a-z]+)*(?:="(?:\\[^\n]|[^\\\n"])*")?(?=[^\S\n]|>)/)]); // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
6224
+ // [...document.querySelectorAll('tbody > tr > td:first-child')].map(el => el.textContent.slice(1, -1))
6225
+
6226
+ const TAGS = global_1.Object.freeze(["html", "base", "head", "link", "meta", "style", "title", "body", "address", "article", "aside", "footer", "header", "h1", "h2", "h3", "h4", "h5", "h6", "main", "nav", "section", "blockquote", "dd", "div", "dl", "dt", "figcaption", "figure", "hr", "li", "menu", "ol", "p", "pre", "ul", "a", "abbr", "b", "bdi", "bdo", "br", "cite", "code", "data", "dfn", "em", "i", "kbd", "mark", "q", "rp", "rt", "ruby", "s", "samp", "small", "span", "strong", "sub", "sup", "time", "u", "var", "wbr", "area", "audio", "img", "map", "track", "video", "embed", "iframe", "object", "picture", "portal", "source", "svg", "math", "canvas", "noscript", "script", "del", "ins", "caption", "col", "colgroup", "table", "tbody", "td", "tfoot", "th", "thead", "tr", "button", "datalist", "fieldset", "form", "input", "label", "legend", "meter", "optgroup", "option", "output", "progress", "select", "textarea", "details", "dialog", "summary", "slot", "template", "acronym", "applet", "basefont", "bgsound", "big", "blink", "center", "content", "dir", "font", "frame", "frameset", "hgroup", "image", "keygen", "marquee", "menuitem", "nobr", "noembed", "noframes", "param", "plaintext", "rb", "rtc", "shadow", "spacer", "strike", "tt", "xmp"]);
6222
6227
 
6223
6228
  function elem(tag, as, bs, cs) {
6224
6229
  if (!tags.includes(tag)) return invalid('tag', `Invalid HTML tag <${tag}>`, as, bs, cs);
6225
- const attrs = attributes('html', [], attrspec[tag], as.slice(1, -1));
6230
+ const attrs = attributes('html', [], attrspecs[tag], as.slice(1, -1));
6226
6231
  return 'data-invalid-syntax' in attrs ? invalid('attribute', 'Invalid HTML attribute', as, bs, cs) : (0, dom_1.html)(tag, attrs, (0, dom_1.defrag)(bs));
6227
6232
  }
6228
6233
 
@@ -6246,7 +6251,7 @@ function attributes(syntax, classes, spec, params) {
6246
6251
  const name = param.split('=', 1)[0];
6247
6252
  const value = param !== name ? param.slice(name.length + 2, -1).replace(/\\(.?)/g, '$1') : global_1.undefined;
6248
6253
  invalid ||= !spec || name in attrs;
6249
- if (spec && !spec[name] && name in spec) continue;
6254
+ if (spec && name in spec && !spec[name]) continue;
6250
6255
  spec?.[name]?.includes(value) || value !== global_1.undefined && spec?.[name]?.length === 0 ? attrs[name] = value ?? '' : invalid ||= !!spec;
6251
6256
  (0, array_1.splice)(params, i--, 1);
6252
6257
  }
@@ -6997,7 +7002,7 @@ const multimap_1 = __webpack_require__(940);
6997
7002
  const array_1 = __webpack_require__(8112);
6998
7003
 
6999
7004
  function* figure(target, footnotes, opts = {}) {
7000
- const refs = new multimap_1.MultiMap((0, array_1.push)((0, array_1.push)((0, array_1.push)([], target.querySelectorAll('a.label:not(.disabled)[data-label]')), footnotes?.annotations?.querySelectorAll('a.label:not(.disabled)') ?? []), footnotes?.references.querySelectorAll('a.label:not(.disabled)') ?? []).map(el => [el.getAttribute('data-label'), el]));
7005
+ const refs = new multimap_1.MultiMap((0, array_1.push)((0, array_1.push)([], target.querySelectorAll('a.label:not(.disabled)[data-label]')), footnotes?.references.querySelectorAll('a.label:not(.disabled)') ?? []).map(el => [el.getAttribute('data-label'), el]));
7001
7006
  const labels = new global_1.Set();
7002
7007
  const numbers = new global_1.Map();
7003
7008
  let base = '0';
@@ -7191,9 +7196,9 @@ const multimap_1 = __webpack_require__(940);
7191
7196
 
7192
7197
  const array_1 = __webpack_require__(8112);
7193
7198
 
7194
- function* footnote(target, footnotes, opts = {}) {
7195
- yield* (0, exports.reference)(target, footnotes?.references, opts);
7196
- yield* (0, exports.annotation)(target, footnotes?.annotations, opts);
7199
+ function* footnote(target, footnotes, opts = {}, bottom = null) {
7200
+ yield* (0, exports.reference)(target, footnotes?.references, opts, bottom);
7201
+ yield* (0, exports.annotation)(target, footnotes?.annotations, opts, bottom);
7197
7202
  return;
7198
7203
  }
7199
7204
 
@@ -7204,8 +7209,7 @@ exports.reference = build('reference', (n, abbr) => `[${abbr || n}]`);
7204
7209
  function build(syntax, marker, splitter) {
7205
7210
  // Referenceを含むAnnotationの重複排除は両構文が互いに処理済みであることを必要とするため
7206
7211
  // 構文ごとに各1回の処理では不可能
7207
- return function* (target, footnote, opts = {}) {
7208
- //assert(syntax !== 'annotation' || !footnote);
7212
+ return function* (target, footnote, opts = {}, bottom = null) {
7209
7213
  const defs = new global_1.Map();
7210
7214
  const buffer = new multimap_1.MultiMap();
7211
7215
  const titles = new global_1.Map(); // Bug: Firefox
@@ -7312,7 +7316,7 @@ function build(syntax, marker, splitter) {
7312
7316
  if (defs.size > 0 || footnote) {
7313
7317
  yield* proc(defs, footnote ?? target.insertBefore((0, dom_1.html)('ol', {
7314
7318
  class: `${syntax}s`
7315
- }), splitters[0] ?? target.querySelector(':scope > :is(#annotations, #references)')));
7319
+ }), splitters[0] ?? bottom));
7316
7320
  }
7317
7321
 
7318
7322
  return;
@@ -8740,7 +8744,7 @@ function fix(h) {
8740
8744
  /***/ 3252:
8741
8745
  /***/ (function(module) {
8742
8746
 
8743
- /*! typed-dom v0.0.298 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
8747
+ /*! typed-dom v0.0.299 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
8744
8748
  (function webpackUniversalModuleDefinition(root, factory) {
8745
8749
  if(true)
8746
8750
  module.exports = factory();
@@ -9174,7 +9178,7 @@ exports.defrag = defrag;
9174
9178
  /***/ 6120:
9175
9179
  /***/ (function(module) {
9176
9180
 
9177
- /*! typed-dom v0.0.298 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
9181
+ /*! typed-dom v0.0.299 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
9178
9182
  (function webpackUniversalModuleDefinition(root, factory) {
9179
9183
  if(true)
9180
9184
  module.exports = factory();
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * @author falsandtru https://github.com/falsandtru/securemark
6
6
  */
7
7
 
8
- import { Collection } from 'spica/collection';
8
+ import { Dict } from 'spica/dict';
9
9
 
10
10
  export function parse(source: string, options?: ParserOptions): DocumentFragment;
11
11
  export function bind(target: DocumentFragment | HTMLElement | ShadowRoot, settings: ParserSettings): {
@@ -33,7 +33,6 @@ export interface ParserSettings {
33
33
  // For editing.
34
34
  readonly caches?: Partial<Caches>;
35
35
  readonly footnotes: {
36
- readonly annotations?: HTMLOListElement;
37
36
  readonly references: HTMLOListElement;
38
37
  };
39
38
  readonly chunk?: boolean;
@@ -48,23 +47,23 @@ export type Progress =
48
47
  | { type: 'cancel' };
49
48
 
50
49
  export interface RenderingOptions {
51
- readonly code?: (target: HTMLElement, cache?: Collection<string, HTMLElement>) => void;
52
- readonly math?: (target: HTMLElement, cache?: Collection<string, HTMLElement>) => void;
50
+ readonly code?: (target: HTMLElement, cache?: Dict<string, HTMLElement>) => void;
51
+ readonly math?: (target: HTMLElement, cache?: Dict<string, HTMLElement>) => void;
53
52
  readonly media?: {
54
53
  readonly twitter?: (source: HTMLImageElement, url: URL) => HTMLElement | undefined;
55
54
  readonly youtube?: (source: HTMLImageElement, url: URL) => HTMLElement | undefined;
56
55
  readonly pdf?: (source: HTMLImageElement, url: URL) => HTMLElement | undefined;
57
56
  readonly video?: (source: HTMLImageElement, url: URL) => HTMLVideoElement | undefined;
58
57
  readonly audio?: (source: HTMLImageElement, url: URL) => HTMLAudioElement | undefined;
59
- readonly image?: (source: HTMLImageElement, url: URL, cache?: Collection<string, HTMLElement>) => HTMLImageElement;
58
+ readonly image?: (source: HTMLImageElement, url: URL, cache?: Dict<string, HTMLElement>) => HTMLImageElement;
60
59
  };
61
60
  readonly caches?: Partial<Caches>;
62
61
  }
63
62
 
64
63
  export interface Caches {
65
- readonly code: Collection<string, HTMLElement>;
66
- readonly math: Collection<string, HTMLElement>;
67
- readonly media: Collection<string, HTMLElement>;
64
+ readonly code: Dict<string, HTMLElement>;
65
+ readonly math: Dict<string, HTMLElement>;
66
+ readonly media: Dict<string, HTMLElement>;
68
67
  }
69
68
 
70
69
  export interface Info {
package/markdown.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Parser, Ctx } from './src/combinator/data/parser';
2
- import { Collection } from 'spica/collection';
2
+ import { Dict } from 'spica/dict';
3
3
 
4
4
  declare abstract class Markdown<T> {
5
5
  private parser?: T;
@@ -29,9 +29,9 @@ export namespace MarkdownParser {
29
29
  };
30
30
  };
31
31
  readonly caches?: {
32
- readonly code?: Collection<string, HTMLElement>;
33
- readonly math?: Collection<string, HTMLElement>;
34
- readonly media?: Collection<string, HTMLElement>;
32
+ readonly code?: Dict<string, HTMLElement>;
33
+ readonly math?: Dict<string, HTMLElement>;
34
+ readonly media?: Dict<string, HTMLElement>;
35
35
  };
36
36
  }
37
37
  export interface SegmentParser extends
@@ -964,11 +964,12 @@ export namespace MarkdownParser {
964
964
  }
965
965
  }
966
966
  export interface HTMLParser extends
967
- // Allow: sup, sub, small, bdo, bdi
968
- // <small>abc</small>
967
+ // Allow: wbr, bdo, bdi
968
+ // <bdi>abc</bdi>
969
969
  Inline<'html'>,
970
970
  Parser<HTMLElement | string, Context, [
971
971
  HTMLParser.OpenTagParser,
972
+ SourceParser.StrParser,
972
973
  HTMLParser.TagParser,
973
974
  HTMLParser.TagParser,
974
975
  ]> {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.253.0",
3
+ "version": "0.254.0",
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",
@@ -34,29 +34,29 @@
34
34
  "@types/mocha": "9.1.1",
35
35
  "@types/power-assert": "1.5.8",
36
36
  "@types/prismjs": "1.26.0",
37
- "@typescript-eslint/parser": "^5.27.1",
37
+ "@typescript-eslint/parser": "^5.28.0",
38
38
  "babel-loader": "^8.2.5",
39
39
  "babel-plugin-unassert": "^3.2.0",
40
- "concurrently": "^7.2.1",
40
+ "concurrently": "^7.2.2",
41
41
  "eslint": "^8.17.0",
42
- "eslint-plugin-redos": "^4.4.0",
42
+ "eslint-plugin-redos": "^4.4.1",
43
43
  "eslint-webpack-plugin": "^3.1.1",
44
44
  "glob": "^8.0.3",
45
- "karma": "^6.3.20",
45
+ "karma": "^6.4.0",
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": "^13.1.2",
52
+ "npm-check-updates": "^14.0.1",
53
53
  "semver": "^7.3.7",
54
- "spica": "0.0.567",
54
+ "spica": "0.0.570",
55
55
  "ts-loader": "^9.3.0",
56
- "typed-dom": "^0.0.298",
56
+ "typed-dom": "^0.0.299",
57
57
  "typescript": "4.7.3",
58
58
  "webpack": "^5.73.0",
59
- "webpack-cli": "^4.9.2",
59
+ "webpack-cli": "^4.10.0",
60
60
  "webpack-merge": "^5.8.0"
61
61
  },
62
62
  "scripts": {
@@ -1,4 +1,4 @@
1
- import { ParserSettings, Progress } from '../../..';
1
+ import { Progress } from '../../..';
2
2
  import { bind } from './bind';
3
3
  import { frag, html } from 'typed-dom/dom';
4
4
 
@@ -27,7 +27,7 @@ describe('Unit: parser/api/bind', () => {
27
27
  return acc;
28
28
  }
29
29
 
30
- const cfgs: ParserSettings = { footnotes: { annotations: html('ol'), references: html('ol') } };
30
+ const cfgs = { footnotes: { annotations: html('ol'), references: html('ol') } };
31
31
 
32
32
  it('huge input', () => {
33
33
  const iter = bind(html('div'), { ...cfgs, id: '' }).parse(`${'\n'.repeat(10 * 1000 ** 2)}`);
@@ -122,7 +122,7 @@ export function bind(target: DocumentFragment | HTMLElement | ShadowRoot, settin
122
122
  : yield { type: 'break' };
123
123
  if (rev !== revision) return yield { type: 'cancel' };
124
124
  }
125
- for (const el of footnote(next(0)?.parentNode ?? target, settings.footnotes, context)) {
125
+ for (const el of footnote(next(0)?.parentNode ?? target, settings.footnotes, context, bottom)) {
126
126
  assert(rev === revision);
127
127
  el
128
128
  ? yield { type: 'footnote', value: el }
@@ -40,7 +40,6 @@ export function parse(source: string, opts: Options = {}, context?: MarkdownPars
40
40
  for (const _ of figure(node, opts.footnotes, context));
41
41
  for (const _ of footnote(node, opts.footnotes, context));
42
42
  assert(opts.id !== '' || !node.querySelector('[id], .index[href], .label[href], .annotation > a[href], .reference > a[href]'));
43
- assert(opts.id !== '' || !opts.footnotes?.annotations?.querySelector('[id], .index[href], .label[href]'));
44
43
  assert(opts.id !== '' || !opts.footnotes?.references.querySelector('[id], .index[href], .label[href]'));
45
44
  return node;
46
45
  }
@@ -15,13 +15,13 @@ describe('Unit: parser/block/extension/message', () => {
15
15
  });
16
16
 
17
17
  it('valid', () => {
18
- assert.deepStrictEqual(inspect(parser('~~~message/note\n~~~')), [['<div class="message" data-type="note"><h6>Note</h6></div>'], '']);
19
- assert.deepStrictEqual(inspect(parser('~~~message/note\n\n~~~')), [['<div class="message" data-type="note"><h6>Note</h6></div>'], '']);
20
- assert.deepStrictEqual(inspect(parser('~~~message/note\na\n~~~')), [['<div class="message" data-type="note"><h6>Note</h6><p>a</p></div>'], '']);
21
- assert.deepStrictEqual(inspect(parser('~~~message/note\na\n\n- \n~~~')), [['<div class="message" data-type="note"><h6>Note</h6><p>a</p><ul><li></li></ul></div>'], '']);
22
- assert.deepStrictEqual(inspect(parser('~~~message/note\n# a\n~~~')), [['<div class="message" data-type="note"><h6>Note</h6><p># a</p></div>'], '']);
23
- assert.deepStrictEqual(inspect(parser('~~~message/caution\n~~~')), [['<div class="message" data-type="caution"><h6>Caution!</h6></div>'], '']);
24
- assert.deepStrictEqual(inspect(parser('~~~message/warning\n~~~')), [['<div class="message" data-type="warning"><h6>WARNING!!</h6></div>'], '']);
18
+ assert.deepStrictEqual(inspect(parser('~~~message/note\n~~~')), [['<section class="message" data-type="note"><h1>Note</h1></section>'], '']);
19
+ assert.deepStrictEqual(inspect(parser('~~~message/note\n\n~~~')), [['<section class="message" data-type="note"><h1>Note</h1></section>'], '']);
20
+ assert.deepStrictEqual(inspect(parser('~~~message/note\na\n~~~')), [['<section class="message" data-type="note"><h1>Note</h1><p>a</p></section>'], '']);
21
+ assert.deepStrictEqual(inspect(parser('~~~message/note\na\n\n- \n~~~')), [['<section class="message" data-type="note"><h1>Note</h1><p>a</p><ul><li></li></ul></section>'], '']);
22
+ assert.deepStrictEqual(inspect(parser('~~~message/note\n# a\n~~~')), [['<section class="message" data-type="note"><h1>Note</h1><p># a</p></section>'], '']);
23
+ assert.deepStrictEqual(inspect(parser('~~~message/caution\n~~~')), [['<section class="message" data-type="caution"><h1>Caution!</h1></section>'], '']);
24
+ assert.deepStrictEqual(inspect(parser('~~~message/warning\n~~~')), [['<section class="message" data-type="warning"><h1>WARNING!!</h1></section>'], '']);
25
25
  });
26
26
 
27
27
  });
@@ -46,8 +46,8 @@ export const message: MessageParser = block(validate('~~~', fmap(
46
46
  }, `${opener}${body}${closer}`)];
47
47
  }
48
48
  return [
49
- html('div', { class: `message`, 'data-type': type }, unshift(
50
- [html('h6', title(type))],
49
+ html('section', { class: `message`, 'data-type': type }, unshift(
50
+ [html('h1', title(type))],
51
51
  [...segment(body)].reduce((acc, seg) => push(acc, eval(content(seg, context), [])), []))),
52
52
  ];
53
53
  })));
@@ -220,7 +220,8 @@ function format(rows: Tree<RowParser>[]): HTMLTableSectionElement[] {
220
220
  let hasDataCell = false;
221
221
  let lHeadCellIdx: bigint;
222
222
  let rHeadCellIdx: bigint;
223
- for (let j = 0, jn = 0n; j < cells.length; jn = BigInt(++j)) {
223
+ for (let j = 0; j < cells.length; ++j) {
224
+ const jn = BigInt(j);
224
225
  const isVirtual = !!ranges[i]?.[j];
225
226
  const cell = isVirtual
226
227
  ? splice(cells, j, 0, undefined) && ranges[i][j]
@@ -248,8 +249,8 @@ function format(rows: Tree<RowParser>[]): HTMLTableSectionElement[] {
248
249
  assert(colSpan > 0);
249
250
  if (colSpan > 1) {
250
251
  splice(cells, j + 1, 0, ...Array(colSpan - 1));
251
- heads |= BigInt(+`0b${`${heads & 1n << jn && 1}`.repeat(colSpan)}`) << jn;
252
- highlights |= BigInt(+`0b${`${highlights & 1n << jn && 1}`.repeat(colSpan)}`) << jn;
252
+ heads |= heads & 1n << jn && ~(~0n << BigInt(colSpan)) << jn;
253
+ highlights |= highlights & 1n << jn && ~(~0n << BigInt(colSpan)) << jn;
253
254
  j += colSpan - 1;
254
255
  }
255
256
  if (target === thead) {
@@ -311,7 +312,7 @@ function format(rows: Tree<RowParser>[]): HTMLTableSectionElement[] {
311
312
  'v c',
312
313
  'v h',
313
314
  'v h c',
314
- ][+!!(highlights & m) + +!!(lHighlight | rHighlight) * 2 + +!!(tHighlights & m) * 4]));
315
+ ][+!!(highlights & m) | +!!(lHighlight | rHighlight) << 1 | +!!(tHighlights & m) << 2]));
315
316
  }
316
317
  continue;
317
318
  case tfoot:
@@ -46,7 +46,7 @@ describe('Unit: parser/inline/emphasis', () => {
46
46
  assert.deepStrictEqual(inspect(parser('*a**b**c*')), [['<em>a<strong>b</strong>c</em>'], '']);
47
47
  assert.deepStrictEqual(inspect(parser('*a**b**c*d')), [['<em>a<strong>b</strong>c</em>'], 'd']);
48
48
  assert.deepStrictEqual(inspect(parser('*`a`*')), [['<em><code data-src="`a`">a</code></em>'], '']);
49
- assert.deepStrictEqual(inspect(parser('*<small>*')), [['<em>&lt;small&gt;</em>'], '']);
49
+ assert.deepStrictEqual(inspect(parser('*<bdi>*')), [['<em>&lt;bdi&gt;</em>'], '']);
50
50
  assert.deepStrictEqual(inspect(parser('*(*a*)*')), [['<em><span class="paren">(<em>a</em>)</span></em>'], '']);
51
51
  assert.deepStrictEqual(inspect(parser('*(**a**)*')), [['<em><span class="paren">(<strong>a</strong>)</span></em>'], '']);
52
52
  });
@@ -11,12 +11,11 @@ describe('Unit: parser/inline/html', () => {
11
11
  assert.deepStrictEqual(inspect(parser('<script>alert()<script>')), undefined);
12
12
  assert.deepStrictEqual(inspect(parser('<script>alert()</script>')), [['<span class="invalid">&lt;script&gt;alert<span class="paren">()</span>&lt;/script&gt;</span>'], '']);
13
13
  assert.deepStrictEqual(inspect(parser('<script src="\\""></script>')), undefined);
14
- assert.deepStrictEqual(inspect(parser('<small onclick="alert()">')), undefined);
15
- assert.deepStrictEqual(inspect(parser('<small onclick="alert()"></small>')), undefined);
16
- assert.deepStrictEqual(inspect(parser('<small onclick="alert()">a</small>')), [['<span class="invalid">&lt;small onclick="alert()"&gt;a&lt;/small&gt;</span>'], '']);
17
- assert.deepStrictEqual(inspect(parser('<small><small onclick="alert()">a</small></small>')), [['<small><span class="invalid">&lt;small onclick="alert()"&gt;a&lt;/small&gt;</span></small>'], '']);
14
+ assert.deepStrictEqual(inspect(parser('<bdi onclick="alert()">')), undefined);
15
+ assert.deepStrictEqual(inspect(parser('<bdi onclick="alert()"></bdi>')), undefined);
16
+ assert.deepStrictEqual(inspect(parser('<bdi onclick="alert()">a</bdi>')), [['<span class="invalid">&lt;bdi onclick="alert()"&gt;a&lt;/bdi&gt;</span>'], '']);
17
+ assert.deepStrictEqual(inspect(parser('<bdi><bdi onclick="alert()">a</bdi></bdi>')), [['<bdi><span class="invalid">&lt;bdi onclick="alert()"&gt;a&lt;/bdi&gt;</span></bdi>'], '']);
18
18
  assert.deepStrictEqual(inspect(parser('<bdo dir="rtl\\"><">a</bdo>')), [['<span class="invalid">&lt;bdo dir="rtl\\"&gt;&lt;"&gt;a&lt;/bdo&gt;</span>'], '']);
19
- assert.deepStrictEqual(inspect(parser('<wbr onclick="alert()">')), [['<wbr class="invalid">'], '']);
20
19
  });
21
20
 
22
21
  it('invalid', () => {
@@ -26,78 +25,80 @@ describe('Unit: parser/inline/html', () => {
26
25
  assert.deepStrictEqual(inspect(parser('<a,b>')), undefined);
27
26
  assert.deepStrictEqual(inspect(parser('<a, b>')), undefined);
28
27
  assert.deepStrictEqual(inspect(parser('<T>')), undefined);
29
- assert.deepStrictEqual(inspect(parser('<small>z')), undefined);
30
- assert.deepStrictEqual(inspect(parser('<small></small>')), undefined);
31
- assert.deepStrictEqual(inspect(parser('<small> </small>')), undefined);
32
- assert.deepStrictEqual(inspect(parser('<small>\\ </small>')), undefined);
33
- assert.deepStrictEqual(inspect(parser('<small>&Tab;</small>')), undefined);
34
- assert.deepStrictEqual(inspect(parser('<small><wbr></small>')), undefined);
35
- assert.deepStrictEqual(inspect(parser('<small>\n</small>')), undefined);
36
- assert.deepStrictEqual(inspect(parser('<small>\na</small>')), undefined);
37
- assert.deepStrictEqual(inspect(parser('<small>\\\na</small>')), undefined);
38
- assert.deepStrictEqual(inspect(parser('<small>a')), undefined);
39
- assert.deepStrictEqual(inspect(parser('<small>a</BDO>')), undefined);
40
- assert.deepStrictEqual(inspect(parser('<SMALL>a</SMALL>')), undefined);
41
- assert.deepStrictEqual(inspect(parser('<SMALL>a</bdo>')), undefined);
42
- assert.deepStrictEqual(inspect(parser('</small>')), undefined);
43
- assert.deepStrictEqual(inspect(parser('<small/>')), undefined);
28
+ assert.deepStrictEqual(inspect(parser('<bdi>z')), undefined);
29
+ assert.deepStrictEqual(inspect(parser('<bdi></bdi>')), undefined);
30
+ assert.deepStrictEqual(inspect(parser('<bdi> </bdi>')), undefined);
31
+ assert.deepStrictEqual(inspect(parser('<bdi>\\ </bdi>')), undefined);
32
+ assert.deepStrictEqual(inspect(parser('<bdi>&Tab;</bdi>')), undefined);
33
+ assert.deepStrictEqual(inspect(parser('<bdi><wbr></bdi>')), undefined);
34
+ assert.deepStrictEqual(inspect(parser('<bdi>\n</bdi>')), undefined);
35
+ assert.deepStrictEqual(inspect(parser('<bdi>\na</bdi>')), undefined);
36
+ assert.deepStrictEqual(inspect(parser('<bdi>\\\na</bdi>')), undefined);
37
+ assert.deepStrictEqual(inspect(parser('<bdi>a')), undefined);
38
+ assert.deepStrictEqual(inspect(parser('<bdi>a</BDO>')), undefined);
39
+ assert.deepStrictEqual(inspect(parser('<BDI>a</BDI>')), undefined);
40
+ assert.deepStrictEqual(inspect(parser('<BDI>a</bdo>')), undefined);
41
+ assert.deepStrictEqual(inspect(parser('</bdi>')), undefined);
42
+ assert.deepStrictEqual(inspect(parser('<bdi/>')), undefined);
44
43
  assert.deepStrictEqual(inspect(parser('<b><b><b>a</b></b></b>')), [['<span class="invalid">&lt;b&gt;<span class="invalid">&lt;b&gt;<span class="invalid">&lt;b&gt;a&lt;/b&gt;</span>&lt;/b&gt;</span>&lt;/b&gt;</span>'], '']);
45
- assert.deepStrictEqual(inspect(parser('<small><small><small>a</small></small></small>')), [['<small><small><small>a</small></small></small>'], '']);
44
+ assert.deepStrictEqual(inspect(parser('<bdi><bdi><bdi>a</bdi></bdi></bdi>')), [['<bdi><bdi><bdi>a</bdi></bdi></bdi>'], '']);
46
45
  assert.deepStrictEqual(inspect(parser('<x a="*b*"')), undefined);
47
46
  assert.deepStrictEqual(inspect(parser('<x a="*b*">')), undefined);
48
47
  assert.deepStrictEqual(inspect(parser('<x a="*b*">c')), undefined);
49
- assert.deepStrictEqual(inspect(parser('<small a="*b*"')), undefined);
50
- assert.deepStrictEqual(inspect(parser('<small a="*b*">')), undefined);
51
- assert.deepStrictEqual(inspect(parser('<small a="*b*">c')), undefined);
52
- assert.deepStrictEqual(inspect(parser('<small a b="*" *c*')), undefined);
53
- assert.deepStrictEqual(inspect(parser('<small a b="*" *c*>')), undefined);
54
- assert.deepStrictEqual(inspect(parser('<small a b="*" *c*>d</small>')), undefined);
55
- assert.deepStrictEqual(inspect(parser('<small a b="*" *>*c*')), undefined);
56
- assert.deepStrictEqual(inspect(parser('<small a b="*" *>*c*</small>')), undefined);
57
- assert.deepStrictEqual(inspect(parser(' <small>a</small>')), undefined);
48
+ assert.deepStrictEqual(inspect(parser('<bdi a="*b*"')), undefined);
49
+ assert.deepStrictEqual(inspect(parser('<bdi a="*b*">')), undefined);
50
+ assert.deepStrictEqual(inspect(parser('<bdi a="*b*">c')), undefined);
51
+ assert.deepStrictEqual(inspect(parser('<bdi a b="*" *c*')), undefined);
52
+ assert.deepStrictEqual(inspect(parser('<bdi a b="*" *c*>')), undefined);
53
+ assert.deepStrictEqual(inspect(parser('<bdi a b="*" *c*>d</bdi>')), undefined);
54
+ assert.deepStrictEqual(inspect(parser('<bdi a b="*" *>*c*')), undefined);
55
+ assert.deepStrictEqual(inspect(parser('<bdi a b="*" *>*c*</bdi>')), undefined);
56
+ assert.deepStrictEqual(inspect(parser(' <bdi>a</bdi>')), undefined);
58
57
  });
59
58
 
60
59
  it('basic', () => {
61
- assert.deepStrictEqual(inspect(parser('<small> a</small>')), [['<small> a</small>'], '']);
62
- assert.deepStrictEqual(inspect(parser('<small> a </small>')), [['<small> a </small>'], '']);
63
- assert.deepStrictEqual(inspect(parser('<small> a </small>')), [['<small> a </small>'], '']);
64
- assert.deepStrictEqual(inspect(parser('<small>\\ a</small>')), [['<small> a</small>'], '']);
65
- assert.deepStrictEqual(inspect(parser('<small><wbr>a</small>')), [['<small><wbr>a</small>'], '']);
66
- assert.deepStrictEqual(inspect(parser('<small>a</small>')), [['<small>a</small>'], '']);
67
- assert.deepStrictEqual(inspect(parser('<small>a</small>a')), [['<small>a</small>'], 'a']);
68
- assert.deepStrictEqual(inspect(parser('<small>a </small>')), [['<small>a </small>'], '']);
69
- assert.deepStrictEqual(inspect(parser('<small>a \n </small>')), [['<small>a </small>'], '']);
70
- assert.deepStrictEqual(inspect(parser('<small>a\n</small>')), [['<small>a</small>'], '']);
71
- assert.deepStrictEqual(inspect(parser('<small>a\n </small>')), [['<small>a </small>'], '']);
72
- assert.deepStrictEqual(inspect(parser('<small>a\n<wbr></small>')), [['<small>a<wbr></small>'], '']);
73
- assert.deepStrictEqual(inspect(parser('<small>a\nb</small>')), [['<small>a<br>b</small>'], '']);
60
+ assert.deepStrictEqual(inspect(parser('<bdi> a</bdi>')), [['<bdi> a</bdi>'], '']);
61
+ assert.deepStrictEqual(inspect(parser('<bdi> a </bdi>')), [['<bdi> a </bdi>'], '']);
62
+ assert.deepStrictEqual(inspect(parser('<bdi> a </bdi>')), [['<bdi> a </bdi>'], '']);
63
+ assert.deepStrictEqual(inspect(parser('<bdi>\\ a</bdi>')), [['<bdi> a</bdi>'], '']);
64
+ assert.deepStrictEqual(inspect(parser('<bdi><wbr>a</bdi>')), [['<bdi><wbr>a</bdi>'], '']);
65
+ assert.deepStrictEqual(inspect(parser('<bdi>a</bdi>')), [['<bdi>a</bdi>'], '']);
66
+ assert.deepStrictEqual(inspect(parser('<bdi>a</bdi>a')), [['<bdi>a</bdi>'], 'a']);
67
+ assert.deepStrictEqual(inspect(parser('<bdi>a </bdi>')), [['<bdi>a </bdi>'], '']);
68
+ assert.deepStrictEqual(inspect(parser('<bdi>a \n </bdi>')), [['<bdi>a </bdi>'], '']);
69
+ assert.deepStrictEqual(inspect(parser('<bdi>a\n</bdi>')), [['<bdi>a</bdi>'], '']);
70
+ assert.deepStrictEqual(inspect(parser('<bdi>a\n </bdi>')), [['<bdi>a </bdi>'], '']);
71
+ assert.deepStrictEqual(inspect(parser('<bdi>a\n<wbr></bdi>')), [['<bdi>a<wbr></bdi>'], '']);
72
+ assert.deepStrictEqual(inspect(parser('<bdi>a\nb</bdi>')), [['<bdi>a<br>b</bdi>'], '']);
74
73
  assert.deepStrictEqual(inspect(parser('<wbr>a')), [['<wbr>'], 'a']);
75
74
  });
76
75
 
77
76
  it('nest', () => {
78
- assert.deepStrictEqual(inspect(parser('<small><small>a</small></small>')), [['<small><small>a</small></small>'], '']);
79
- assert.deepStrictEqual(inspect(parser('<small>a<small>b</small>c</small>')), [['<small>a<small>b</small>c</small>'], '']);
80
- assert.deepStrictEqual(inspect(parser('<small>`a`</small>')), [['<small><code data-src="`a`">a</code></small>'], '']);
77
+ assert.deepStrictEqual(inspect(parser('<bdi><bdi>a</bdi></bdi>')), [['<bdi><bdi>a</bdi></bdi>'], '']);
78
+ assert.deepStrictEqual(inspect(parser('<bdi>a<bdi>b</bdi>c</bdi>')), [['<bdi>a<bdi>b</bdi>c</bdi>'], '']);
79
+ assert.deepStrictEqual(inspect(parser('<bdi>`a`</bdi>')), [['<bdi><code data-src="`a`">a</code></bdi>'], '']);
81
80
  });
82
81
 
83
82
  it('escape', () => {
84
83
  assert.deepStrictEqual(inspect(parser('<a>')), undefined);
85
- assert.deepStrictEqual(inspect(parser('<small><a>a</a></small>')), [['<small><span class="invalid">&lt;a&gt;a&lt;/a&gt;</span></small>'], '']);
86
- assert.deepStrictEqual(inspect(parser('<small>a<a>b</a>c</small>')), [['<small>a<span class="invalid">&lt;a&gt;b&lt;/a&gt;</span>c</small>'], '']);
87
- assert.deepStrictEqual(inspect(parser('<img>')), undefined);
88
- assert.deepStrictEqual(inspect(parser('<small><img></small>')), [['<small>&lt;img&gt;</small>'], '']);
89
- assert.deepStrictEqual(inspect(parser('<img />')), undefined);
90
- assert.deepStrictEqual(inspect(parser('<small><img /></small>')), [['<small>&lt;img /&gt;</small>'], '']);
84
+ assert.deepStrictEqual(inspect(parser('<bdi><a>a</a></bdi>')), [['<bdi><span class="invalid">&lt;a&gt;a&lt;/a&gt;</span></bdi>'], '']);
85
+ assert.deepStrictEqual(inspect(parser('<bdi>a<a>b</a>c</bdi>')), [['<bdi>a<span class="invalid">&lt;a&gt;b&lt;/a&gt;</span>c</bdi>'], '']);
86
+ assert.deepStrictEqual(inspect(parser('<img>')), [['<img'], '>']);
87
+ assert.deepStrictEqual(inspect(parser('<bdi><img></bdi>')), [['<bdi>&lt;img&gt;</bdi>'], '']);
88
+ assert.deepStrictEqual(inspect(parser('<img />')), [['<img'], ' />']);
89
+ assert.deepStrictEqual(inspect(parser('<bdi><img /></bdi>')), [['<bdi>&lt;img /&gt;</bdi>'], '']);
91
90
  });
92
91
 
93
92
  it('attribute', () => {
94
- assert.deepStrictEqual(inspect(parser('<small >a</small>')), [['<small>a</small>'], '']);
95
- assert.deepStrictEqual(inspect(parser('<small >a</small>')), [['<small>a</small>'], '']);
96
- assert.deepStrictEqual(inspect(parser('<small __proto__>a</small>')), undefined);
97
- assert.deepStrictEqual(inspect(parser('<small constructor>a</small>')), [['<span class="invalid">&lt;small constructor&gt;a&lt;/small&gt;</span>'], '']);
98
- assert.deepStrictEqual(inspect(parser('<small toString>a</small>')), undefined);
99
- assert.deepStrictEqual(inspect(parser('<small X>a</small>')), undefined);
100
- assert.deepStrictEqual(inspect(parser('<small x>a</small>')), [['<span class="invalid">&lt;small x&gt;a&lt;/small&gt;</span>'], '']);
93
+ assert.deepStrictEqual(inspect(parser('<bdi\n>a</bdi>')), undefined);
94
+ assert.deepStrictEqual(inspect(parser('<bdi >a</bdi>')), [['<bdi>a</bdi>'], '']);
95
+ assert.deepStrictEqual(inspect(parser('<bdi \n>a</bdi>')), undefined);
96
+ assert.deepStrictEqual(inspect(parser('<bdi >a</bdi>')), [['<bdi>a</bdi>'], '']);
97
+ assert.deepStrictEqual(inspect(parser('<bdi __proto__>a</bdi>')), undefined);
98
+ assert.deepStrictEqual(inspect(parser('<bdi constructor>a</bdi>')), [['<span class="invalid">&lt;bdi constructor&gt;a&lt;/bdi&gt;</span>'], '']);
99
+ assert.deepStrictEqual(inspect(parser('<bdi toString>a</bdi>')), undefined);
100
+ assert.deepStrictEqual(inspect(parser('<bdi X>a</bdi>')), undefined);
101
+ assert.deepStrictEqual(inspect(parser('<bdi x>a</bdi>')), [['<span class="invalid">&lt;bdi x&gt;a&lt;/bdi&gt;</span>'], '']);
101
102
  assert.deepStrictEqual(inspect(parser('<bdo>a</bdo>')), [['<span class="invalid">&lt;bdo&gt;a&lt;/bdo&gt;</span>'], '']);
102
103
  assert.deepStrictEqual(inspect(parser('<bdo >a</bdo>')), [['<span class="invalid">&lt;bdo &gt;a&lt;/bdo&gt;</span>'], '']);
103
104
  assert.deepStrictEqual(inspect(parser('<bdo __proto__>a</bdo>')), undefined);
@@ -116,9 +117,11 @@ describe('Unit: parser/inline/html', () => {
116
117
  assert.deepStrictEqual(inspect(parser('<bdo dir="rtl" >a</bdo>')), [['<bdo dir="rtl">a</bdo>'], '']);
117
118
  assert.deepStrictEqual(inspect(parser('<bdo dir="rtl" >a</bdo>')), [['<bdo dir="rtl">a</bdo>'], '']);
118
119
  assert.deepStrictEqual(inspect(parser('<bdo dir="rtl">a</bdo>')), [['<bdo dir="rtl">a</bdo>'], '']);
119
- assert.deepStrictEqual(inspect(parser('<wbr constructor>')), [['<wbr class="invalid">'], '']);
120
- assert.deepStrictEqual(inspect(parser('<wbr X>')), undefined);
121
- assert.deepStrictEqual(inspect(parser('<wbr x>')), [['<wbr class="invalid">'], '']);
120
+ assert.deepStrictEqual(inspect(parser('<wbr\n>')), undefined);
121
+ assert.deepStrictEqual(inspect(parser('<wbr >')), [['<wbr'], ' >']);
122
+ assert.deepStrictEqual(inspect(parser('<wbr constructor>')), [['<wbr'], ' constructor>']);
123
+ assert.deepStrictEqual(inspect(parser('<wbr X>')), [['<wbr'], ' X>']);
124
+ assert.deepStrictEqual(inspect(parser('<wbr x>')), [['<wbr'], ' x>']);
122
125
  });
123
126
 
124
127
  });
@@ -1,6 +1,6 @@
1
1
  import { undefined, Object } from 'spica/global';
2
2
  import { HTMLParser } from '../inline';
3
- import { union, some, validate, creator, surround, open, match, lazy } from '../../combinator';
3
+ import { union, some, validate, focus, creator, surround, open, match, lazy } from '../../combinator';
4
4
  import { inline } from '../inline';
5
5
  import { str } from '../source';
6
6
  import { startLoose, blankWith } from '../util';
@@ -9,44 +9,42 @@ import { memoize } from 'spica/memoize';
9
9
  import { Cache } from 'spica/cache';
10
10
  import { unshift, push, splice } from 'spica/array';
11
11
 
12
- const tags = Object.freeze(['wbr', 'sup', 'sub', 'small', 'bdo', 'bdi']);
13
- const attrspec = {
12
+ const tags = Object.freeze(['bdo', 'bdi']);
13
+ const attrspecs = {
14
14
  bdo: {
15
- dir: Object.freeze(['ltr', 'rtl'] as const),
15
+ dir: Object.freeze(['ltr', 'rtl']),
16
16
  },
17
17
  } as const;
18
- Object.setPrototypeOf(attrspec, null);
19
- Object.values(attrspec).forEach(o => Object.setPrototypeOf(o, null));
18
+ Object.setPrototypeOf(attrspecs, null);
19
+ Object.values(attrspecs).forEach(o => Object.setPrototypeOf(o, null));
20
20
 
21
21
  export const html: HTMLParser = lazy(() => creator(validate('<', validate(/^<[a-z]+(?=[^\S\n]|>)/, union([
22
+ focus(
23
+ '<wbr>',
24
+ () => [[h('wbr')], '']),
25
+ focus(
26
+ // https://html.spec.whatwg.org/multipage/syntax.html#void-elements
27
+ /^<(?:area|base|br|col|embed|hr|img|input|link|meta|source|track|wbr)(?=[^\S\n]|>)/,
28
+ source => [[source], '']),
22
29
  match(
23
- /^<(wbr)(?=[^\S\n]|>)/,
24
- memoize(
25
- ([, tag]) =>
26
- surround(
27
- `<${tag}`, some(union([attribute])), /^\s*>/, true,
28
- ([, bs = []], rest) =>
29
- [[h(tag as 'span', attributes('html', [], attrspec[tag], bs))], rest]),
30
- ([, tag]) => tags.indexOf(tag), [])),
31
- match(
32
- /^<(sup|sub|small|bdo|bdi)(?=[^\S\n]|>)/,
30
+ new RegExp(String.raw`^<(${TAGS.join('|')})(?=[^\S\n]|>)`),
33
31
  memoize(
34
32
  ([, tag]) =>
35
33
  surround<HTMLParser.TagParser, string>(surround(
36
- str(`<${tag}`), some(attribute), str(/^\s*>/), true),
34
+ str(`<${tag}`), some(attribute), str(/^[^\S\n]*>/), true),
37
35
  startLoose(some(union([
38
36
  open(/^\n?/, some(inline, blankWith('\n', `</${tag}>`)), true),
39
37
  ])), `</${tag}>`),
40
38
  str(`</${tag}>`), false,
41
39
  ([as, bs, cs], rest) =>
42
40
  [[elem(tag, as, bs, cs)], rest]),
43
- ([, tag]) => tags.indexOf(tag), [])),
41
+ ([, tag]) => TAGS.indexOf(tag), [])),
44
42
  match(
45
43
  /^<([a-z]+)(?=[^\S\n]|>)/,
46
44
  memoize(
47
45
  ([, tag]) =>
48
46
  surround<HTMLParser.TagParser, string>(surround(
49
- str(`<${tag}`), some(attribute), str(/^\s*>/), true),
47
+ str(`<${tag}`), some(attribute), str(/^[^\S\n]*>/), true),
50
48
  startLoose(some(union([
51
49
  open(/^\n?/, some(inline, blankWith('\n', `</${tag}>`)), true),
52
50
  ])), `</${tag}>`),
@@ -61,16 +59,159 @@ export const attribute: HTMLParser.TagParser.AttributeParser = union([
61
59
  str(/^[^\S\n]+[a-z]+(?:-[a-z]+)*(?:="(?:\\[^\n]|[^\\\n"])*")?(?=[^\S\n]|>)/),
62
60
  ]);
63
61
 
62
+ // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
63
+ // [...document.querySelectorAll('tbody > tr > td:first-child')].map(el => el.textContent.slice(1, -1))
64
+ const TAGS = Object.freeze([
65
+ "html",
66
+ "base",
67
+ "head",
68
+ "link",
69
+ "meta",
70
+ "style",
71
+ "title",
72
+ "body",
73
+ "address",
74
+ "article",
75
+ "aside",
76
+ "footer",
77
+ "header",
78
+ "h1", "h2", "h3", "h4", "h5", "h6",
79
+ "main",
80
+ "nav",
81
+ "section",
82
+ "blockquote",
83
+ "dd",
84
+ "div",
85
+ "dl",
86
+ "dt",
87
+ "figcaption",
88
+ "figure",
89
+ "hr",
90
+ "li",
91
+ "menu",
92
+ "ol",
93
+ "p",
94
+ "pre",
95
+ "ul",
96
+ "a",
97
+ "abbr",
98
+ "b",
99
+ "bdi",
100
+ "bdo",
101
+ "br",
102
+ "cite",
103
+ "code",
104
+ "data",
105
+ "dfn",
106
+ "em",
107
+ "i",
108
+ "kbd",
109
+ "mark",
110
+ "q",
111
+ "rp",
112
+ "rt",
113
+ "ruby",
114
+ "s",
115
+ "samp",
116
+ "small",
117
+ "span",
118
+ "strong",
119
+ "sub",
120
+ "sup",
121
+ "time",
122
+ "u",
123
+ "var",
124
+ "wbr",
125
+ "area",
126
+ "audio",
127
+ "img",
128
+ "map",
129
+ "track",
130
+ "video",
131
+ "embed",
132
+ "iframe",
133
+ "object",
134
+ "picture",
135
+ "portal",
136
+ "source",
137
+ "svg",
138
+ "math",
139
+ "canvas",
140
+ "noscript",
141
+ "script",
142
+ "del",
143
+ "ins",
144
+ "caption",
145
+ "col",
146
+ "colgroup",
147
+ "table",
148
+ "tbody",
149
+ "td",
150
+ "tfoot",
151
+ "th",
152
+ "thead",
153
+ "tr",
154
+ "button",
155
+ "datalist",
156
+ "fieldset",
157
+ "form",
158
+ "input",
159
+ "label",
160
+ "legend",
161
+ "meter",
162
+ "optgroup",
163
+ "option",
164
+ "output",
165
+ "progress",
166
+ "select",
167
+ "textarea",
168
+ "details",
169
+ "dialog",
170
+ "summary",
171
+ "slot",
172
+ "template",
173
+ "acronym",
174
+ "applet",
175
+ "basefont",
176
+ "bgsound",
177
+ "big",
178
+ "blink",
179
+ "center",
180
+ "content",
181
+ "dir",
182
+ "font",
183
+ "frame",
184
+ "frameset",
185
+ "hgroup",
186
+ "image",
187
+ "keygen",
188
+ "marquee",
189
+ "menuitem",
190
+ "nobr",
191
+ "noembed",
192
+ "noframes",
193
+ "param",
194
+ "plaintext",
195
+ "rb",
196
+ "rtc",
197
+ "shadow",
198
+ "spacer",
199
+ "strike",
200
+ "tt",
201
+ "xmp",
202
+ ]);
203
+
64
204
  function elem(tag: string, as: string[], bs: (HTMLElement | string)[], cs: string[]): HTMLElement {
65
205
  assert(as.length > 0);
66
206
  assert(as[0][0] === '<' && as[as.length - 1].slice(-1) === '>');
67
207
  assert(cs.length === 1);
68
208
  if (!tags.includes(tag)) return invalid('tag', `Invalid HTML tag <${tag}>`, as, bs, cs);
69
- const attrs = attributes('html', [], attrspec[tag], as.slice(1, -1));
209
+ const attrs = attributes('html', [], attrspecs[tag], as.slice(1, -1));
70
210
  return 'data-invalid-syntax' in attrs
71
211
  ? invalid('attribute', 'Invalid HTML attribute', as, bs, cs)
72
212
  : h(tag as 'span', attrs, defrag(bs));
73
213
  }
214
+
74
215
  function invalid(type: string, message: string, as: (HTMLElement | string)[], bs: (HTMLElement | string)[], cs: (HTMLElement | string)[]): HTMLElement {
75
216
  return h('span', {
76
217
  class: 'invalid',
@@ -103,7 +244,7 @@ export function attributes(
103
244
  ? param.slice(name.length + 2, -1).replace(/\\(.?)/g, '$1')
104
245
  : undefined;
105
246
  invalid ||= !spec || name in attrs;
106
- if (spec && !spec[name] && name in spec) continue;
247
+ if (spec && name in spec && !spec[name]) continue;
107
248
  spec?.[name]?.includes(value) || value !== undefined && spec?.[name]?.length === 0
108
249
  ? attrs[name] = value ?? ''
109
250
  : invalid ||= !!spec;
@@ -43,7 +43,7 @@ describe('Unit: parser/inline/strong', () => {
43
43
  assert.deepStrictEqual(inspect(parser('**a*b*c**')), [['<strong>a<em>b</em>c</strong>'], '']);
44
44
  assert.deepStrictEqual(inspect(parser('**a*b*c**d')), [['<strong>a<em>b</em>c</strong>'], 'd']);
45
45
  assert.deepStrictEqual(inspect(parser('**`a`**')), [['<strong><code data-src="`a`">a</code></strong>'], '']);
46
- assert.deepStrictEqual(inspect(parser('**<small>**')), [['<strong>&lt;small&gt;</strong>'], '']);
46
+ assert.deepStrictEqual(inspect(parser('**<bdi>**')), [['<strong>&lt;bdi&gt;</strong>'], '']);
47
47
  assert.deepStrictEqual(inspect(parser('**(*a*)**')), [['<strong><span class="paren">(<em>a</em>)</span></strong>'], '']);
48
48
  assert.deepStrictEqual(inspect(parser('**(**a**)**')), [['<strong><span class="paren">(<strong>a</strong>)</span></strong>'], '']);
49
49
  });
@@ -99,8 +99,8 @@ describe('Unit: parser/inline', () => {
99
99
  assert.deepStrictEqual(inspect(parser('*++ ++*')), [['<em><ins> </ins></em>'], '']);
100
100
  assert.deepStrictEqual(inspect(parser('*++ a ++*')), [['<em><ins> a </ins></em>'], '']);
101
101
  assert.deepStrictEqual(inspect(parser('*++ a ++*')), [['<em><ins> a </ins></em>'], '']);
102
- assert.deepStrictEqual(inspect(parser('*<small>`a`</small>*')), [['<em><small><code data-src="`a`">a</code></small></em>'], '']);
103
- assert.deepStrictEqual(inspect(parser('<small>*<bdi>a</bdi>*</small>')), [['<small><em><bdi>a</bdi></em></small>'], '']);
102
+ assert.deepStrictEqual(inspect(parser('*<bdi>`a`</bdi>*')), [['<em><bdi><code data-src="`a`">a</code></bdi></em>'], '']);
103
+ assert.deepStrictEqual(inspect(parser('<bdi>*<bdi>a</bdi>*</bdi>')), [['<bdi><em><bdi>a</bdi></em></bdi>'], '']);
104
104
  assert.deepStrictEqual(inspect(parser('<bdi>((<bdi>((a))</bdi>))</bdi>')), [['<bdi><sup class="annotation"><span><bdi><span class="paren">((a))</span></bdi></span></sup></bdi>'], '']);
105
105
  assert.deepStrictEqual(inspect(parser('<bdi>[[<bdi>[[a]]</bdi>]]</bdi>')), [['<bdi><sup class="reference"><span><bdi>[[a]]</bdi></span></sup></bdi>'], '']);
106
106
  assert.deepStrictEqual(inspect(parser('*[*]')), [['*', '[', '*', ']'], '']);
@@ -155,9 +155,8 @@ describe('Unit: parser/inline', () => {
155
155
  assert.deepStrictEqual(inspect(parser('[(([a]{#}))]{#}')), [['<a href="#"><span class="paren">(<span class="paren">([a]{#})</span>)</span></a>'], '']);
156
156
  assert.deepStrictEqual(inspect(parser('"[[""]]')), [['"', '<sup class="reference"><span>""</span></sup>'], '']);
157
157
  assert.deepStrictEqual(inspect(parser('<http://host>')), [['<', '<a href="http://host" target="_blank">http://host</a>', '>'], '']);
158
- assert.deepStrictEqual(inspect(parser('<<small>a<</small>')), [['<', '<small>a&lt;</small>'], '']);
159
- assert.deepStrictEqual(inspect(parser('<sup><sub>a</sub>')), [['<', 'sup', '>', '<sub>a</sub>'], '']);
160
- assert.deepStrictEqual(inspect(parser('*<small>*`</small>`')), [['<em>&lt;small&gt;</em>', '<code data-src="`</small>`">&lt;/small&gt;</code>'], '']);
158
+ assert.deepStrictEqual(inspect(parser('<<bdi>a<</bdi>')), [['<', '<bdi>a&lt;</bdi>'], '']);
159
+ assert.deepStrictEqual(inspect(parser('*<bdi>*`</bdi>`')), [['<em>&lt;bdi&gt;</em>', '<code data-src="`</bdi>`">&lt;/bdi&gt;</code>'], '']);
161
160
  assert.deepStrictEqual(inspect(parser('[~http://host')), [['[', '~', '<a href="http://host" target="_blank">http://host</a>'], '']);
162
161
  assert.deepStrictEqual(inspect(parser('[~a@b')), [['[', '~', '<a class="email" href="mailto:a@b">a@b</a>'], '']);
163
162
  assert.deepStrictEqual(inspect(parser('[~~a~~]')), [['[', '<del>a</del>', ']'], '']);
@@ -6,14 +6,11 @@ import { push } from 'spica/array';
6
6
 
7
7
  export function* figure(
8
8
  target: ParentNode & Node,
9
- footnotes?: Readonly<{ annotations?: HTMLOListElement; references: HTMLOListElement; }>,
10
- opts: Readonly<{
11
- id?: string;
12
- }> = {},
9
+ footnotes?: { readonly references: HTMLOListElement; },
10
+ opts: { readonly id?: string; } = {},
13
11
  ): Generator<HTMLAnchorElement | undefined, undefined, undefined> {
14
- const refs = new MultiMap<string, HTMLAnchorElement>(push(push(push([],
12
+ const refs = new MultiMap<string, HTMLAnchorElement>(push(push([],
15
13
  target.querySelectorAll('a.label:not(.disabled)[data-label]')),
16
- footnotes?.annotations?.querySelectorAll('a.label:not(.disabled)') ?? []),
17
14
  footnotes?.references.querySelectorAll('a.label:not(.disabled)') ?? [])
18
15
  .map(el => [el.getAttribute('data-label')!, el]));
19
16
  const labels = new Set<string>();
@@ -6,11 +6,12 @@ import { push } from 'spica/array';
6
6
 
7
7
  export function* footnote(
8
8
  target: ParentNode & Node,
9
- footnotes?: Readonly<{ annotations?: HTMLOListElement; references: HTMLOListElement; }>,
10
- opts: Readonly<{ id?: string; }> = {},
9
+ footnotes?: { readonly annotations?: HTMLOListElement; readonly references: HTMLOListElement; },
10
+ opts: { readonly id?: string; } = {},
11
+ bottom: Node | null = null,
11
12
  ): Generator<HTMLAnchorElement | HTMLLIElement | undefined, undefined, undefined> {
12
- yield* reference(target, footnotes?.references, opts);
13
- yield* annotation(target, footnotes?.annotations, opts);
13
+ yield* reference(target, footnotes?.references, opts, bottom);
14
+ yield* annotation(target, footnotes?.annotations, opts, bottom);
14
15
  return;
15
16
  }
16
17
 
@@ -28,9 +29,9 @@ function build(
28
29
  return function* (
29
30
  target: ParentNode & Node,
30
31
  footnote?: HTMLOListElement,
31
- opts: Readonly<{ id?: string }> = {},
32
+ opts: { readonly id?: string } = {},
33
+ bottom: Node | null = null,
32
34
  ): Generator<HTMLAnchorElement | HTMLLIElement | undefined, undefined, undefined> {
33
- //assert(syntax !== 'annotation' || !footnote);
34
35
  const defs = new Map<string, HTMLLIElement>();
35
36
  const buffer = new MultiMap<string, HTMLElement>();
36
37
  const titles = new Map<string, string>();
@@ -148,7 +149,7 @@ function build(
148
149
  `^${refIndex}`));
149
150
  }
150
151
  if (defs.size > 0 || footnote) {
151
- yield* proc(defs, footnote ?? target.insertBefore(html('ol', { class: `${syntax}s` }), splitters[0] ?? target.querySelector(':scope > :is(#annotations, #references)')));
152
+ yield* proc(defs, footnote ?? target.insertBefore(html('ol', { class: `${syntax}s` }), splitters[0] ?? bottom));
152
153
  }
153
154
  return;
154
155
  }
@@ -1,7 +1,7 @@
1
1
  import Prism from 'prismjs';
2
- import { Collection } from 'spica/collection';
2
+ import { Dict } from 'spica/dict';
3
3
 
4
- export function code(target: HTMLElement, cache?: Collection<string, HTMLElement>): void {
4
+ export function code(target: HTMLElement, cache?: Dict<string, HTMLElement>): void {
5
5
  assert(target.children.length === 0);
6
6
  const source = target.textContent!;
7
7
  Prism.highlightElement(target, false, () =>
@@ -1,8 +1,8 @@
1
1
  import { undefined } from 'spica/global';
2
- import { Collection } from 'spica/collection';
2
+ import { Dict } from 'spica/dict';
3
3
  import { html, define } from 'typed-dom/dom';
4
4
 
5
- export function math(target: HTMLElement, cache?: Collection<string, HTMLElement>): void {
5
+ export function math(target: HTMLElement, cache?: Dict<string, HTMLElement>): void {
6
6
  assert(target.children.length === 0);
7
7
  const source = target.textContent!;
8
8
  queue(target, () => {
@@ -1,8 +1,8 @@
1
1
  import { Object } from 'spica/global';
2
- import { Collection } from 'spica/collection';
2
+ import { Dict } from 'spica/dict';
3
3
  import { define } from 'typed-dom/dom';
4
4
 
5
- export function image(source: HTMLImageElement, url: URL, cache?: Collection<string, HTMLElement>): HTMLImageElement {
5
+ export function image(source: HTMLImageElement, url: URL, cache?: Dict<string, HTMLElement>): HTMLImageElement {
6
6
  if (cache?.has(url.href)) return define(
7
7
  cache.get(url.href)!.cloneNode(true) as HTMLImageElement,
8
8
  Object.fromEntries([...source.attributes]
@@ -5,7 +5,7 @@ import { pdf } from './media/pdf';
5
5
  import { video } from './media/video';
6
6
  import { audio } from './media/audio';
7
7
  import { image } from './media/image';
8
- import { Collection } from 'spica/collection';
8
+ import { Dict } from 'spica/dict';
9
9
  import { ReadonlyURL } from 'spica/url';
10
10
  import { reduce } from 'spica/memoize';
11
11
 
@@ -14,7 +14,7 @@ type MediaOptions = NonNullable<RenderingOptions['media']>;
14
14
  const extend = reduce((opts: MediaOptions): MediaOptions =>
15
15
  ({ twitter, youtube, pdf, video, audio, image, ...opts }));
16
16
 
17
- export function media(base: string, source: HTMLImageElement, opts: MediaOptions, cache?: Collection<string, HTMLElement>): HTMLElement | undefined {
17
+ export function media(base: string, source: HTMLImageElement, opts: MediaOptions, cache?: Dict<string, HTMLElement>): HTMLElement | undefined {
18
18
  assert(source.matches('img:not([src])[data-src]'));
19
19
  opts = extend(opts);
20
20
  const url = new ReadonlyURL(source.getAttribute('data-src')!, base);