securemark 0.298.0 → 0.298.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.298.2
4
+
5
+ - Refactoring.
6
+
7
+ ## 0.298.1
8
+
9
+ - Refactoring.
10
+
3
11
  ## 0.298.0
4
12
 
5
13
  - Refactoring.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! securemark v0.298.0 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
1
+ /*! securemark v0.298.2 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("Prism"), require("DOMPurify"));
@@ -4518,6 +4518,7 @@ function parse(source, options = {}, context) {
4518
4518
  host: options.host ?? context?.host ?? new url_1.ReadonlyURL(location.pathname, location.origin),
4519
4519
  url: url ? new url_1.ReadonlyURL(url) : context?.url,
4520
4520
  id: options.id ?? context?.id,
4521
+ local: options.local ?? context?.local,
4521
4522
  caches: context?.caches,
4522
4523
  resources: context?.resources
4523
4524
  });
@@ -4713,7 +4714,8 @@ const markdown = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combina
4713
4714
  class: 'references'
4714
4715
  });
4715
4716
  const document = (0, parse_1.parse)(source, {
4716
- id: '',
4717
+ local: true,
4718
+ id: context.id === '' ? '' : (0, util_1.randomID)(),
4717
4719
  notes: {
4718
4720
  references
4719
4721
  }
@@ -4867,7 +4869,8 @@ exports.aside = (0, combinator_1.block)((0, combinator_1.recursion)(0 /* Recursi
4867
4869
  class: 'references'
4868
4870
  });
4869
4871
  const document = (0, parse_1.parse)(body.slice(0, -1), {
4870
- id: '',
4872
+ local: true,
4873
+ id: context.id === '' ? '' : (0, util_1.randomID)(),
4871
4874
  notes: {
4872
4875
  references
4873
4876
  }
@@ -4918,7 +4921,8 @@ exports.example = (0, combinator_1.block)((0, combinator_1.recursion)(0 /* Recur
4918
4921
  class: 'references'
4919
4922
  });
4920
4923
  const document = (0, parse_1.parse)(body.slice(0, -1), {
4921
- id: '',
4924
+ local: true,
4925
+ id: context.id === '' ? '' : (0, util_1.randomID)(),
4922
4926
  notes: {
4923
4927
  references
4924
4928
  }
@@ -6014,8 +6018,9 @@ class Context extends parser_1.Context {
6014
6018
  this.recursion = new RecursionCounter('annotation', 2);
6015
6019
  const {
6016
6020
  segment,
6017
- buffer,
6021
+ local,
6018
6022
  sequential,
6023
+ buffer,
6019
6024
  header,
6020
6025
  host,
6021
6026
  url,
@@ -6023,8 +6028,9 @@ class Context extends parser_1.Context {
6023
6028
  caches
6024
6029
  } = options;
6025
6030
  this.segment = segment ?? 0 /* Segment.unknown */;
6026
- this.buffer = buffer ?? new parser_1.List();
6031
+ this.local = local ?? false;
6027
6032
  this.sequential = sequential ?? false;
6033
+ this.buffer = buffer ?? new parser_1.List();
6028
6034
  this.header = header ?? true;
6029
6035
  this.host = host;
6030
6036
  this.url = url;
@@ -6306,7 +6312,6 @@ exports.annotation = (0, combinator_1.lazy)(() => (0, combinator_1.constraint)(1
6306
6312
  const {
6307
6313
  source,
6308
6314
  position,
6309
- range,
6310
6315
  linebreak,
6311
6316
  recursion,
6312
6317
  resources
@@ -6354,12 +6359,10 @@ exports.annotation = (0, combinator_1.lazy)(() => (0, combinator_1.constraint)(1
6354
6359
  if (source[context.position] === ')') {
6355
6360
  bs.push(new parser_1.Node(')'));
6356
6361
  context.position += 1;
6362
+ context.range += 1;
6357
6363
  }
6358
- const str = linebreak === 0 ? source.slice(position - range + 2, position) : '';
6359
- bs = linebreak === 0 && (str === '' || bracket_1.indexA.test(str)) ? new parser_1.List([new parser_1.Node((0, dom_1.html)('span', {
6360
- class: 'paren'
6361
- }, (0, dom_1.defrag)((0, util_1.unwrap)(bs))))]) : new parser_1.List([new parser_1.Node((0, dom_1.html)('span', {
6362
- class: 'bracket'
6364
+ bs = new parser_1.List([new parser_1.Node((0, dom_1.html)('span', {
6365
+ class: (0, bracket_1.bracketname)(context, bracket_1.indexA, 2, context.position - position)
6363
6366
  }, (0, dom_1.defrag)((0, util_1.unwrap)(bs))))]);
6364
6367
  bs.unshift(new parser_1.Node('('));
6365
6368
  const cs = parser(context);
@@ -6656,7 +6659,7 @@ const bracket = (0, combinator_1.lazy)(() => (0, combinator_1.union)([(0, combin
6656
6659
  Object.defineProperty(exports, "__esModule", ({
6657
6660
  value: true
6658
6661
  }));
6659
- exports.bracket = exports.indexA = void 0;
6662
+ exports.bracket = exports.bracketname = exports.indexA = void 0;
6660
6663
  const parser_1 = __webpack_require__(605);
6661
6664
  const combinator_1 = __webpack_require__(3484);
6662
6665
  const inline_1 = __webpack_require__(7973);
@@ -6664,8 +6667,19 @@ const link_1 = __webpack_require__(3628);
6664
6667
  const source_1 = __webpack_require__(8745);
6665
6668
  const util_1 = __webpack_require__(4992);
6666
6669
  const dom_1 = __webpack_require__(394);
6667
- exports.indexA = /^[0-9A-Za-z]+(?:(?:[.-]|, )[0-9A-Za-z]+)*$/;
6668
- const indexF = new RegExp(exports.indexA.source.replace(', ', '[,、]').replace(/[09AZaz.]|\-(?!\w)/g, c => String.fromCodePoint(c.codePointAt(0) + 0xFEE0)));
6670
+ exports.indexA = /[0-9A-Za-z]+(?:(?:[.-]|, )[0-9A-Za-z]+)*/y;
6671
+ const indexF = new RegExp(exports.indexA.source.replace(', ', '[,、]').replace(/[09AZaz.]|\-(?!\w)/g, c => String.fromCodePoint(c.codePointAt(0) + 0xFEE0)), 'y');
6672
+ function bracketname(context, syntax, opener, closer) {
6673
+ const {
6674
+ source,
6675
+ position,
6676
+ range,
6677
+ linebreak
6678
+ } = context;
6679
+ syntax.lastIndex = position - range + opener;
6680
+ return range - opener - closer === 0 || linebreak === 0 && range - opener - closer <= 16 && syntax.test(source) && syntax.lastIndex === position - closer ? 'paren' : 'bracket';
6681
+ }
6682
+ exports.bracketname = bracketname;
6669
6683
  exports.bracket = (0, combinator_1.lazy)(() => (0, combinator_1.union)([input => {
6670
6684
  const {
6671
6685
  source,
@@ -6688,58 +6702,16 @@ exports.bracket = (0, combinator_1.lazy)(() => (0, combinator_1.union)([input =>
6688
6702
  return d1(input);
6689
6703
  }
6690
6704
  }]));
6691
- const p1 = (0, combinator_1.lazy)(() => (0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.precedence)(1, (0, combinator_1.recursion)(5 /* Recursion.bracket */, (0, combinator_1.some)(inline_1.inline, ')', [[')', 1]]))), (0, source_1.str)(')'), true, [], ([as, bs = [], cs], {
6692
- source,
6693
- position,
6694
- range,
6695
- linebreak
6696
- }) => {
6697
- const str = linebreak === 0 ? source.slice(position - range + 1, position - 1) : '';
6698
- return linebreak === 0 && (str === '' || exports.indexA.test(str)) ? new parser_1.List([new parser_1.Node((0, dom_1.html)('span', {
6699
- class: 'paren'
6700
- }, `(${str})`))]) : new parser_1.List([new parser_1.Node((0, dom_1.html)('span', {
6701
- class: 'bracket'
6702
- }, (0, dom_1.defrag)((0, util_1.unwrap)(as.import(bs).import(cs)))))]);
6703
- }, ([as, bs = new parser_1.List()], context) => {
6704
- const {
6705
- source,
6706
- position,
6707
- range,
6708
- linebreak
6709
- } = context;
6710
- const str = linebreak === 0 ? source.slice(position - range + 1, position) : '';
6711
- return linebreak === 0 && (str === '' || exports.indexA.test(str)) ? new parser_1.List([new parser_1.Node((0, dom_1.html)('span', {
6712
- class: 'paren'
6713
- }, `(${str}`))]) : new parser_1.List([new parser_1.Node((0, dom_1.html)('span', {
6714
- class: 'bracket'
6715
- }, (0, dom_1.defrag)((0, util_1.unwrap)(as.import(bs)))))]);
6716
- }));
6717
- const p2 = (0, combinator_1.lazy)(() => (0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.precedence)(1, (0, combinator_1.recursion)(5 /* Recursion.bracket */, (0, combinator_1.some)(inline_1.inline, ')', [[')', 1]]))), (0, source_1.str)(')'), true, [], ([as, bs = [], cs], {
6718
- source,
6719
- position,
6720
- range,
6721
- linebreak
6722
- }) => {
6723
- const str = linebreak === 0 ? source.slice(position - range + 1, position - 1) : '';
6724
- return linebreak === 0 && (str === '' || indexF.test(str)) ? new parser_1.List([new parser_1.Node((0, dom_1.html)('span', {
6725
- class: 'paren'
6726
- }, `(${str})`))]) : new parser_1.List([new parser_1.Node((0, dom_1.html)('span', {
6727
- class: 'bracket'
6728
- }, (0, dom_1.defrag)((0, util_1.unwrap)(as.import(bs).import(cs)))))]);
6729
- }, ([as, bs = new parser_1.List()], context) => {
6730
- const {
6731
- source,
6732
- position,
6733
- range,
6734
- linebreak
6735
- } = context;
6736
- const str = linebreak === 0 ? source.slice(position - range + 1, position) : '';
6737
- return linebreak === 0 && (str === '' || indexF.test(str)) ? new parser_1.List([new parser_1.Node((0, dom_1.html)('span', {
6738
- class: 'paren'
6739
- }, `(${str}`))]) : new parser_1.List([new parser_1.Node((0, dom_1.html)('span', {
6740
- class: 'bracket'
6741
- }, (0, dom_1.defrag)((0, util_1.unwrap)(as.import(bs)))))]);
6742
- }));
6705
+ const p1 = (0, combinator_1.lazy)(() => (0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.precedence)(1, (0, combinator_1.recursion)(5 /* Recursion.bracket */, (0, combinator_1.some)(inline_1.inline, ')', [[')', 1]]))), (0, source_1.str)(')'), true, [], ([as, bs = new parser_1.List(), cs], context) => new parser_1.List([new parser_1.Node((0, dom_1.html)('span', {
6706
+ class: bracketname(context, exports.indexA, 1, 1)
6707
+ }, (0, dom_1.defrag)((0, util_1.unwrap)(as.import(bs).import(cs)))))]), ([as, bs = new parser_1.List()], context) => new parser_1.List([new parser_1.Node((0, dom_1.html)('span', {
6708
+ class: bracketname(context, exports.indexA, 1, 0)
6709
+ }, (0, dom_1.defrag)((0, util_1.unwrap)(as.import(bs)))))])));
6710
+ const p2 = (0, combinator_1.lazy)(() => (0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.precedence)(1, (0, combinator_1.recursion)(5 /* Recursion.bracket */, (0, combinator_1.some)(inline_1.inline, ')', [[')', 1]]))), (0, source_1.str)(')'), true, [], ([as, bs = new parser_1.List(), cs], context) => new parser_1.List([new parser_1.Node((0, dom_1.html)('span', {
6711
+ class: bracketname(context, indexF, 1, 1)
6712
+ }, (0, dom_1.defrag)((0, util_1.unwrap)(as.import(bs).import(cs)))))]), ([as, bs = new parser_1.List()], context) => new parser_1.List([new parser_1.Node((0, dom_1.html)('span', {
6713
+ class: bracketname(context, indexF, 1, 0)
6714
+ }, (0, dom_1.defrag)((0, util_1.unwrap)(as.import(bs)))))])));
6743
6715
  const s1 = (0, combinator_1.lazy)(() => (0, combinator_1.surround)((0, source_1.str)('['), (0, combinator_1.precedence)(1, (0, combinator_1.recursion)(5 /* Recursion.bracket */, (0, combinator_1.some)(inline_1.inline, ']', [[']', 1]]))), (0, source_1.str)(']'), true, [2 | 4 /* Backtrack.common */], ([as, bs = new parser_1.List(), cs], context) => {
6744
6716
  const {
6745
6717
  source,
@@ -7069,18 +7041,20 @@ const combinator_1 = __webpack_require__(3484);
7069
7041
  const dom_1 = __webpack_require__(394);
7070
7042
  function indexee(parser) {
7071
7043
  return (0, combinator_1.fmap)(parser, (ns, {
7072
- id
7044
+ id,
7045
+ local
7073
7046
  }) => ns.length === 1 ? new parser_1.List([new parser_1.Node((0, dom_1.define)(ns.head.value, {
7074
7047
  id: identity('index', id, ns.head.value),
7048
+ class: local ? `${ns.head.value.className} local`.trimStart() : undefined,
7075
7049
  'data-index': null
7076
7050
  }))]) : ns);
7077
7051
  }
7078
7052
  exports.indexee = indexee;
7079
- const MAX = 60;
7053
+ const table = [...[...Array(36)].map((_, i) => i.toString(36)), ...[...Array(36)].map((_, i) => i.toString(36).toUpperCase()).slice(-26), '-', '='].join('');
7054
+ const MAX = 64 - '='.length - Math.ceil(Math.log(~0 >>> 0) / Math.log(table.length));
7080
7055
  const ELLIPSIS = '...';
7081
7056
  const PART = (MAX - ELLIPSIS.length) / 2 | 0;
7082
7057
  const REM = MAX - PART * 2 - ELLIPSIS.length;
7083
- const table = [...[...Array(36)].map((_, i) => i.toString(36)), ...[...Array(36)].map((_, i) => i.toString(36).toUpperCase()).slice(-26), '-', '='].join('');
7084
7058
  function identity(type, id, text) {
7085
7059
  if (id === '') return undefined;
7086
7060
  if (typeof text !== 'string') {
@@ -7112,7 +7086,9 @@ function hash(source) {
7112
7086
  }
7113
7087
  return baseR(x >>> 0, 62);
7114
7088
  }
7089
+
7115
7090
  // 62も64も最大6桁
7091
+
7116
7092
  function baseR(n, r) {
7117
7093
  let acc = '';
7118
7094
  do {
@@ -8137,17 +8113,16 @@ const array_1 = __webpack_require__(6876);
8137
8113
  const dom_1 = __webpack_require__(394);
8138
8114
  const query_1 = __webpack_require__(2282);
8139
8115
  function* figure(target, notes, opts = {}) {
8140
- const refs = new queue_1.MultiQueue((0, array_1.push)((0, query_1.querySelectorAll)(target, 'a.label:not(.disabled)[data-label]'), notes && (0, query_1.querySelectorAll)(notes.references, 'a.label:not(.disabled)') || []).map(el => [el.getAttribute('data-label'), el]));
8116
+ const selector = ':is(figure[data-label], h1, h2)';
8117
+ const refs = new queue_1.MultiQueue((0, array_1.push)((0, query_1.querySelectorAll)(target, 'a.label:not(.local)[data-label]'), notes && (0, query_1.querySelectorAll)(notes.references, 'a.label:not(.local)') || []).map(el => [el.getAttribute('data-label'), el]));
8141
8118
  const labels = new Set();
8142
8119
  const numbers = new Map();
8143
- const scope = target instanceof Element ? ':scope > ' : '';
8144
8120
  let base = '0';
8145
8121
  let bases = base.split('.');
8146
8122
  let index = bases;
8147
- for (let defs = target.querySelectorAll(`${scope}:is(figure[data-label], h1, h2)`), len = defs.length, i = 0; i < len; ++i) {
8123
+ for (let defs = target instanceof Element ? target.querySelectorAll(`:scope > ${selector}`) : target.querySelectorAll(`${selector}:not(* > *)`), len = defs.length, i = 0; i < len; ++i) {
8148
8124
  yield;
8149
8125
  const def = defs[i];
8150
- if (!scope && def.parentNode !== target) continue;
8151
8126
  const {
8152
8127
  tagName
8153
8128
  } = def;
@@ -8219,10 +8194,9 @@ function* figure(target, notes, opts = {}) {
8219
8194
  (0, util_1.unmarkInvalid)(ref);
8220
8195
  }
8221
8196
  if (ref.hash.slice(1) === def.id && ref.innerText === figindex) continue;
8222
- yield (0, dom_1.define)(ref, opts.id !== '' ? {
8223
- href: `#${def.id}`
8224
- } : {
8225
- class: `${ref.className} disabled`
8197
+ yield (0, dom_1.define)(ref, {
8198
+ class: opts.local ? `${ref.className} local` : undefined,
8199
+ href: opts.id !== '' ? `#${def.id}` : undefined
8226
8200
  }, figindex);
8227
8201
  }
8228
8202
  }
@@ -8289,9 +8263,9 @@ function* note(target, notes, opts = {}, bottom = null) {
8289
8263
  exports.note = note;
8290
8264
  const annotationRefsMemoryCaller = (0, memoize_1.memoize)(target => new Map() ?? target, new WeakMap());
8291
8265
  const referenceRefsMemoryCaller = (0, memoize_1.memoize)(target => new Map() ?? target, new WeakMap());
8292
- const annotation = build('annotation', 'annotations', '.annotation:not(:is(.annotations, .references) .annotation, .disabled)', n => `*${n}`, 'h1, h2, h3, h4, h5, h6, aside.aside, hr');
8293
- const reference = build('reference', 'references', '.reference:not(:is(.annotations, .references) .reference, .disabled)', (n, abbr) => `[${abbr || n}]`);
8294
- function build(syntax, list, query, marker, splitter = '') {
8266
+ const annotation = build('annotation', 'annotations', '.annotation:not(:is(.annotations, .references) &, .local)', n => `*${n}`, 'h1, h2, h3, h4, h5, h6, aside.aside, hr');
8267
+ const reference = build('reference', 'references', '.reference:not(:is(.annotations, .references) &, .local)', (n, abbr) => `[${abbr || n}]`);
8268
+ function build(syntax, list, selector, marker, splitter = '') {
8295
8269
  splitter &&= `${splitter}, .${list}`;
8296
8270
  return function* (memory, target, note, opts = {}, bottom = null) {
8297
8271
  const refInfoCaller = (0, memoize_1.memoize)(ref => {
@@ -8308,7 +8282,7 @@ function build(syntax, list, query, marker, splitter = '') {
8308
8282
  };
8309
8283
  }, memory);
8310
8284
  const defs = new Map();
8311
- const refs = target.querySelectorAll(query);
8285
+ const refs = target.querySelectorAll(selector);
8312
8286
  const identifierInfoCaller = (0, memoize_1.memoize)(identifier => ({
8313
8287
  defIndex: 0,
8314
8288
  defSubindex: 0,
@@ -8316,8 +8290,7 @@ function build(syntax, list, query, marker, splitter = '') {
8316
8290
  title: '' && 0,
8317
8291
  queue: []
8318
8292
  }));
8319
- const scope = target instanceof Element ? ':scope > ' : '';
8320
- const splitters = splitter ? target.querySelectorAll(`${scope}:is(${splitter})`) : [];
8293
+ const splitters = splitter ? target instanceof Element ? target.querySelectorAll(`:scope > :is(${splitter}, .${list})`) : target.querySelectorAll(`:is(${splitter}, .${list}):not(* > *)`) : [];
8321
8294
  let iSplitters = 0;
8322
8295
  let total = 0;
8323
8296
  let format;
@@ -8328,7 +8301,8 @@ function build(syntax, list, query, marker, splitter = '') {
8328
8301
  const pos = splitter?.compareDocumentPosition(ref) ?? 0;
8329
8302
  if (pos & (Node.DOCUMENT_POSITION_PRECEDING | Node.DOCUMENT_POSITION_DISCONNECTED)) break;
8330
8303
  if (~iSplitters << 32 - 8 === 0) yield;
8331
- if (splitter.classList.contains(list) && defs.size === 0) {
8304
+ if (splitter.classList.contains(list) && splitter.nextElementSibling !== splitters[iSplitters + 1]) {
8305
+ yield* proc(splitter);
8332
8306
  splitter.remove();
8333
8307
  continue;
8334
8308
  }
@@ -8337,7 +8311,7 @@ function build(syntax, list, query, marker, splitter = '') {
8337
8311
  const note = splitter.classList.contains(list) ? splitter : target.insertBefore((0, dom_1.html)('ol', {
8338
8312
  class: list
8339
8313
  }), splitter);
8340
- yield* proc(defs, note);
8314
+ yield* proc(note, defs);
8341
8315
  }
8342
8316
  }
8343
8317
  const {
@@ -8364,7 +8338,7 @@ function build(syntax, list, query, marker, splitter = '') {
8364
8338
  const title = info.title ||= text;
8365
8339
  (0, dom_1.define)(ref, {
8366
8340
  id: refId,
8367
- class: opts.id !== '' ? undefined : void ref.classList.add('disabled'),
8341
+ class: opts.local ? `${ref.className} local` : undefined,
8368
8342
  title
8369
8343
  }, []);
8370
8344
  if (title && info.queue.length > 0) {
@@ -8403,25 +8377,25 @@ function build(syntax, list, query, marker, splitter = '') {
8403
8377
  }
8404
8378
  if (note || defs.size > 0) {
8405
8379
  const splitter = splitters[iSplitters++];
8406
- yield* proc(defs, note ?? (splitter?.classList.contains(list) ? splitter : target.insertBefore((0, dom_1.html)('ol', {
8380
+ note ??= splitter?.classList.contains(list) ? splitter : target.insertBefore((0, dom_1.html)('ol', {
8407
8381
  class: list
8408
- }), splitter ?? bottom)));
8382
+ }), splitter ?? bottom);
8383
+ yield* proc(note, defs);
8409
8384
  }
8410
8385
  if (splitter) for (let splitter; splitter = splitters[iSplitters]; ++iSplitters) {
8411
8386
  if (~iSplitters << 32 - 8 === 0) yield;
8412
8387
  if (splitter.classList.contains(list)) {
8388
+ yield* proc(splitter);
8413
8389
  splitter.remove();
8414
8390
  }
8415
8391
  }
8416
8392
  };
8417
8393
  }
8418
- function* proc(defs, note) {
8419
- const {
8420
- children
8421
- } = note;
8394
+ function* proc(note, defs) {
8422
8395
  for (let defs = note.children, i = defs.length; i--;) {
8423
- yield note.removeChild(children[i]);
8396
+ yield note.removeChild(defs[i]);
8424
8397
  }
8398
+ if (!defs) return;
8425
8399
  for (const [, def] of defs) {
8426
8400
  yield note.appendChild(def);
8427
8401
  }
@@ -9046,10 +9020,11 @@ exports.unescsource = unescsource;
9046
9020
  Object.defineProperty(exports, "__esModule", ({
9047
9021
  value: true
9048
9022
  }));
9049
- exports.stringify = exports.unmarkInvalid = exports.markInvalid = exports.invalid = exports.repeat = exports.unwrap = void 0;
9023
+ exports.randomID = exports.stringify = exports.unmarkInvalid = exports.markInvalid = exports.invalid = exports.repeat = exports.unwrap = void 0;
9050
9024
  const parser_1 = __webpack_require__(605);
9051
9025
  const delimiter_1 = __webpack_require__(385);
9052
9026
  const alias_1 = __webpack_require__(5413);
9027
+ const random_1 = __webpack_require__(3158);
9053
9028
  const dom_1 = __webpack_require__(394);
9054
9029
  function* unwrap(nodes) {
9055
9030
  if (nodes === undefined) return;
@@ -9167,6 +9142,10 @@ function stringify(nodes) {
9167
9142
  return acc;
9168
9143
  }
9169
9144
  exports.stringify = stringify;
9145
+ function randomID() {
9146
+ return `random-${(0, random_1.rnd0Z)(6)}`;
9147
+ }
9148
+ exports.randomID = randomID;
9170
9149
 
9171
9150
  /***/ },
9172
9151
 
@@ -9868,7 +9847,7 @@ Object.defineProperty(exports, "__esModule", ({
9868
9847
  exports.toc = void 0;
9869
9848
  const array_1 = __webpack_require__(6876);
9870
9849
  const dom_1 = __webpack_require__(394);
9871
- const selector = ':is(h1, h2, h3, h4, h5, h6, aside.aside)[id]';
9850
+ const selector = ':is(h1, h2, h3, h4, h5, h6, aside.aside)[id]:not(.local)';
9872
9851
  function toc(source) {
9873
9852
  const hs = [];
9874
9853
  for (let es = source.querySelectorAll(selector), len = es.length, i = 0; i < len; ++i) {
package/markdown.d.ts CHANGED
@@ -16,10 +16,12 @@ export namespace MarkdownParser {
16
16
  Markdown<'segment'>,
17
17
  Parser<string, Context, [
18
18
  SourceParser.EmptySegmentParser,
19
- BlockParser.HeadingParser.SegmentParser,
20
- BlockParser.CodeBlockParser.SegmentParser,
21
- BlockParser.MathBlockParser.SegmentParser,
22
- BlockParser.ExtensionParser.SegmentParser,
19
+ Parser<string, Context, [
20
+ BlockParser.HeadingParser.SegmentParser,
21
+ BlockParser.CodeBlockParser.SegmentParser,
22
+ BlockParser.MathBlockParser.SegmentParser,
23
+ BlockParser.ExtensionParser.SegmentParser,
24
+ ]>,
23
25
  SourceParser.ContentLineParser,
24
26
  ]> {
25
27
  }
@@ -48,20 +50,22 @@ export namespace MarkdownParser {
48
50
  Markdown<'block'>,
49
51
  Parser<HTMLElement, Context, [
50
52
  SourceParser.EmptySegmentParser,
51
- BlockParser.PagebreakParser,
52
- BlockParser.HeadingParser,
53
- BlockParser.UListParser,
54
- BlockParser.OListParser,
55
- BlockParser.IListParser,
56
- BlockParser.DListParser,
57
- BlockParser.TableParser,
58
- BlockParser.CodeBlockParser,
59
- BlockParser.MathBlockParser,
60
- BlockParser.ExtensionParser,
61
- BlockParser.SidefenceParser,
62
- BlockParser.BlockquoteParser,
63
- BlockParser.MediaBlockParser,
64
- BlockParser.ReplyParser,
53
+ Parser<HTMLElement, Context, [
54
+ BlockParser.PagebreakParser,
55
+ BlockParser.HeadingParser,
56
+ BlockParser.UListParser,
57
+ BlockParser.OListParser,
58
+ BlockParser.IListParser,
59
+ BlockParser.DListParser,
60
+ BlockParser.TableParser,
61
+ BlockParser.CodeBlockParser,
62
+ BlockParser.MathBlockParser,
63
+ BlockParser.ExtensionParser,
64
+ BlockParser.SidefenceParser,
65
+ BlockParser.BlockquoteParser,
66
+ BlockParser.MediaBlockParser,
67
+ BlockParser.ReplyParser,
68
+ ]>,
65
69
  BlockParser.ParagraphParser,
66
70
  ]> {
67
71
  }
@@ -614,25 +618,27 @@ export namespace MarkdownParser {
614
618
  export interface InlineParser extends
615
619
  Markdown<'inline'>,
616
620
  Parser<HTMLElement | string, Context, [
617
- InlineParser.AnnotationParser,
618
- InlineParser.ReferenceParser,
619
- InlineParser.TemplateParser,
620
- InlineParser.RemarkParser,
621
- InlineParser.ExtensionParser,
622
- InlineParser.LinkParser.TextLinkParser,
623
- InlineParser.RubyParser,
624
- InlineParser.HTMLParser,
625
- InlineParser.InsertionParser,
626
- InlineParser.DeletionParser,
627
- InlineParser.MarkParser,
628
- InlineParser.EmStrongParser,
629
- InlineParser.StrongParser,
630
- InlineParser.EmphasisParser,
631
- InlineParser.ItalicParser,
632
- InlineParser.MathParser,
633
- InlineParser.CodeParser,
634
- InlineParser.HTMLEntityParser,
635
- InlineParser.BracketParser,
621
+ Parser<HTMLElement | string, Context, [
622
+ InlineParser.AnnotationParser,
623
+ InlineParser.ReferenceParser,
624
+ InlineParser.TemplateParser,
625
+ InlineParser.RemarkParser,
626
+ InlineParser.ExtensionParser,
627
+ InlineParser.LinkParser.TextLinkParser,
628
+ InlineParser.RubyParser,
629
+ InlineParser.HTMLParser,
630
+ InlineParser.InsertionParser,
631
+ InlineParser.DeletionParser,
632
+ InlineParser.MarkParser,
633
+ InlineParser.EmStrongParser,
634
+ InlineParser.StrongParser,
635
+ InlineParser.EmphasisParser,
636
+ InlineParser.ItalicParser,
637
+ InlineParser.MathParser,
638
+ InlineParser.CodeParser,
639
+ InlineParser.HTMLEntityParser,
640
+ InlineParser.BracketParser,
641
+ ]>,
636
642
  InlineParser.AutolinkParser,
637
643
  SourceParser.TextParser,
638
644
  ]> {
@@ -1056,12 +1062,6 @@ export namespace MarkdownParser {
1056
1062
  Inline<'bracket'>,
1057
1063
  Parser<HTMLElement | string, Context, [
1058
1064
  InlineParser,
1059
- InlineParser,
1060
- InlineParser,
1061
- InlineParser,
1062
- InlineParser,
1063
- InlineParser,
1064
- InlineParser,
1065
1065
  ]> {
1066
1066
  }
1067
1067
  export interface AutolinkParser extends
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.298.0",
3
+ "version": "0.298.2",
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",
package/src/debug.test.ts CHANGED
@@ -43,6 +43,6 @@ export function inspect(parser: Parser<DocumentFragment | HTMLElement | string>,
43
43
  // Bug: Firefox
44
44
  export function normalize(html: string): string {
45
45
  return html
46
- .replace(/(data-number="[\w.]+") (hidden="")/g, '$2 $1')
47
- .replace(/(data-type="[\w-]+") (type="\w+")/g, '$2 $1');
46
+ .replace(/:random-\w+:/g, ':random:')
47
+ .replace(/ data-invalid-\w+="[^"]*"/g, '');
48
48
  }
@@ -1,6 +1,7 @@
1
1
  import { parse } from './parse';
2
2
  import { Context } from '../context';
3
3
  import { html } from 'typed-dom/dom';
4
+ import { normalize } from '../../debug.test';
4
5
 
5
6
  describe('Unit: parser/api/parse', () => {
6
7
  describe('parse', () => {
@@ -201,10 +202,10 @@ describe('Unit: parser/api/parse', () => {
201
202
  '~~~',
202
203
  ].join('\n'),
203
204
  '{#}',
204
- ].join('\n\n'), { host: new URL(`${location.origin}/z`) }).children].map(el => el.outerHTML),
205
+ ].join('\n\n'), { host: new URL(`${location.origin}/z`) }).children].map(el => normalize(el.outerHTML)),
205
206
  [
206
207
  `<aside class="header"><details open=""><summary>Header</summary><span class="field" data-name="url" data-value="https://example/x"><span class="field-name">URL</span>: <span class="field-value">https://example/x</span>\n</span></details></aside>`,
207
- '<pre class="invalid" translate="no" data-invalid-syntax="header" data-invalid-type="syntax" data-invalid-message="Invalid syntax">---\nURL: https://example/y\n---\n</pre>',
208
+ '<pre class="invalid" translate="no">---\nURL: https://example/y\n---\n</pre>',
208
209
  '<aside class="example" data-type="markdown"><pre translate="no">---\nURL: https://example/y\n---\n\n{#}</pre><hr><section><aside class="header"><details open=""><summary>Header</summary><span class="field" data-name="url" data-value="https://example/y"><span class="field-name">URL</span>: <span class="field-value">https://example/y</span>\n</span></details></aside><p><a class="url" href="https://example/y#" target="_blank">#</a></p><h2>References</h2><ol class="references"></ol></section></aside>',
209
210
  '<p><a class="url" href="https://example/x#" target="_blank">#</a></p>',
210
211
  ]);
@@ -11,6 +11,7 @@ import { ReadonlyURL } from 'spica/url';
11
11
  import { frag } from 'typed-dom/dom';
12
12
 
13
13
  interface Options extends ParserOptions {
14
+ readonly local?: boolean;
14
15
  readonly test?: boolean;
15
16
  }
16
17
 
@@ -21,6 +22,7 @@ export function parse(source: string, options: Options = {}, context?: Context):
21
22
  host: options.host ?? context?.host ?? new ReadonlyURL(location.pathname, location.origin),
22
23
  url: url ? new ReadonlyURL(url as ':') : context?.url,
23
24
  id: options.id ?? context?.id,
25
+ local: options.local ?? context?.local,
24
26
  caches: context?.caches,
25
27
  resources: context?.resources,
26
28
  });
@@ -78,7 +78,7 @@ describe('Unit: parser/block/blockquote', () => {
78
78
  assert.deepStrictEqual(inspect(parser, input('!> a \n b c ', new Context())), [['<blockquote><section><p> a<br> b c</p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
79
79
  assert.deepStrictEqual(inspect(parser, input('!>> a', new Context())), [['<blockquote><blockquote><section><p>a</p><h2>References</h2><ol class="references"></ol></section></blockquote></blockquote>'], '']);
80
80
  assert.deepStrictEqual(inspect(parser, input('!>> a\n> b', new Context())), [['<blockquote><blockquote><section><p>a</p><h2>References</h2><ol class="references"></ol></section></blockquote><section><p>b</p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
81
- assert.deepStrictEqual(inspect(parser, input('!> - a', new Context())), [['<blockquote><section><ul><li>a</li></ul><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
81
+ assert.deepStrictEqual(inspect(parser, input('!> - a', new Context())), [['<blockquote><section><ul><li id="index:random:a" class="local">a</li></ul><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
82
82
  assert.deepStrictEqual(inspect(parser, input('!> ```\na\n```', new Context())), [['<blockquote><section><pre class="text">a</pre><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
83
83
  assert.deepStrictEqual(inspect(parser, input('!> ```\n> a\n```', new Context())), [['<blockquote><section><pre class="text">a</pre><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
84
84
  assert.deepStrictEqual(inspect(parser, input('!> ```\n> a\n> ```', new Context())), [['<blockquote><section><pre class="text">a</pre><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
@@ -91,10 +91,10 @@ describe('Unit: parser/block/blockquote', () => {
91
91
  assert.deepStrictEqual(inspect(parser, input('!>> > a\n> b', new Context())), [['<blockquote><blockquote><section><blockquote><pre>a</pre></blockquote><h2>References</h2><ol class="references"></ol></section></blockquote><section><p>b</p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
92
92
  assert.deepStrictEqual(inspect(parser, input('!> !> a', new Context())), [['<blockquote><section><blockquote><section><p>a</p><h2>References</h2><ol class="references"></ol></section></blockquote><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
93
93
  assert.deepStrictEqual(inspect(parser, input('!> \na', new Context())), [['<blockquote><section><p>a</p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
94
- assert.deepStrictEqual(inspect(parser, input('!>> ## a\n> ## a', new Context())), [['<blockquote><blockquote><section><h2>a</h2><h2>References</h2><ol class="references"></ol></section></blockquote><section><h2>a</h2><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
95
- assert.deepStrictEqual(inspect(parser, input('!>> ~ a\n> ~ a', new Context())), [['<blockquote><blockquote><section><dl><dt>a</dt><dd></dd></dl><h2>References</h2><ol class="references"></ol></section></blockquote><section><dl><dt>a</dt><dd></dd></dl><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
96
- assert.deepStrictEqual(inspect(parser, input('!>> ~~~figure $test-a\n>> > \n>>\n~~~\n> ~~~figure $test-a\n> > \n>\n[#a]\n~~~', new Context())), [['<blockquote><blockquote><section><figure data-type="quote" data-label="test-a" data-group="test" data-number="1"><figcaption><span class="figindex">Test 1. </span><span class="figtext"></span></figcaption><div><blockquote></blockquote></div></figure><h2>References</h2><ol class="references"></ol></section></blockquote><section><figure data-type="quote" data-label="test-a" data-group="test" data-number="1"><figcaption><span class="figindex">Test 1. </span><span class="figtext"><a class="index">a</a></span></figcaption><div><blockquote></blockquote></div></figure><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
97
- assert.deepStrictEqual(inspect(parser, input('!>> ((a))\n> ((a))', new Context())), [['<blockquote><blockquote><section><p><sup class="annotation disabled" title="a"><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1"><span>a</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote><section><p><sup class="annotation disabled" title="a"><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1"><span>a</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
94
+ assert.deepStrictEqual(inspect(parser, input('!>> ## a\n> ## a', new Context())), [['<blockquote><blockquote><section><h2 id="index:random:a" class="local">a</h2><h2>References</h2><ol class="references"></ol></section></blockquote><section><h2 id="index:random:a" class="local">a</h2><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
95
+ assert.deepStrictEqual(inspect(parser, input('!>> ~ a\n> ~ a', new Context())), [['<blockquote><blockquote><section><dl><dt id="index:random:a" class="local">a</dt><dd></dd></dl><h2>References</h2><ol class="references"></ol></section></blockquote><section><dl><dt id="index:random:a" class="local">a</dt><dd></dd></dl><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
96
+ assert.deepStrictEqual(inspect(parser, input('!>> ~~~figure $test-a\n>> > \n>>\n~~~\n> ~~~figure $test-a\n> > \n>\n[#a]\n~~~', new Context())), [['<blockquote><blockquote><section><figure data-type="quote" data-label="test-a" data-group="test" data-number="1" id="label:random:test-a"><figcaption><span class="figindex">Test 1. </span><span class="figtext"></span></figcaption><div><blockquote></blockquote></div></figure><h2>References</h2><ol class="references"></ol></section></blockquote><section><figure data-type="quote" data-label="test-a" data-group="test" data-number="1" id="label:random:test-a"><figcaption><span class="figindex">Test 1. </span><span class="figtext"><a class="index" href="#index:random:a">a</a></span></figcaption><div><blockquote></blockquote></div></figure><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
97
+ assert.deepStrictEqual(inspect(parser, input('!>> ((a))\n> ((a))', new Context())), [['<blockquote><blockquote><section><p><sup class="annotation local" id="annotation:random:ref:a:1" title="a"><a href="#annotation:random:def:a:1">*1</a></sup></p><ol class="annotations"><li id="annotation:random:def:a:1" data-marker="*1"><span>a</span><sup><a href="#annotation:random:ref:a:1">^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote><section><p><sup class="annotation local" id="annotation:random:ref:a:1" title="a"><a href="#annotation:random:def:a:1">*1</a></sup></p><ol class="annotations"><li id="annotation:random:def:a:1" data-marker="*1"><span>a</span><sup><a href="#annotation:random:ref:a:1">^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
98
98
  });
99
99
 
100
100
  });
@@ -4,7 +4,7 @@ import { List, Node } from '../../combinator/data/parser';
4
4
  import { union, some, consume, recursion, block, validate, rewrite, open, convert, lazy, fmap } from '../../combinator';
5
5
  import { autolink } from '../autolink';
6
6
  import { contentline } from '../source';
7
- import { unwrap } from '../util';
7
+ import { unwrap, randomID } from '../util';
8
8
  import { parse } from '../api/parse';
9
9
  import { html, defrag } from 'typed-dom/dom';
10
10
 
@@ -44,7 +44,8 @@ const markdown: BlockquoteParser.MarkdownParser = lazy(() => fmap(
44
44
  const { source } = context;
45
45
  const references = html('ol', { class: 'references' });
46
46
  const document = parse(source, {
47
- id: '',
47
+ local: true,
48
+ id: context.id === '' ? '' : randomID(),
48
49
  notes: {
49
50
  references,
50
51
  },