securemark 0.275.2 → 0.276.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.276.1
4
+
5
+ - Refactoring.
6
+
7
+ ## 0.276.0
8
+
9
+ - Change indexer syntax.
10
+
3
11
  ## 0.275.2
4
12
 
5
13
  - Fix identifiers.
package/README.md CHANGED
@@ -53,7 +53,7 @@ Secure markdown renderer working on browsers for user input data.
53
53
  - Shortmedia (!https://host/image.png, !https://youtu.be/...)
54
54
  - Syntex highlight (```lang filename)
55
55
  - LaTeX ($expr$, ${expr}$, $$)
56
- - Index (# title [#indexer], ~ term [#indexer], [#index])
56
+ - Index ([#index], # title [|signature], ~ term [|signature])
57
57
  - Figure (~~~figure $fig-name)
58
58
  - Label ($fig-name, [$fig-name])
59
59
  - Annotation (((annotation)))
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! securemark v0.275.2 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
1
+ /*! securemark v0.276.1 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"));
@@ -2782,14 +2782,14 @@ Object.defineProperty(exports, "__esModule", ({
2782
2782
  }));
2783
2783
  exports.convert = void 0;
2784
2784
  const parser_1 = __webpack_require__(6728);
2785
- function convert(conv, parser) {
2785
+ function convert(conv, parser, empty = false) {
2786
2786
  return ({
2787
2787
  source,
2788
2788
  context
2789
2789
  }) => {
2790
2790
  if (source === '') return;
2791
2791
  const src = conv(source, context);
2792
- if (src === '') return [[], ''];
2792
+ if (src === '') return empty ? [[], ''] : undefined;
2793
2793
  context.offset ??= 0;
2794
2794
  context.offset += source.length - src.length;
2795
2795
  const result = parser({
@@ -4365,8 +4365,8 @@ exports.blockquote = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, co
4365
4365
  const opener = /^(?=>>+(?:$|\s))/;
4366
4366
  const indent = (0, combinator_1.block)((0, combinator_1.open)(opener, (0, combinator_1.some)(source_1.contentline, /^>(?:$|\s)/)), false);
4367
4367
  const unindent = source => source.replace(/(?<=^|\n)>(?:[^\S\n]|(?=>*(?:$|\s)))|\n$/g, '');
4368
- const source = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, combinator_1.rewrite)(indent, (0, combinator_1.convert)(unindent, source)), (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, (0, combinator_1.fmap)(autolink_1.autolink, ns => [(0, dom_1.html)('pre', (0, dom_1.defrag)(ns))])))]))), ns => [(0, dom_1.html)('blockquote', ns)]));
4369
- const markdown = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, combinator_1.rewrite)(indent, (0, combinator_1.convert)(unindent, markdown)), (0, combinator_1.creation)(99, false, (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, ({
4368
+ const source = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, combinator_1.rewrite)(indent, (0, combinator_1.convert)(unindent, source, true)), (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, (0, combinator_1.fmap)(autolink_1.autolink, ns => [(0, dom_1.html)('pre', (0, dom_1.defrag)(ns))]), true))]))), ns => [(0, dom_1.html)('blockquote', ns)]));
4369
+ const markdown = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, combinator_1.rewrite)(indent, (0, combinator_1.convert)(unindent, markdown, true)), (0, combinator_1.creation)(99, false, (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, ({
4370
4370
  source,
4371
4371
  context
4372
4372
  }) => {
@@ -4380,7 +4380,7 @@ const markdown = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combina
4380
4380
  }
4381
4381
  }, context);
4382
4382
  return [[(0, dom_1.html)('section', [document, (0, dom_1.html)('h2', 'References'), references])], ''];
4383
- })))]))), ns => [(0, dom_1.html)('blockquote', ns)]));
4383
+ }, true)))]))), ns => [(0, dom_1.html)('blockquote', ns)]));
4384
4384
 
4385
4385
  /***/ }),
4386
4386
 
@@ -4949,8 +4949,8 @@ const row = (0, combinator_1.lazy)(() => (0, combinator_1.dup)((0, combinator_1.
4949
4949
  const alignment = /^[-=<>]+(?:\/[-=^v]*)?(?=[^\S\n]*\n)/;
4950
4950
  const align = (0, combinator_1.line)((0, combinator_1.fmap)((0, combinator_1.union)([(0, source_1.str)(alignment)]), ([s]) => s.split('/').map(s => s.split(''))));
4951
4951
  const delimiter = /^[-=<>]+(?:\/[-=^v]*)?(?=[^\S\n]*\n)|^[#:](?:(?!:\D|0)\d*:(?!0)\d*)?(?:!+[+]?)?(?=\s)/;
4952
- const head = (0, combinator_1.creation)(1, false, (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.open)((0, source_1.str)(/^#(?:(?!:\D|0)\d*:(?!0)\d*)?(?:!+[+]?)?(?=\s)/), (0, combinator_1.rewrite)((0, combinator_1.inits)([source_1.anyline, (0, combinator_1.some)(source_1.contentline, delimiter)]), (0, combinator_1.trim)((0, visibility_1.visualize)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]))))), true), ns => [(0, dom_1.html)('th', attributes(ns.shift()), (0, dom_1.defrag)(ns))]), false));
4953
- const data = (0, combinator_1.creation)(1, false, (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.open)((0, source_1.str)(/^:(?:(?!:\D|0)\d*:(?!0)\d*)?(?:!+[+]?)?(?=\s)/), (0, combinator_1.rewrite)((0, combinator_1.inits)([source_1.anyline, (0, combinator_1.some)(source_1.contentline, delimiter)]), (0, combinator_1.trim)((0, visibility_1.visualize)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]))))), true), ns => [(0, dom_1.html)('td', attributes(ns.shift()), (0, dom_1.defrag)(ns))]), false));
4952
+ const head = (0, combinator_1.creation)(1, false, (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.open)((0, source_1.str)(/^#(?:(?!:\D|0)\d*:(?!0)\d*)?(?:!+[+]?)?(?=\s)/), (0, combinator_1.rewrite)((0, combinator_1.inits)([source_1.anyline, (0, combinator_1.some)(source_1.contentline, delimiter)]), (0, combinator_1.open)(/^(?:\s*\n|\s)/, (0, visibility_1.visualize)((0, visibility_1.trimBlankStart)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline])))), true)), true), ns => [(0, dom_1.html)('th', attributes(ns.shift()), (0, visibility_1.trimNodeEnd)((0, dom_1.defrag)(ns)))]), false));
4953
+ const data = (0, combinator_1.creation)(1, false, (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.open)((0, source_1.str)(/^:(?:(?!:\D|0)\d*:(?!0)\d*)?(?:!+[+]?)?(?=\s)/), (0, combinator_1.rewrite)((0, combinator_1.inits)([source_1.anyline, (0, combinator_1.some)(source_1.contentline, delimiter)]), (0, combinator_1.open)(/^(?:\s*\n|\s)/, (0, visibility_1.visualize)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]))), true)), true), ns => [(0, dom_1.html)('td', attributes(ns.shift()), (0, visibility_1.trimNodeEnd)((0, dom_1.defrag)(ns)))]), false));
4954
4954
  const dataline = (0, combinator_1.creation)(1, false, (0, combinator_1.line)((0, combinator_1.rewrite)(source_1.contentline, (0, combinator_1.union)([(0, combinator_1.validate)(/^!+\s/, (0, combinator_1.convert)(source => `:${source}`, data)), (0, combinator_1.convert)(source => `: ${source}`, data)]))));
4955
4955
  function attributes(source) {
4956
4956
  let [, rowspan = undefined, colspan = undefined, highlight = undefined, extension = undefined] = source.match(/^[#:](?:(\d+)?:(\d+)?)?(?:(!+)([+]?))?$/) ?? [];
@@ -5263,7 +5263,6 @@ const index_1 = __webpack_require__(4479);
5263
5263
  const source_1 = __webpack_require__(6743);
5264
5264
  const visibility_1 = __webpack_require__(7618);
5265
5265
  const memoize_1 = __webpack_require__(1808);
5266
- const array_1 = __webpack_require__(8112);
5267
5266
  const dom_1 = __webpack_require__(3252);
5268
5267
  const openers = {
5269
5268
  '.': /^([0-9]+|[a-z]+|[A-Z]+)(?:-(?!-)[0-9]*)*(?![^\S\n])\.?(?:$|\s)/,
@@ -5271,12 +5270,12 @@ const openers = {
5271
5270
  };
5272
5271
  exports.olist = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.validate)(new RegExp([/^([0-9]+|[a-z]+|[A-Z]+)(?:-[0-9]+)*\.(?=[^\S\n]|\n[^\S\n]*\S)/.source, /^\(([0-9]+|[a-z]+)\)(?:-[0-9]+)*(?=[^\S\n]|\n[^\S\n]*\S)/.source].join('|')), (0, combinator_1.state)(8 /* State.media */, exports.olist_))));
5273
5272
  exports.olist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.union)([(0, combinator_1.match)(openers['.'], (0, memoize_1.memoize)(ms => list(type(ms[1]), '.'), ms => idx(ms[1]), [])), (0, combinator_1.match)(openers['('], (0, memoize_1.memoize)(ms => list(type(ms[1]), '('), ms => idx(ms[1]), []))])));
5274
- const list = (type, form) => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(heads[form], (0, combinator_1.subsequence)([ulist_1.checkbox, (0, combinator_1.union)([(0, combinator_1.trim)((0, combinator_1.fmap)((0, combinator_1.close)((0, combinator_1.union)([index_1.index]), /^$/), ([el]) => [(0, dom_1.define)(el, {
5273
+ const list = (type, form) => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(heads[form], (0, combinator_1.subsequence)([ulist_1.checkbox, (0, combinator_1.trim)((0, combinator_1.union)([(0, combinator_1.fmap)((0, combinator_1.close)((0, combinator_1.union)([index_1.index]), /^$/), ([el]) => [(0, dom_1.define)(el, {
5275
5274
  class: void el.classList.add('indexer'),
5276
5275
  'data-index': ''
5277
- })])), (0, visibility_1.trimBlank)((0, visibility_1.visualize)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline]))))])]), true)), (0, combinator_1.indent)((0, combinator_1.union)([ulist_1.ulist_, exports.olist_, ilist_1.ilist_]))]), exports.invalid), ns => [(0, dom_1.html)('li', {
5278
- 'data-marker': ns[0] || undefined
5279
- }, (0, dom_1.defrag)((0, ulist_1.fillFirstLine)((0, array_1.shift)(ns)[1])))]), true)]))), es => [format((0, dom_1.html)('ol', es), type, form)]);
5276
+ })]), (0, visibility_1.visualize)((0, visibility_1.trimBlank)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline]))))]))]), true)), (0, combinator_1.indent)((0, combinator_1.union)([ulist_1.ulist_, exports.olist_, ilist_1.ilist_]))]), exports.invalid), ns => [(0, dom_1.html)('li', {
5277
+ 'data-marker': ns.shift() || undefined
5278
+ }, (0, dom_1.defrag)((0, ulist_1.fillFirstLine)(ns)))]), true)]))), es => [format((0, dom_1.html)('ol', es), type, form)]);
5280
5279
  const heads = {
5281
5280
  '.': (0, combinator_1.focus)(openers['.'], ({
5282
5281
  source
@@ -5572,7 +5571,7 @@ exports.sidefence = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, com
5572
5571
  })])));
5573
5572
  const opener = /^(?=\|\|+(?:$|\s))/;
5574
5573
  const unindent = source => source.replace(/(?<=^|\n)\|(?:[^\S\n]|(?=\|*(?:$|\s)))|\n$/g, '');
5575
- const source = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, combinator_1.focus)(/^(?:\|\|+(?:[^\S\n][^\n]*)?(?:$|\n))+/, (0, combinator_1.convert)(unindent, source)), (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, (0, combinator_1.fmap)(autolink_1.autolink, ns => [(0, dom_1.html)('pre', (0, dom_1.defrag)(ns))])))]))), ns => [(0, dom_1.html)('blockquote', ns)]));
5574
+ const source = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, combinator_1.focus)(/^(?:\|\|+(?:[^\S\n][^\n]*)?(?:$|\n))+/, (0, combinator_1.convert)(unindent, source, true)), (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, (0, combinator_1.fmap)(autolink_1.autolink, ns => [(0, dom_1.html)('pre', (0, dom_1.defrag)(ns))]), true))]))), ns => [(0, dom_1.html)('blockquote', ns)]));
5576
5575
 
5577
5576
  /***/ }),
5578
5577
 
@@ -5603,9 +5602,9 @@ const row = (parser, optional) => (0, combinator_1.creation)(1, false, (0, combi
5603
5602
  'data-invalid-message': 'Missing the start symbol of the table row'
5604
5603
  }, [(0, dom_1.html)('td', source.replace('\n', ''))])], ''])));
5605
5604
  const align = (0, combinator_1.creation)(1, false, (0, combinator_1.fmap)((0, combinator_1.open)('|', (0, combinator_1.union)([(0, combinator_1.focus)(/^:-+:/, () => [['center'], '']), (0, combinator_1.focus)(/^:-+/, () => [['start'], '']), (0, combinator_1.focus)(/^-+:/, () => [['end'], '']), (0, combinator_1.focus)(/^-+/, () => [[''], ''])])), ns => [(0, dom_1.html)('td', (0, dom_1.defrag)(ns))]));
5606
- const cell = (0, combinator_1.surround)(/^\|\s*(?=\S)/, (0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), /^\|/, [[/^[|\\]?\s*$/, 9]]), /^[^|]*/, true);
5607
- const head = (0, combinator_1.creation)(1, false, (0, combinator_1.fmap)(cell, ns => [(0, dom_1.html)('th', (0, visibility_1.trimNode)((0, dom_1.defrag)(ns)))]));
5608
- const data = (0, combinator_1.creation)(1, false, (0, combinator_1.fmap)(cell, ns => [(0, dom_1.html)('td', (0, visibility_1.trimNode)((0, dom_1.defrag)(ns)))]));
5605
+ const cell = (0, combinator_1.surround)(/^\|\s*(?=\S)/, (0, visibility_1.trimBlankStart)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), /^\|/, [[/^[|\\]?\s*$/, 9]])), /^[^|]*/, true);
5606
+ const head = (0, combinator_1.creation)(1, false, (0, combinator_1.fmap)(cell, ns => [(0, dom_1.html)('th', (0, visibility_1.trimNodeEnd)((0, dom_1.defrag)(ns)))]));
5607
+ const data = (0, combinator_1.creation)(1, false, (0, combinator_1.fmap)(cell, ns => [(0, dom_1.html)('td', (0, visibility_1.trimNodeEnd)((0, dom_1.defrag)(ns)))]));
5609
5608
  function format(rows) {
5610
5609
  const aligns = rows[0].className === 'invalid' ? [] : (0, duff_1.duffReduce)(rows.shift().children, (acc, el) => (0, array_1.push)(acc, [el.textContent]), []);
5611
5610
  for (let i = 0; i < rows.length; ++i) {
@@ -5641,10 +5640,10 @@ const visibility_1 = __webpack_require__(7618);
5641
5640
  const array_1 = __webpack_require__(8112);
5642
5641
  const dom_1 = __webpack_require__(3252);
5643
5642
  exports.ulist = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.validate)(/^-(?=[^\S\n]|\n[^\S\n]*\S)/, (0, combinator_1.state)(8 /* State.media */, exports.ulist_))));
5644
- exports.ulist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)(/^-(?=$|\s)/, (0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(/^-(?:$|\s)/, (0, combinator_1.subsequence)([exports.checkbox, (0, combinator_1.union)([(0, combinator_1.trim)((0, combinator_1.fmap)((0, combinator_1.close)((0, combinator_1.union)([index_1.index]), /^$/), ([el]) => [(0, dom_1.define)(el, {
5643
+ exports.ulist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)(/^-(?=$|\s)/, (0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(/^-(?:$|\s)/, (0, combinator_1.subsequence)([exports.checkbox, (0, combinator_1.trim)((0, combinator_1.union)([(0, combinator_1.fmap)((0, combinator_1.close)((0, combinator_1.union)([index_1.index]), /^$/), ([el]) => [(0, dom_1.define)(el, {
5645
5644
  class: void el.classList.add('indexer'),
5646
5645
  'data-index': ''
5647
- })])), (0, visibility_1.trimBlank)((0, visibility_1.visualize)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline]))))])]), true)), (0, combinator_1.indent)((0, combinator_1.union)([exports.ulist_, olist_1.olist_, ilist_1.ilist_]))]), olist_1.invalid), ns => [(0, dom_1.html)('li', (0, dom_1.defrag)(fillFirstLine(ns)))]), true)])))), es => [format((0, dom_1.html)('ul', es))])));
5646
+ })]), (0, visibility_1.visualize)((0, visibility_1.trimBlank)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline]))))]))]), true)), (0, combinator_1.indent)((0, combinator_1.union)([exports.ulist_, olist_1.olist_, ilist_1.ilist_]))]), olist_1.invalid), ns => [(0, dom_1.html)('li', (0, dom_1.defrag)(fillFirstLine(ns)))]), true)])))), es => [format((0, dom_1.html)('ul', es))])));
5648
5647
  exports.checkbox = (0, combinator_1.creation)(1, false, (0, combinator_1.focus)(/^\[[xX ]\](?=$|\s)/, ({
5649
5648
  source
5650
5649
  }) => [[(0, dom_1.html)('span', {
@@ -5790,9 +5789,9 @@ const combinator_1 = __webpack_require__(2087);
5790
5789
  const inline_1 = __webpack_require__(1160);
5791
5790
  const visibility_1 = __webpack_require__(7618);
5792
5791
  const dom_1 = __webpack_require__(3252);
5793
- exports.annotation = (0, combinator_1.lazy)(() => (0, combinator_1.surround)('((', (0, combinator_1.constraint)(256 /* State.annotation */, false, (0, combinator_1.syntax)(0 /* Syntax.none */, 6, 1, 256 /* State.annotation */ | 8 /* State.media */, (0, visibility_1.startLoose)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), ')', [[/^\\?\n/, 9], [')', 2], ['))', 6]]), ')'))), '))', false, ([, ns], rest) => [[(0, dom_1.html)('sup', {
5792
+ exports.annotation = (0, combinator_1.lazy)(() => (0, combinator_1.surround)('((', (0, combinator_1.constraint)(256 /* State.annotation */, false, (0, combinator_1.syntax)(0 /* Syntax.none */, 6, 1, 256 /* State.annotation */ | 8 /* State.media */, (0, visibility_1.trimBlankStart)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), ')', [[/^\\?\n/, 9], [')', 2], ['))', 6]])))), '))', false, ([, ns], rest) => [[(0, dom_1.html)('sup', {
5794
5793
  class: 'annotation'
5795
- }, [(0, dom_1.html)('span', (0, visibility_1.trimNode)((0, dom_1.defrag)(ns)))])], rest]));
5794
+ }, [(0, dom_1.html)('span', (0, visibility_1.trimNodeEnd)((0, dom_1.defrag)(ns)))])], rest]));
5796
5795
 
5797
5796
  /***/ }),
5798
5797
 
@@ -6140,19 +6139,19 @@ exports.extension = (0, combinator_1.validate)(['[', '$'], (0, combinator_1.unio
6140
6139
  Object.defineProperty(exports, "__esModule", ({
6141
6140
  value: true
6142
6141
  }));
6143
- exports.index = void 0;
6142
+ exports.signature = exports.index = void 0;
6144
6143
  const combinator_1 = __webpack_require__(2087);
6145
6144
  const inline_1 = __webpack_require__(1160);
6146
6145
  const indexee_1 = __webpack_require__(1269);
6147
6146
  const source_1 = __webpack_require__(6743);
6148
6147
  const visibility_1 = __webpack_require__(7618);
6149
6148
  const dom_1 = __webpack_require__(3252);
6150
- exports.index = (0, combinator_1.lazy)(() => (0, combinator_1.validate)('[#', (0, combinator_1.fmap)((0, indexee_1.indexee)((0, combinator_1.surround)('[#', (0, combinator_1.constraint)(64 /* State.index */, false, (0, combinator_1.syntax)(128 /* Syntax.index */, 2, 1, 502 /* State.linkers */ | 8 /* State.media */, (0, visibility_1.startTight)((0, combinator_1.open)((0, source_1.stropt)('|'), (0, combinator_1.some)((0, combinator_1.union)([signature, inline_1.inline]), ']', [[/^\\?\n/, 9], [']', 2]]), true)))), ']', false, ([, ns], rest) => [[(0, dom_1.html)('a', (0, visibility_1.trimNodeEnd)((0, dom_1.defrag)(ns)))], rest])), ([el]) => [(0, dom_1.define)(el, {
6149
+ exports.index = (0, combinator_1.lazy)(() => (0, combinator_1.validate)('[#', (0, combinator_1.fmap)((0, indexee_1.indexee)((0, combinator_1.surround)('[#', (0, combinator_1.constraint)(64 /* State.index */, false, (0, combinator_1.syntax)(128 /* Syntax.index */, 2, 1, 502 /* State.linkers */ | 8 /* State.media */, (0, visibility_1.startTight)((0, combinator_1.open)((0, source_1.stropt)('|'), (0, combinator_1.some)((0, combinator_1.union)([exports.signature, inline_1.inline]), ']', [[/^\\?\n/, 9], [']', 2]]), true)))), ']', false, ([, ns], rest) => [[(0, dom_1.html)('a', (0, visibility_1.trimNodeEnd)((0, dom_1.defrag)(ns)))], rest])), ([el]) => [(0, dom_1.define)(el, {
6151
6150
  id: el.id ? null : undefined,
6152
6151
  class: 'index',
6153
6152
  href: el.id ? `#${el.id}` : undefined
6154
6153
  })])));
6155
- const signature = (0, combinator_1.lazy)(() => (0, combinator_1.creation)((0, combinator_1.fmap)((0, combinator_1.open)('|', (0, visibility_1.startTight)((0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.txt]), ']'))), ns => [(0, dom_1.html)('span', {
6154
+ exports.signature = (0, combinator_1.lazy)(() => (0, combinator_1.creation)((0, combinator_1.fmap)((0, combinator_1.open)('|', (0, visibility_1.startTight)((0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.txt]), ']'))), ns => [(0, dom_1.html)('span', {
6156
6155
  class: 'indexer',
6157
6156
  'data-index': (0, indexee_1.identity)(undefined, ns.join('')).slice(7)
6158
6157
  })])));
@@ -6285,14 +6284,10 @@ exports.indexer = void 0;
6285
6284
  const combinator_1 = __webpack_require__(2087);
6286
6285
  const index_1 = __webpack_require__(4479);
6287
6286
  const dom_1 = __webpack_require__(3252);
6288
- exports.indexer = (0, combinator_1.creation)((0, combinator_1.fmap)((0, combinator_1.verify)((0, combinator_1.surround)(/^\s+(?=\[#\S)/, (0, combinator_1.state)(64 /* State.index */, false, (0, combinator_1.union)([(0, combinator_1.focus)('[#]', () => [[(0, dom_1.html)('a', {
6289
- href: '#'
6290
- })], '']), index_1.index])), /^\s*$/),
6291
- // Indexer is invisible but invalids must be visible.
6292
- ([el]) => el.getElementsByClassName('invalid').length === 0), ([el]) => [(0, dom_1.html)('span', {
6287
+ exports.indexer = (0, combinator_1.surround)(/^\s+\[(?=\|\S)/, (0, combinator_1.state)(64 /* State.index */, false, (0, combinator_1.union)([index_1.signature, (0, combinator_1.creation)((0, combinator_1.focus)(/^\|(?=\])/, () => [[(0, dom_1.html)('span', {
6293
6288
  class: 'indexer',
6294
- 'data-index': el.getAttribute('href').slice(1).replace(/^[^:]*:[^:]*:/, '')
6295
- })]));
6289
+ 'data-index': ''
6290
+ })], '']))])), /^\]\s*$/);
6296
6291
 
6297
6292
  /***/ }),
6298
6293
 
@@ -6394,7 +6389,7 @@ exports.html = (0, combinator_1.lazy)(() => (0, combinator_1.validate)('<', (0,
6394
6389
  exports.attribute = (0, combinator_1.union)([(0, source_1.str)(/^[^\S\n]+[a-z]+(?:-[a-z]+)*(?:="[^"\n]*")?(?=[^\S\n]|>)/i)]);
6395
6390
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
6396
6391
  // [...document.querySelectorAll('tbody > tr > td:first-child')].map(el => el.textContent.slice(1, -1))
6397
- const TAGS = 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"]);
6392
+ const TAGS = Object.freeze(["html", "base", "head", "link", "meta", "style", "title", "body", "address", "article", "aside", "footer", "header", "h1", "h2", "h3", "h4", "h5", "h6", "hgroup", "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", "bgsound", "big", "blink", "center", "content", "dir", "font", "frame", "frameset", "image", "keygen", "marquee", "menuitem", "nobr", "noembed", "noframes", "param", "plaintext", "rb", "rtc", "shadow", "spacer", "strike", "tt", "xmp"]);
6398
6393
  function elem(tag, as, bs, cs) {
6399
6394
  if (!tags.includes(tag)) return invalid('tag', `Invalid HTML tag name "${tag}"`, as, bs, cs);
6400
6395
  if (cs.length === 0) return invalid('tag', `Missing the closing HTML tag "</${tag}>"`, as, bs, cs);
@@ -6769,9 +6764,9 @@ const inline_1 = __webpack_require__(1160);
6769
6764
  const source_1 = __webpack_require__(6743);
6770
6765
  const visibility_1 = __webpack_require__(7618);
6771
6766
  const dom_1 = __webpack_require__(3252);
6772
- exports.reference = (0, combinator_1.lazy)(() => (0, combinator_1.surround)('[[', (0, combinator_1.constraint)(128 /* State.reference */, false, (0, combinator_1.syntax)(256 /* Syntax.reference */, 6, 1, 256 /* State.annotation */ | 128 /* State.reference */ | 8 /* State.media */, (0, visibility_1.startLoose)((0, combinator_1.subsequence)([abbr, (0, combinator_1.fmap)((0, source_1.str)('^'), ns => ['', ...ns]), (0, combinator_1.some)(inline_1.inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]])]), ']'))), ']]', false, ([, ns], rest) => [[(0, dom_1.html)('sup', attributes(ns), [(0, dom_1.html)('span', (0, visibility_1.trimNode)((0, dom_1.defrag)(ns)))])], rest]));
6767
+ exports.reference = (0, combinator_1.lazy)(() => (0, combinator_1.surround)('[[', (0, combinator_1.constraint)(128 /* State.reference */, false, (0, combinator_1.syntax)(256 /* Syntax.reference */, 6, 1, 256 /* State.annotation */ | 128 /* State.reference */ | 8 /* State.media */, (0, combinator_1.subsequence)([abbr, (0, visibility_1.trimBlankStart)((0, combinator_1.some)(inline_1.inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]]))]))), ']]', false, ([, ns], rest) => [[(0, dom_1.html)('sup', attributes(ns), [(0, dom_1.html)('span', (0, visibility_1.trimNodeEnd)((0, dom_1.defrag)(ns)))])], rest]));
6773
6768
  // Chicago-Style
6774
- const abbr = (0, combinator_1.creation)((0, combinator_1.bind)((0, combinator_1.surround)('^', (0, combinator_1.union)([(0, source_1.str)(/^(?=[A-Z])(?:[0-9A-Za-z]'?|(?:[-.:]|\.?\??,? ?)(?!['\-.:?, ]))+/)]), /^\|?(?=]])|^\|[^\S\n]*/), ([source], rest) => [['\n', source.trimEnd()], rest.replace(visibility_1.regBlankStart, '')]));
6769
+ const abbr = (0, combinator_1.creation)((0, combinator_1.surround)('^', (0, combinator_1.union)([(0, source_1.str)(/^(?=[A-Z])(?:[0-9A-Za-z]'?|(?:[-.:]|\.?\??,? ?)(?!['\-.:?, ]))+/)]), /^\|?(?=]])|^\|[^\S\n]*/, true, ([, ns], rest) => ns ? [['\n', ns[0].trimEnd()], rest.replace(visibility_1.blank.start, '')] : [[''], `^${rest}`], ([,, rest]) => [[''], `^${rest}`]));
6775
6770
  function attributes(ns) {
6776
6771
  switch (ns[0]) {
6777
6772
  case '':
@@ -7634,7 +7629,7 @@ exports.stringify = stringify;
7634
7629
  Object.defineProperty(exports, "__esModule", ({
7635
7630
  value: true
7636
7631
  }));
7637
- exports.trimNodeEnd = exports.trimNode = exports.trimBlankStart = exports.trimBlank = exports.isStartTightNodes = exports.isStartLooseNodes = exports.startTight = exports.startLoose = exports.blankWith = exports.regBlankStart = exports.visualize = void 0;
7632
+ exports.trimNodeEnd = exports.trimNode = exports.trimBlankStart = exports.trimBlank = exports.isStartTightNodes = exports.isStartLooseNodes = exports.startTight = exports.blankWith = exports.visualize = exports.blank = void 0;
7638
7633
  const parser_1 = __webpack_require__(6728);
7639
7634
  const combinator_1 = __webpack_require__(2087);
7640
7635
  const htmlentity_1 = __webpack_require__(1562);
@@ -7642,9 +7637,13 @@ const source_1 = __webpack_require__(6743);
7642
7637
  const normalize_1 = __webpack_require__(185);
7643
7638
  const memoize_1 = __webpack_require__(1808);
7644
7639
  const array_1 = __webpack_require__(8112);
7640
+ var blank;
7641
+ (function (blank) {
7642
+ blank.line = new RegExp(/^(?:\\?[^\S\n]|&IHN;|<wbr[^\S\n]*>|\\$)+$/.source.replace('IHN', `(?:${normalize_1.invisibleHTMLEntityNames.join('|')})`), 'gm');
7643
+ blank.start = new RegExp(/^(?:\\?[^\S\n]|&IHN;|<wbr[^\S\n]*>)+/.source.replace('IHN', `(?:${normalize_1.invisibleHTMLEntityNames.join('|')})`));
7644
+ })(blank = exports.blank || (exports.blank = {}));
7645
7645
  function visualize(parser) {
7646
- const blankline = new RegExp(/^(?:\\$|\\?[^\S\n]|&IHN;|<wbr[^\S\n]*>)+$/.source.replace('IHN', `(?:${normalize_1.invisibleHTMLEntityNames.join('|')})`), 'gm');
7647
- return (0, combinator_1.union)([(0, combinator_1.convert)(source => source.replace(blankline, line => line.replace(/[\\&<]/g, '\x1B$&')), (0, combinator_1.verify)(parser, (ns, rest, context) => !rest && hasVisible(ns, context))), (0, combinator_1.some)((0, combinator_1.union)([source_1.linebreak, source_1.unescsource]))]);
7646
+ return (0, combinator_1.union)([(0, combinator_1.convert)(source => source.replace(blank.line, line => line.replace(/[\\&<]/g, '\x1B$&')), (0, combinator_1.verify)(parser, (ns, rest, context) => !rest && hasVisible(ns, context))), (0, combinator_1.some)((0, combinator_1.union)([source_1.linebreak, source_1.unescsource]))]);
7648
7647
  }
7649
7648
  exports.visualize = visualize;
7650
7649
  function hasVisible(nodes, {
@@ -7661,27 +7660,11 @@ function hasVisible(nodes, {
7661
7660
  }
7662
7661
  return false;
7663
7662
  }
7664
- exports.regBlankStart = new RegExp(/^(?:\\?[^\S\n]|&IHN;|<wbr[^\S\n]*>)+/.source.replace('IHN', `(?:${normalize_1.invisibleHTMLEntityNames.join('|')})`));
7665
7663
  function blankWith(starting, delimiter) {
7666
7664
  if (delimiter === undefined) return blankWith('', starting);
7667
7665
  return new RegExp(String.raw`^(?:(?=${starting})(?:\\?\s|&(?:${normalize_1.invisibleHTMLEntityNames.join('|')});|<wbr[^\S\n]*>)${starting && '+'})?${typeof delimiter === 'string' ? delimiter.replace(/[*+()\[\]]/g, '\\$&') : delimiter.source}`);
7668
7666
  }
7669
7667
  exports.blankWith = blankWith;
7670
- function startLoose(parser, except) {
7671
- return input => isStartLoose(input, except) ? parser(input) : undefined;
7672
- }
7673
- exports.startLoose = startLoose;
7674
- const isStartLoose = (0, memoize_1.reduce)(({
7675
- source,
7676
- context
7677
- }, except) => {
7678
- return isStartTight({
7679
- source: source.replace(exports.regBlankStart, ''),
7680
- context
7681
- }, except);
7682
- }, ({
7683
- source
7684
- }, except = '') => `${source}\x1E${except}`);
7685
7668
  function startTight(parser, except) {
7686
7669
  return input => isStartTight(input, except) ? parser(input) : undefined;
7687
7670
  }
@@ -7768,7 +7751,7 @@ function trimBlank(parser) {
7768
7751
  }
7769
7752
  exports.trimBlank = trimBlank;
7770
7753
  function trimBlankStart(parser) {
7771
- return (0, combinator_1.convert)((0, memoize_1.reduce)(source => source.replace(exports.regBlankStart, '')), parser);
7754
+ return (0, combinator_1.convert)(source => source.replace(blank.start, ''), parser);
7772
7755
  }
7773
7756
  exports.trimBlankStart = trimBlankStart;
7774
7757
  function trimBlankEnd(parser) {
package/markdown.d.ts CHANGED
@@ -673,7 +673,6 @@ export namespace MarkdownParser {
673
673
  Inline<'reference'>,
674
674
  Parser<HTMLElement, Context, [
675
675
  ReferenceParser.AbbrParser,
676
- SourceParser.StrParser,
677
676
  InlineParser,
678
677
  ]> {
679
678
  }
@@ -744,7 +743,6 @@ export namespace MarkdownParser {
744
743
  }
745
744
  }
746
745
  export interface ExtensionParser extends
747
- // [#abc]
748
746
  Inline<'extension'>,
749
747
  Parser<HTMLElement | string, Context, [
750
748
  ExtensionParser.IndexParser,
@@ -755,6 +753,7 @@ export namespace MarkdownParser {
755
753
  export namespace ExtensionParser {
756
754
  export interface IndexParser extends
757
755
  // [#index]
756
+ // [#index|signature]
758
757
  Inline<'extension/index'>,
759
758
  Parser<HTMLAnchorElement, Context, [
760
759
  IndexParser.SignatureParser,
@@ -791,12 +790,12 @@ export namespace MarkdownParser {
791
790
  }
792
791
  }
793
792
  export interface IndexerParser extends
794
- // [#index]
795
- // [#]
793
+ // [|signature]
794
+ // [|]
796
795
  Inline<'extension/indexer'>,
797
796
  Parser<HTMLElement, Context, [
798
- Parser<HTMLAnchorElement, Context, []>,
799
- IndexParser,
797
+ IndexParser.SignatureParser,
798
+ Parser<HTMLSpanElement, Context, []>,
800
799
  ]> {
801
800
  }
802
801
  export interface LabelParser extends
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.275.2",
3
+ "version": "0.276.1",
4
4
  "description": "Secure markdown renderer working on browsers for user input data.",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/falsandtru/securemark",
@@ -1,12 +1,12 @@
1
1
  import { Parser, Ctx, Context, check } from '../../data/parser';
2
2
 
3
- export function convert<P extends Parser<unknown>>(conv: (source: string, context: Context<P>) => string, parser: P): P;
4
- export function convert<T>(conv: (source: string, context: Ctx) => string, parser: Parser<T>): Parser<T> {
3
+ export function convert<P extends Parser<unknown>>(conv: (source: string, context: Context<P>) => string, parser: P, empty?: boolean): P;
4
+ export function convert<T>(conv: (source: string, context: Ctx) => string, parser: Parser<T>, empty = false): Parser<T> {
5
5
  assert(parser);
6
6
  return ({ source, context }) => {
7
7
  if (source === '') return;
8
8
  const src = conv(source, context);
9
- if (src === '') return [[], ''];
9
+ if (src === '') return empty ? [[], ''] : undefined;
10
10
  context.offset ??= 0;
11
11
  context.offset += source.length - src.length;
12
12
  const result = parser({ source: src, context });
@@ -25,8 +25,8 @@ export function context<T>(base: Ctx, parser: Parser<T>): Parser<T> {
25
25
  apply(parser, source, context, changes, values);
26
26
  }
27
27
 
28
- function apply<P extends Parser<unknown>>(parser: P, source: string, context: Context<P>, changes: [string, any][], values: any[], reset?: boolean): Result<Tree<P>>;
29
- function apply<T>(parser: Parser<T>, source: string, context: Ctx, changes: [string, any][], values: any[], reset = false): Result<T> {
28
+ function apply<P extends Parser<unknown>>(parser: P, source: string, context: Context<P>, changes: readonly [string, unknown][], values: unknown[], reset?: boolean): Result<Tree<P>>;
29
+ function apply<T>(parser: Parser<T>, source: string, context: Ctx, changes: readonly [string, unknown][], values: unknown[], reset = false): Result<T> {
30
30
  if (context) for (let i = 0; i < changes.length; ++i) {
31
31
  const change = changes[i];
32
32
  const prop = change[0];
@@ -36,7 +36,7 @@ function apply<T>(parser: Parser<T>, source: string, context: Ctx, changes: [str
36
36
  assert(typeof change[1] === 'object');
37
37
  assert(context[prop] || !(prop in context));
38
38
  if (prop in context && !hasOwnProperty(context, prop)) break;
39
- context[prop as string] = ObjectCreate(change[1]);
39
+ context[prop as string] = ObjectCreate(change[1] as object);
40
40
  break;
41
41
  // @ts-expect-error
42
42
  case 'memo':
@@ -12,7 +12,7 @@ export function inits<T, D extends Parser<T>[]>(parsers: D, resume?: (nodes: T[]
12
12
  if (rest === '') break;
13
13
  if (context.delimiters?.match(rest, context.precedence)) break;
14
14
  const result = parsers[i]({ source: rest, context });
15
- assert(check(rest, result));
15
+ assert(check(rest, result, false));
16
16
  if (result === undefined) break;
17
17
  nodes = nodes
18
18
  ? push(nodes, eval(result))
@@ -12,7 +12,7 @@ export function sequence<T, D extends Parser<T>[]>(parsers: D, resume?: (nodes:
12
12
  if (rest === '') return;
13
13
  if (context.delimiters?.match(rest, context.precedence)) return;
14
14
  const result = parsers[i]({ source: rest, context });
15
- assert(check(rest, result));
15
+ assert(check(rest, result, false));
16
16
  if (result === undefined) return;
17
17
  nodes = nodes
18
18
  ? push(nodes, eval(result))
@@ -22,10 +22,10 @@ const source: BlockquoteParser.SourceParser = lazy(() => fmap(
22
22
  some(creation(1, false, union([
23
23
  rewrite(
24
24
  indent,
25
- convert(unindent, source)),
25
+ convert(unindent, source, true)),
26
26
  rewrite(
27
27
  some(contentline, opener),
28
- convert(unindent, fmap(autolink, ns => [html('pre', defrag(ns))]))),
28
+ convert(unindent, fmap(autolink, ns => [html('pre', defrag(ns))]), true)),
29
29
  ]))),
30
30
  ns => [html('blockquote', ns)]));
31
31
 
@@ -33,7 +33,7 @@ const markdown: BlockquoteParser.MarkdownParser = lazy(() => fmap(
33
33
  some(creation(1, false, union([
34
34
  rewrite(
35
35
  indent,
36
- convert(unindent, markdown)),
36
+ convert(unindent, markdown, true)),
37
37
  creation(99, false,
38
38
  rewrite(
39
39
  some(contentline, opener),
@@ -46,6 +46,6 @@ const markdown: BlockquoteParser.MarkdownParser = lazy(() => fmap(
46
46
  },
47
47
  }, context);
48
48
  return [[html('section', [document, html('h2', 'References'), references])], ''];
49
- }))),
49
+ }, true))),
50
50
  ]))),
51
51
  ns => [html('blockquote', ns)]));
@@ -65,8 +65,8 @@ describe('Unit: parser/block/dlist', () => {
65
65
  });
66
66
 
67
67
  it('index', () => {
68
- assert.deepStrictEqual(inspect(parser('~ a [#b]')), [['<dl><dt id="index::b">a<span class="indexer" data-index="b"></span></dt><dd></dd></dl>'], '']);
69
- assert.deepStrictEqual(inspect(parser('~ a [#b]\\')), [['<dl><dt id="index::a_[#b]">a [<a class="hashtag" href="/hashtags/b">#b</a>]</dt><dd></dd></dl>'], '']);
68
+ assert.deepStrictEqual(inspect(parser('~ a [|b]')), [['<dl><dt id="index::b">a<span class="indexer" data-index="b"></span></dt><dd></dd></dl>'], '']);
69
+ assert.deepStrictEqual(inspect(parser('~ a [|b]\\')), [['<dl><dt id="index::a_b">a <span class="invalid">b</span></dt><dd></dd></dl>'], '']);
70
70
  assert.deepStrictEqual(inspect(parser('~ A')), [['<dl><dt id="index::A">A</dt><dd></dd></dl>'], '']);
71
71
  assert.deepStrictEqual(inspect(parser('~ _A_')), [['<dl><dt id="index::A"><em>A</em></dt><dd></dd></dl>'], '']);
72
72
  assert.deepStrictEqual(inspect(parser('~ `A`')), [['<dl><dt id="index::`A`"><code data-src="`A`">A</code></dt><dd></dd></dl>'], '']);
@@ -95,6 +95,42 @@ describe('Unit: parser/block/extension/table', () => {
95
95
  ]),
96
96
  html('tfoot'),
97
97
  ]).outerHTML], '']);
98
+ assert.deepStrictEqual(
99
+ inspect(parser('~~~table\n:\n1\n~~~')),
100
+ [[html('table', [
101
+ html('thead'),
102
+ html('tbody', [
103
+ html('tr', [html('td', '1')]),
104
+ ]),
105
+ html('tfoot'),
106
+ ]).outerHTML], '']);
107
+ assert.deepStrictEqual(
108
+ inspect(parser('~~~table\n: \n1\n~~~')),
109
+ [[html('table', [
110
+ html('thead'),
111
+ html('tbody', [
112
+ html('tr', [html('td', '1')]),
113
+ ]),
114
+ html('tfoot'),
115
+ ]).outerHTML], '']);
116
+ assert.deepStrictEqual(
117
+ inspect(parser('~~~table\n: \n 1\n~~~')),
118
+ [[html('table', [
119
+ html('thead'),
120
+ html('tbody', [
121
+ html('tr', [html('td', ' 1')]),
122
+ ]),
123
+ html('tfoot'),
124
+ ]).outerHTML], '']);
125
+ assert.deepStrictEqual(
126
+ inspect(parser('~~~table\n: \n\n1\n~~~')),
127
+ [[html('table', [
128
+ html('thead'),
129
+ html('tbody', [
130
+ html('tr', [html('td'), html('td', '1')]),
131
+ ]),
132
+ html('tfoot'),
133
+ ]).outerHTML], '']);
98
134
  assert.deepStrictEqual(
99
135
  inspect(parser('~~~table\n\\ \n\\ \n~~~')),
100
136
  [[html('table', [
@@ -491,7 +527,7 @@ describe('Unit: parser/block/extension/table', () => {
491
527
  assert.deepStrictEqual(
492
528
  inspect(parser([
493
529
  '~~~table',
494
- `-\n# 1\n${[...Array(32)].map((_, i) => `: ${i + 2}`).join('\n')}`,
530
+ `-\n# 1\n${[...Array(32)].map((_, i) => `: ${i + 2}`).join('\n')}`,
495
531
  `-\n#!+ 1\n${[...Array(32)].map((_, i) => `: ${i + 2}`).join('\n')}`,
496
532
  '~~~'
497
533
  ].join('\n'))),
@@ -511,7 +547,7 @@ describe('Unit: parser/block/extension/table', () => {
511
547
  assert.deepStrictEqual(
512
548
  inspect(parser([
513
549
  '~~~table',
514
- `-\n${[...Array(32)].map((_, i) => `: ${i + 1}`).join('\n')}\n# 33`,
550
+ `-\n${[...Array(32)].map((_, i) => `: ${i + 1}`).join('\n')}\n# 33`,
515
551
  `-\n${[...Array(32)].map((_, i) => `: ${i + 1}`).join('\n')}\n#!+ 33`,
516
552
  '~~~'
517
553
  ].join('\n'))),
@@ -1,10 +1,10 @@
1
1
  import { max, min, isArray } from 'spica/alias';
2
2
  import { ExtensionParser } from '../../block';
3
3
  import { Tree, eval } from '../../../combinator/data/parser';
4
- import { union, subsequence, inits, some, creation, block, line, validate, fence, rewrite, open, clear, convert, trim, dup, lazy, fmap } from '../../../combinator';
4
+ import { union, subsequence, inits, some, creation, block, line, validate, fence, rewrite, open, clear, convert, dup, lazy, fmap } from '../../../combinator';
5
5
  import { inline } from '../../inline';
6
6
  import { str, anyline, emptyline, contentline } from '../../source';
7
- import { visualize } from '../../visibility';
7
+ import { visualize, trimBlankStart, trimNodeEnd } from '../../visibility';
8
8
  import { unshift, splice } from 'spica/array';
9
9
  import { html, define, defrag } from 'typed-dom/dom';
10
10
 
@@ -84,9 +84,9 @@ const head: CellParser.HeadParser = creation(1, false, block(fmap(open(
84
84
  anyline,
85
85
  some(contentline, delimiter),
86
86
  ]),
87
- trim(visualize(some(union([inline]))))),
87
+ open(/^(?:\s*\n|\s)/, visualize(trimBlankStart(some(union([inline])))), true)),
88
88
  true),
89
- ns => [html('th', attributes(ns.shift()! as string), defrag(ns))]),
89
+ ns => [html('th', attributes(ns.shift()! as string), trimNodeEnd(defrag(ns)))]),
90
90
  false));
91
91
 
92
92
  const data: CellParser.DataParser = creation(1, false, block(fmap(open(
@@ -96,9 +96,9 @@ const data: CellParser.DataParser = creation(1, false, block(fmap(open(
96
96
  anyline,
97
97
  some(contentline, delimiter),
98
98
  ]),
99
- trim(visualize(some(union([inline]))))),
99
+ open(/^(?:\s*\n|\s)/, visualize(some(union([inline]))), true)),
100
100
  true),
101
- ns => [html('td', attributes(ns.shift()! as string), defrag(ns))]),
101
+ ns => [html('td', attributes(ns.shift()! as string), trimNodeEnd(defrag(ns)))]),
102
102
  false));
103
103
 
104
104
  const dataline: CellParser.DatalineParser = creation(1, false, line(
@@ -60,27 +60,25 @@ describe('Unit: parser/block/heading', () => {
60
60
  });
61
61
 
62
62
  it('indexer', () => {
63
- assert.deepStrictEqual(inspect(parser('# [#a]')), [['<h1 id="index::[#a]">[#a]</h1>'], '']);
64
- assert.deepStrictEqual(inspect(parser('# a[#b]')), [['<h1 id="index::a[#b]">a[#b]</h1>'], '']);
65
- assert.deepStrictEqual(inspect(parser('# a [#b]')), [['<h1 id="index::b">a<span class="indexer" data-index="b"></span></h1>'], '']);
66
- assert.deepStrictEqual(inspect(parser('# a [#b] ')), [['<h1 id="index::b">a<span class="indexer" data-index="b"></span></h1>'], '']);
67
- assert.deepStrictEqual(inspect(parser('# a [#b]\\')), [['<h1 id="index::a_[#b]">a [#b]</h1>'], '']);
68
- assert.deepStrictEqual(inspect(parser('# a [#B]')), [['<h1 id="index::B">a<span class="indexer" data-index="B"></span></h1>'], '']);
69
- assert.deepStrictEqual(inspect(parser('# a [#b ]')), [['<h1 id="index::b">a<span class="indexer" data-index="b"></span></h1>'], '']);
70
- assert.deepStrictEqual(inspect(parser('# a [#b ]')), [['<h1 id="index::b">a<span class="indexer" data-index="b"></span></h1>'], '']);
71
- assert.deepStrictEqual(inspect(parser('# a [#b c]')), [['<h1 id="index::b_c">a<span class="indexer" data-index="b_c"></span></h1>'], '']);
72
- assert.deepStrictEqual(inspect(parser('# a [#_b_`c`${d}$]')), [['<h1 id="index::b`c`${d}$">a<span class="indexer" data-index="b`c`${d}$"></span></h1>'], '']);
73
- assert.deepStrictEqual(inspect(parser('# a [#@a]')), [['<h1 id="index::@a">a<span class="indexer" data-index="@a"></span></h1>'], '']);
74
- assert.deepStrictEqual(inspect(parser('# a [#http://host]')), [['<h1 id="index::http://host">a<span class="indexer" data-index="http://host"></span></h1>'], '']);
75
- assert.deepStrictEqual(inspect(parser('# a [#!http://host]')), [['<h1 id="index::!http://host">a<span class="indexer" data-index="!http://host"></span></h1>'], '']);
76
- assert.deepStrictEqual(inspect(parser('# a [#a((b))]')), [['<h1 id="index::a((b))">a<span class="indexer" data-index="a((b))"></span></h1>'], '']);
77
- assert.deepStrictEqual(inspect(parser('# a [#a[[b]]]')), [['<h1 id="index::a[[b]]">a<span class="indexer" data-index="a[[b]]"></span></h1>'], '']);
78
- assert.deepStrictEqual(inspect(parser('# a [#b |c]')), [['<h1 id="index::c">a<span class="indexer" data-index="c"></span></h1>'], '']);
79
- assert.deepStrictEqual(inspect(parser('# a [#b] [#c]')), [['<h1 id="index::c">a [#b]<span class="indexer" data-index="c"></span></h1>'], '']);
80
- assert.deepStrictEqual(inspect(parser('# a [#b] \n')), [['<h1 id="index::b">a<span class="indexer" data-index="b"></span></h1>'], '']);
81
- assert.deepStrictEqual(inspect(parser('# a \\[#b]')), [['<h1 id="index::a_[#b]">a [#b]</h1>'], '']);
82
- assert.deepStrictEqual(inspect(parser('## a [#b] [#c]')), [['<h2 id="index::c">a [<a class="hashtag" href="/hashtags/b">#b</a>]<span class="indexer" data-index="c"></span></h2>'], '']);
83
- assert.deepStrictEqual(inspect(parser('## a [#b ] [#c ]')), [['<h2 id="index::c">a [<a class="hashtag" href="/hashtags/b">#b</a> ]<span class="indexer" data-index="c"></span></h2>'], '']);
63
+ assert.deepStrictEqual(inspect(parser('# [|a]')), [['<h1 id="index::a"><span class="invalid">a</span></h1>'], '']);
64
+ assert.deepStrictEqual(inspect(parser('# a[|b]')), [['<h1 id="index::ab">a<span class="invalid">b</span></h1>'], '']);
65
+ assert.deepStrictEqual(inspect(parser('# a [|b]')), [['<h1 id="index::b">a<span class="indexer" data-index="b"></span></h1>'], '']);
66
+ assert.deepStrictEqual(inspect(parser('# a [|b] ')), [['<h1 id="index::b">a<span class="indexer" data-index="b"></span></h1>'], '']);
67
+ assert.deepStrictEqual(inspect(parser('# a [|b]\\')), [['<h1 id="index::a_b">a <span class="invalid">b</span></h1>'], '']);
68
+ assert.deepStrictEqual(inspect(parser('# a [|B]')), [['<h1 id="index::B">a<span class="indexer" data-index="B"></span></h1>'], '']);
69
+ assert.deepStrictEqual(inspect(parser('# a [|b ]')), [['<h1 id="index::b">a<span class="indexer" data-index="b"></span></h1>'], '']);
70
+ assert.deepStrictEqual(inspect(parser('# a [|b ]')), [['<h1 id="index::b">a<span class="indexer" data-index="b"></span></h1>'], '']);
71
+ assert.deepStrictEqual(inspect(parser('# a [|b c]')), [['<h1 id="index::b_c">a<span class="indexer" data-index="b_c"></span></h1>'], '']);
72
+ assert.deepStrictEqual(inspect(parser('# a [|_b_`c`${d}$]')), [['<h1 id="index::_b_`c`${d}$">a<span class="indexer" data-index="_b_`c`${d}$"></span></h1>'], '']);
73
+ assert.deepStrictEqual(inspect(parser('# a [|@a]')), [['<h1 id="index::@a">a<span class="indexer" data-index="@a"></span></h1>'], '']);
74
+ assert.deepStrictEqual(inspect(parser('# a [|http://host]')), [['<h1 id="index::http://host">a<span class="indexer" data-index="http://host"></span></h1>'], '']);
75
+ assert.deepStrictEqual(inspect(parser('# a [|!http://host]')), [['<h1 id="index::!http://host">a<span class="indexer" data-index="!http://host"></span></h1>'], '']);
76
+ assert.deepStrictEqual(inspect(parser('# a [|a((b))]')), [['<h1 id="index::a((b))">a<span class="indexer" data-index="a((b))"></span></h1>'], '']);
77
+ assert.deepStrictEqual(inspect(parser('# a [|a[[b]]]')), [['<h1 id="index::a[[b]]">a<span class="indexer" data-index="a[[b]]"></span></h1>'], '']);
78
+ assert.deepStrictEqual(inspect(parser('# a [|b] [|c]')), [['<h1 id="index::c">a <span class="invalid">b</span><span class="indexer" data-index="c"></span></h1>'], '']);
79
+ assert.deepStrictEqual(inspect(parser('# a [|b] \n')), [['<h1 id="index::b">a<span class="indexer" data-index="b"></span></h1>'], '']);
80
+ assert.deepStrictEqual(inspect(parser('# a \\[|b]')), [['<h1 id="index::a_[|b]">a [|b]</h1>'], '']);
81
+ assert.deepStrictEqual(inspect(parser('## a [|b] [|c]')), [['<h2 id="index::c">a <span class="invalid">b</span><span class="indexer" data-index="c"></span></h2>'], '']);
84
82
  });
85
83
 
86
84
  });
@@ -127,13 +127,13 @@ describe('Unit: parser/block/olist', () => {
127
127
  });
128
128
 
129
129
  it('indexer', () => {
130
- assert.deepStrictEqual(inspect(parser('1. [#a]')), [['<ol><li><a class="index indexer" href="#index::a" data-index="">a</a></li></ol>'], '']);
131
- assert.deepStrictEqual(inspect(parser('1. a [#]')), [['<ol><li>a<span class="indexer" data-index=""></span></li></ol>'], '']);
132
- assert.deepStrictEqual(inspect(parser('1. a [#b]')), [['<ol><li id="index::b">a<span class="indexer" data-index="b"></span></li></ol>'], '']);
133
- assert.deepStrictEqual(inspect(parser('1. [ ] [#a]')), [['<ol class="checklist"><li><span class="checkbox">☐</span><a class="index indexer" href="#index::a" data-index="">a</a></li></ol>'], '']);
134
- assert.deepStrictEqual(inspect(parser('1. [ ] a [#b]')), [['<ol class="checklist"><li id="index::b"><span class="checkbox">☐</span>a<span class="indexer" data-index="b"></span></li></ol>'], '']);
135
- assert.deepStrictEqual(inspect(parser('1. a [#]\n 1. c [#d]')), [['<ol><li>a<span class="indexer" data-index=""></span><ol><li id="index::d">c<span class="indexer" data-index="d"></span></li></ol></li></ol>'], '']);
136
- assert.deepStrictEqual(inspect(parser('1. a [#b]\n 1. c [#d]')), [['<ol><li id="index::b">a<span class="indexer" data-index="b"></span><ol><li id="index::d">c<span class="indexer" data-index="d"></span></li></ol></li></ol>'], '']);
130
+ assert.deepStrictEqual(inspect(parser('1. [|a]')), [['<ol><li id="index::a"><span class="invalid">a</span></li></ol>'], '']);
131
+ assert.deepStrictEqual(inspect(parser('1. a [|]')), [['<ol><li>a<span class="indexer" data-index=""></span></li></ol>'], '']);
132
+ assert.deepStrictEqual(inspect(parser('1. a [|b]')), [['<ol><li id="index::b">a<span class="indexer" data-index="b"></span></li></ol>'], '']);
133
+ assert.deepStrictEqual(inspect(parser('1. [ ] [|a]')), [['<ol class="checklist"><li id="index::a"><span class="checkbox">☐</span><span class="invalid">a</span></li></ol>'], '']);
134
+ assert.deepStrictEqual(inspect(parser('1. [ ] a [|b]')), [['<ol class="checklist"><li id="index::b"><span class="checkbox">☐</span>a<span class="indexer" data-index="b"></span></li></ol>'], '']);
135
+ assert.deepStrictEqual(inspect(parser('1. a [|]\n 1. c [|d]')), [['<ol><li>a<span class="indexer" data-index=""></span><ol><li id="index::d">c<span class="indexer" data-index="d"></span></li></ol></li></ol>'], '']);
136
+ assert.deepStrictEqual(inspect(parser('1. a [|b]\n 1. c [|d]')), [['<ol><li id="index::b">a<span class="indexer" data-index="b"></span><ol><li id="index::d">c<span class="indexer" data-index="d"></span></li></ol></li></ol>'], '']);
137
137
  });
138
138
 
139
139
  });
@@ -9,7 +9,6 @@ import { contentline } from '../source';
9
9
  import { State } from '../context';
10
10
  import { visualize, trimBlank } from '../visibility';
11
11
  import { memoize } from 'spica/memoize';
12
- import { shift } from 'spica/array';
13
12
  import { html, define, defrag } from 'typed-dom/dom';
14
13
 
15
14
  const openers = {
@@ -38,17 +37,16 @@ const list = (type: string, form: string): OListParser.ListParser => fmap(
38
37
  some(creation(1, false, union([
39
38
  indexee(fmap(fallback(
40
39
  inits([
41
- line(open(heads[form], subsequence([checkbox, union([
42
- trim(fmap(close(union([index]), /^$/), ([el]) => [
40
+ line(open(heads[form], subsequence([checkbox, trim(union([
41
+ fmap(close(union([index]), /^$/), ([el]) => [
43
42
  define(el, { class: void el.classList.add('indexer'), 'data-index': '' })
44
- ])),
45
- trimBlank(visualize(some(union([indexer, inline])))),
46
- ])]), true)),
43
+ ]),
44
+ visualize(trimBlank(some(union([indexer, inline])))),
45
+ ]))]), true)),
47
46
  indent(union([ulist_, olist_, ilist_])),
48
47
  ]),
49
48
  invalid),
50
- (ns: [string, ...(HTMLElement | string)[]]) =>
51
- [html('li', { 'data-marker': ns[0] || undefined }, defrag(fillFirstLine(shift(ns)[1])))]), true),
49
+ ns => [html('li', { 'data-marker': ns.shift() as string || undefined }, defrag(fillFirstLine(ns)))]), true),
52
50
  ]))),
53
51
  es => [format(html('ol', es), type, form)]);
54
52
 
@@ -23,9 +23,9 @@ const source: SidefenceParser.SourceParser = lazy(() => fmap(
23
23
  some(creation(1, false, union([
24
24
  focus(
25
25
  /^(?:\|\|+(?:[^\S\n][^\n]*)?(?:$|\n))+/,
26
- convert(unindent, source)),
26
+ convert(unindent, source, true)),
27
27
  rewrite(
28
28
  some(contentline, opener),
29
- convert(unindent, fmap(autolink, ns => [html('pre', defrag(ns))]))),
29
+ convert(unindent, fmap(autolink, ns => [html('pre', defrag(ns))]), true)),
30
30
  ]))),
31
31
  ns => [html('blockquote', ns)]));
@@ -2,7 +2,7 @@ import { TableParser } from '../block';
2
2
  import { union, sequence, some, creation, block, line, validate, focus, rewrite, surround, open, fallback, lazy, fmap } from '../../combinator';
3
3
  import { inline } from '../inline';
4
4
  import { contentline } from '../source';
5
- import { trimNode } from '../visibility';
5
+ import { trimBlankStart, trimNodeEnd } from '../visibility';
6
6
  import { duffReduce } from 'spica/duff';
7
7
  import { push } from 'spica/array';
8
8
  import { html, defrag } from 'typed-dom/dom';
@@ -49,16 +49,16 @@ const align: AlignParser = creation(1, false, fmap(open(
49
49
 
50
50
  const cell: CellParser = surround(
51
51
  /^\|\s*(?=\S)/,
52
- some(union([inline]), /^\|/, [[/^[|\\]?\s*$/, 9]]),
52
+ trimBlankStart(some(union([inline]), /^\|/, [[/^[|\\]?\s*$/, 9]])),
53
53
  /^[^|]*/, true);
54
54
 
55
55
  const head: CellParser.HeadParser = creation(1, false, fmap(
56
56
  cell,
57
- ns => [html('th', trimNode(defrag(ns)))]));
57
+ ns => [html('th', trimNodeEnd(defrag(ns)))]));
58
58
 
59
59
  const data: CellParser.DataParser = creation(1, false, fmap(
60
60
  cell,
61
- ns => [html('td', trimNode(defrag(ns)))]));
61
+ ns => [html('td', trimNodeEnd(defrag(ns)))]));
62
62
 
63
63
  function format(rows: HTMLTableRowElement[]): HTMLTableRowElement[] {
64
64
  const aligns = rows[0].className === 'invalid'
@@ -67,13 +67,13 @@ describe('Unit: parser/block/ulist', () => {
67
67
  });
68
68
 
69
69
  it('indexer', () => {
70
- assert.deepStrictEqual(inspect(parser('- [#a]')), [['<ul><li><a class="index indexer" href="#index::a" data-index="">a</a></li></ul>'], '']);
71
- assert.deepStrictEqual(inspect(parser('- a [#]')), [['<ul><li>a<span class="indexer" data-index=""></span></li></ul>'], '']);
72
- assert.deepStrictEqual(inspect(parser('- a [#b]')), [['<ul><li id="index::b">a<span class="indexer" data-index="b"></span></li></ul>'], '']);
73
- assert.deepStrictEqual(inspect(parser('- [ ] [#a]')), [['<ul class="checklist"><li><span class="checkbox">☐</span><a class="index indexer" href="#index::a" data-index="">a</a></li></ul>'], '']);
74
- assert.deepStrictEqual(inspect(parser('- [ ] a [#b]')), [['<ul class="checklist"><li id="index::b"><span class="checkbox">☐</span>a<span class="indexer" data-index="b"></span></li></ul>'], '']);
75
- assert.deepStrictEqual(inspect(parser('- a [#]\n - c [#d]')), [['<ul><li>a<span class="indexer" data-index=""></span><ul><li id="index::d">c<span class="indexer" data-index="d"></span></li></ul></li></ul>'], '']);
76
- assert.deepStrictEqual(inspect(parser('- a [#b]\n - c [#d]')), [['<ul><li id="index::b">a<span class="indexer" data-index="b"></span><ul><li id="index::d">c<span class="indexer" data-index="d"></span></li></ul></li></ul>'], '']);
70
+ assert.deepStrictEqual(inspect(parser('- [|a]')), [['<ul><li id="index::a"><span class="invalid">a</span></li></ul>'], '']);
71
+ assert.deepStrictEqual(inspect(parser('- a [|]')), [['<ul><li>a<span class="indexer" data-index=""></span></li></ul>'], '']);
72
+ assert.deepStrictEqual(inspect(parser('- a [|b]')), [['<ul><li id="index::b">a<span class="indexer" data-index="b"></span></li></ul>'], '']);
73
+ assert.deepStrictEqual(inspect(parser('- [ ] [|a]')), [['<ul class="checklist"><li id="index::a"><span class="checkbox">☐</span><span class="invalid">a</span></li></ul>'], '']);
74
+ assert.deepStrictEqual(inspect(parser('- [ ] a [|b]')), [['<ul class="checklist"><li id="index::b"><span class="checkbox">☐</span>a<span class="indexer" data-index="b"></span></li></ul>'], '']);
75
+ assert.deepStrictEqual(inspect(parser('- a [|]\n - c [|d]')), [['<ul><li>a<span class="indexer" data-index=""></span><ul><li id="index::d">c<span class="indexer" data-index="d"></span></li></ul></li></ul>'], '']);
76
+ assert.deepStrictEqual(inspect(parser('- a [|b]\n - c [|d]')), [['<ul><li id="index::b">a<span class="indexer" data-index="b"></span><ul><li id="index::d">c<span class="indexer" data-index="d"></span></li></ul></li></ul>'], '']);
77
77
  });
78
78
 
79
79
  });
@@ -19,12 +19,12 @@ export const ulist_: UListParser = lazy(() => block(fmap(validate(
19
19
  some(creation(1, false, union([
20
20
  indexee(fmap(fallback(
21
21
  inits([
22
- line(open(/^-(?:$|\s)/, subsequence([checkbox, union([
23
- trim(fmap(close(union([index]), /^$/), ([el]) => [
22
+ line(open(/^-(?:$|\s)/, subsequence([checkbox, trim(union([
23
+ fmap(close(union([index]), /^$/), ([el]) => [
24
24
  define(el, { class: void el.classList.add('indexer'), 'data-index': '' })
25
- ])),
26
- trimBlank(visualize(some(union([indexer, inline])))),
27
- ])]), true)),
25
+ ]),
26
+ visualize(trimBlank(some(union([indexer, inline])))),
27
+ ]))]), true)),
28
28
  indent(union([ulist_, olist_, ilist_])),
29
29
  ]),
30
30
  invalid),
@@ -2,15 +2,14 @@ import { AnnotationParser } from '../inline';
2
2
  import { union, some, syntax, constraint, surround, lazy } from '../../combinator';
3
3
  import { inline } from '../inline';
4
4
  import { Syntax, State } from '../context';
5
- import { startLoose, trimNode } from '../visibility';
5
+ import { trimBlankStart, trimNodeEnd } from '../visibility';
6
6
  import { html, defrag } from 'typed-dom/dom';
7
7
 
8
8
  export const annotation: AnnotationParser = lazy(() => surround(
9
9
  '((',
10
10
  constraint(State.annotation, false,
11
11
  syntax(Syntax.none, 6, 1, State.annotation | State.media,
12
- startLoose(
13
- some(union([inline]), ')', [[/^\\?\n/, 9], [')', 2], ['))', 6]]), ')'))),
12
+ trimBlankStart(some(union([inline]), ')', [[/^\\?\n/, 9], [')', 2], ['))', 6]])))),
14
13
  '))',
15
14
  false,
16
- ([, ns], rest) => [[html('sup', { class: 'annotation' }, [html('span', trimNode(defrag(ns)))])], rest]));
15
+ ([, ns], rest) => [[html('sup', { class: 'annotation' }, [html('span', trimNodeEnd(defrag(ns)))])], rest]));
@@ -30,7 +30,7 @@ export const index: IndexParser = lazy(() => validate('[#', fmap(indexee(surroun
30
30
  }),
31
31
  ])));
32
32
 
33
- const signature: IndexParser.SignatureParser = lazy(() => creation(fmap(open(
33
+ export const signature: IndexParser.SignatureParser = lazy(() => creation(fmap(open(
34
34
  '|',
35
35
  startTight(some(union([bracket, txt]), ']'))),
36
36
  ns => [
@@ -8,29 +8,28 @@ describe('Unit: parser/inline/extension/indexer', () => {
8
8
 
9
9
  it('invalid', () => {
10
10
  assert.deepStrictEqual(inspect(parser('')), undefined);
11
- assert.deepStrictEqual(inspect(parser('[#a]')), undefined);
11
+ assert.deepStrictEqual(inspect(parser('[|a]')), undefined);
12
12
  assert.deepStrictEqual(inspect(parser(' ')), undefined);
13
- assert.deepStrictEqual(inspect(parser(' #')), undefined);
14
- assert.deepStrictEqual(inspect(parser(' #a')), undefined);
15
- assert.deepStrictEqual(inspect(parser(' [# ]')), undefined);
16
- assert.deepStrictEqual(inspect(parser(' [#]]')), undefined);
17
- assert.deepStrictEqual(inspect(parser(' [#a]]')), undefined);
18
- assert.deepStrictEqual(inspect(parser(' [#&a;]')), undefined);
13
+ assert.deepStrictEqual(inspect(parser(' |')), undefined);
14
+ assert.deepStrictEqual(inspect(parser(' |a')), undefined);
15
+ assert.deepStrictEqual(inspect(parser(' [| ]')), undefined);
16
+ assert.deepStrictEqual(inspect(parser(' [|]]')), undefined);
17
+ assert.deepStrictEqual(inspect(parser(' [|a]]')), undefined);
19
18
  });
20
19
 
21
20
  it('valid', () => {
22
- assert.deepStrictEqual(inspect(parser(' [#]')), [['<span class="indexer" data-index=""></span>'], '']);
23
- assert.deepStrictEqual(inspect(parser(' [#a]')), [['<span class="indexer" data-index="a"></span>'], '']);
24
- assert.deepStrictEqual(inspect(parser(' [#a] ')), [['<span class="indexer" data-index="a"></span>'], '']);
25
- assert.deepStrictEqual(inspect(parser(' [#a ]')), [['<span class="indexer" data-index="a"></span>'], '']);
26
- assert.deepStrictEqual(inspect(parser(' [#a ]')), [['<span class="indexer" data-index="a"></span>'], '']);
27
- assert.deepStrictEqual(inspect(parser(' [#a b]')), [['<span class="indexer" data-index="a_b"></span>'], '']);
28
- assert.deepStrictEqual(inspect(parser(' [#a b]')), [['<span class="indexer" data-index="a_b"></span>'], '']);
29
- assert.deepStrictEqual(inspect(parser(' [#A]')), [['<span class="indexer" data-index="A"></span>'], '']);
30
- assert.deepStrictEqual(inspect(parser(' [#*A*]')), [['<span class="indexer" data-index="A"></span>'], '']);
31
- assert.deepStrictEqual(inspect(parser(' [#`A`]')), [['<span class="indexer" data-index="`A`"></span>'], '']);
32
- assert.deepStrictEqual(inspect(parser(' [#${A}$]')), [['<span class="indexer" data-index="${A}$"></span>'], '']);
33
- assert.deepStrictEqual(inspect(parser(' [#a]')), [['<span class="indexer" data-index="a"></span>'], '']);
21
+ assert.deepStrictEqual(inspect(parser(' [|]')), [['<span class="indexer" data-index=""></span>'], '']);
22
+ assert.deepStrictEqual(inspect(parser(' [|a]')), [['<span class="indexer" data-index="a"></span>'], '']);
23
+ assert.deepStrictEqual(inspect(parser(' [|a] ')), [['<span class="indexer" data-index="a"></span>'], '']);
24
+ assert.deepStrictEqual(inspect(parser(' [|a ]')), [['<span class="indexer" data-index="a"></span>'], '']);
25
+ assert.deepStrictEqual(inspect(parser(' [|a ]')), [['<span class="indexer" data-index="a"></span>'], '']);
26
+ assert.deepStrictEqual(inspect(parser(' [|a b]')), [['<span class="indexer" data-index="a_b"></span>'], '']);
27
+ assert.deepStrictEqual(inspect(parser(' [|a b]')), [['<span class="indexer" data-index="a_b"></span>'], '']);
28
+ assert.deepStrictEqual(inspect(parser(' [|A]')), [['<span class="indexer" data-index="A"></span>'], '']);
29
+ assert.deepStrictEqual(inspect(parser(' [|*A*]')), [['<span class="indexer" data-index="*A*"></span>'], '']);
30
+ assert.deepStrictEqual(inspect(parser(' [|`A`]')), [['<span class="indexer" data-index="`A`"></span>'], '']);
31
+ assert.deepStrictEqual(inspect(parser(' [|${A}$]')), [['<span class="indexer" data-index="${A}$"></span>'], '']);
32
+ assert.deepStrictEqual(inspect(parser(' [|a]')), [['<span class="indexer" data-index="a"></span>'], '']);
34
33
  });
35
34
 
36
35
  });
@@ -1,22 +1,14 @@
1
1
  import { ExtensionParser } from '../../inline';
2
- import { union, creation, state, verify, focus, surround, fmap } from '../../../combinator';
3
- import { index } from './index';
2
+ import { union, creation, state, focus, surround } from '../../../combinator';
3
+ import { signature } from './index';
4
4
  import { State } from '../../context';
5
5
  import { html } from 'typed-dom/dom';
6
6
 
7
- export const indexer: ExtensionParser.IndexerParser = creation(fmap(verify(surround(
8
- /^\s+(?=\[#\S)/,
7
+ export const indexer: ExtensionParser.IndexerParser = surround(
8
+ /^\s+\[(?=\|\S)/,
9
9
  state(State.index, false,
10
10
  union([
11
- focus('[#]', () => [[html('a', { href: '#' })], '']),
12
- index,
11
+ signature,
12
+ creation(focus(/^\|(?=\])/, () => [[html('span', { class: 'indexer', 'data-index': '' })], ''])),
13
13
  ])),
14
- /^\s*$/),
15
- // Indexer is invisible but invalids must be visible.
16
- ([el]) => el.getElementsByClassName('invalid').length === 0),
17
- ([el]) => [
18
- html('span', {
19
- class: 'indexer',
20
- 'data-index': el.getAttribute('href')!.slice(1).replace(/^[^:]*:[^:]*:/, ''),
21
- }),
22
- ]));
14
+ /^\]\s*$/);
@@ -83,6 +83,7 @@ const TAGS = Object.freeze([
83
83
  "footer",
84
84
  "header",
85
85
  "h1", "h2", "h3", "h4", "h5", "h6",
86
+ "hgroup",
86
87
  "main",
87
88
  "nav",
88
89
  "section",
@@ -179,7 +180,6 @@ const TAGS = Object.freeze([
179
180
  "template",
180
181
  "acronym",
181
182
  "applet",
182
- "basefont",
183
183
  "bgsound",
184
184
  "big",
185
185
  "blink",
@@ -189,7 +189,6 @@ const TAGS = Object.freeze([
189
189
  "font",
190
190
  "frame",
191
191
  "frameset",
192
- "hgroup",
193
192
  "image",
194
193
  "keygen",
195
194
  "marquee",
@@ -1,31 +1,31 @@
1
1
  import { ReferenceParser } from '../inline';
2
- import { union, subsequence, some, syntax, creation, constraint, surround, lazy, fmap, bind } from '../../combinator';
2
+ import { union, subsequence, some, syntax, creation, constraint, surround, lazy } from '../../combinator';
3
3
  import { inline } from '../inline';
4
4
  import { str } from '../source';
5
5
  import { Syntax, State } from '../context';
6
- import { regBlankStart, startLoose, trimNode } from '../visibility';
6
+ import { blank, trimBlankStart, trimNodeEnd } from '../visibility';
7
7
  import { html, defrag } from 'typed-dom/dom';
8
8
 
9
9
  export const reference: ReferenceParser = lazy(() => surround(
10
10
  '[[',
11
11
  constraint(State.reference, false,
12
12
  syntax(Syntax.reference, 6, 1, State.annotation | State.reference | State.media,
13
- startLoose(
14
13
  subsequence([
15
14
  abbr,
16
- fmap(str('^'), ns => ['', ...ns]),
17
- some(inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]]),
18
- ]), ']'))),
15
+ trimBlankStart(some(inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]])),
16
+ ]))),
19
17
  ']]',
20
18
  false,
21
- ([, ns], rest) => [[html('sup', attributes(ns), [html('span', trimNode(defrag(ns)))])], rest]));
19
+ ([, ns], rest) => [[html('sup', attributes(ns), [html('span', trimNodeEnd(defrag(ns)))])], rest]));
22
20
 
23
21
  // Chicago-Style
24
- const abbr: ReferenceParser.AbbrParser = creation(bind(surround(
22
+ const abbr: ReferenceParser.AbbrParser = creation(surround(
25
23
  '^',
26
24
  union([str(/^(?=[A-Z])(?:[0-9A-Za-z]'?|(?:[-.:]|\.?\??,? ?)(?!['\-.:?, ]))+/)]),
27
- /^\|?(?=]])|^\|[^\S\n]*/),
28
- ([source], rest) => [['\n', source.trimEnd()], rest.replace(regBlankStart, '')]));
25
+ /^\|?(?=]])|^\|[^\S\n]*/,
26
+ true,
27
+ ([, ns], rest) => ns ? [['\n', ns[0].trimEnd()], rest.replace(blank.start, '')] : [[''], `^${rest}`],
28
+ ([, , rest]) => [[''], `^${rest}`]));
29
29
 
30
30
  function attributes(ns: (string | HTMLElement)[]): Record<string, string | undefined> {
31
31
  switch (ns[0]) {
@@ -8,14 +8,21 @@ import { invisibleHTMLEntityNames } from './api/normalize';
8
8
  import { reduce } from 'spica/memoize';
9
9
  import { push } from 'spica/array';
10
10
 
11
+ export namespace blank {
12
+ export const line = new RegExp(
13
+ /^(?:\\?[^\S\n]|&IHN;|<wbr[^\S\n]*>|\\$)+$/.source
14
+ .replace('IHN', `(?:${invisibleHTMLEntityNames.join('|')})`),
15
+ 'gm');
16
+ export const start = new RegExp(
17
+ /^(?:\\?[^\S\n]|&IHN;|<wbr[^\S\n]*>)+/.source
18
+ .replace('IHN', `(?:${invisibleHTMLEntityNames.join('|')})`));
19
+ }
20
+
11
21
  export function visualize<P extends Parser<HTMLElement | string>>(parser: P): P;
12
22
  export function visualize<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
13
- const blankline = new RegExp(
14
- /^(?:\\$|\\?[^\S\n]|&IHN;|<wbr[^\S\n]*>)+$/.source.replace('IHN', `(?:${invisibleHTMLEntityNames.join('|')})`),
15
- 'gm');
16
23
  return union([
17
24
  convert(
18
- source => source.replace(blankline, line => line.replace(/[\\&<]/g, '\x1B$&')),
25
+ source => source.replace(blank.line, line => line.replace(/[\\&<]/g, '\x1B$&')),
19
26
  verify(parser, (ns, rest, context) => !rest && hasVisible(ns, context))),
20
27
  some(union([linebreak, unescsource])),
21
28
  ]);
@@ -38,9 +45,6 @@ function hasVisible(
38
45
  return false;
39
46
  }
40
47
 
41
- export const regBlankStart = new RegExp(
42
- /^(?:\\?[^\S\n]|&IHN;|<wbr[^\S\n]*>)+/.source.replace('IHN', `(?:${invisibleHTMLEntityNames.join('|')})`));
43
-
44
48
  export function blankWith(delimiter: string | RegExp): RegExp;
45
49
  export function blankWith(starting: '' | '\n', delimiter: string | RegExp): RegExp;
46
50
  export function blankWith(starting: '' | '\n', delimiter?: string | RegExp): RegExp {
@@ -53,16 +57,16 @@ export function blankWith(starting: '' | '\n', delimiter?: string | RegExp): Reg
53
57
  }`);
54
58
  }
55
59
 
56
- export function startLoose<P extends Parser<HTMLElement | string>>(parser: P, except?: string): P;
57
- export function startLoose<T extends HTMLElement | string>(parser: Parser<T>, except?: string): Parser<T> {
58
- return input =>
59
- isStartLoose(input, except)
60
- ? parser(input)
61
- : undefined;
62
- }
63
- const isStartLoose = reduce(({ source, context }: Input<MarkdownParser.Context>, except?: string): boolean => {
64
- return isStartTight({ source: source.replace(regBlankStart, ''), context }, except);
65
- }, ({ source }, except = '') => `${source}\x1E${except}`);
60
+ //export function startLoose<P extends Parser<HTMLElement | string>>(parser: P, except?: string): P;
61
+ //export function startLoose<T extends HTMLElement | string>(parser: Parser<T>, except?: string): Parser<T> {
62
+ // return input =>
63
+ // isStartLoose(input, except)
64
+ // ? parser(input)
65
+ // : undefined;
66
+ //}
67
+ //const isStartLoose = reduce(({ source, context }: Input<MarkdownParser.Context>, except?: string): boolean => {
68
+ // return isStartTight({ source: source.replace(blank.start, ''), context }, except);
69
+ //}, ({ source }, except = '') => `${source}\x1E${except}`);
66
70
 
67
71
  export function startTight<P extends Parser<unknown>>(parser: P, except?: string): P;
68
72
  export function startTight<T>(parser: Parser<T>, except?: string): Parser<T> {
@@ -154,7 +158,7 @@ export function trimBlank<T extends HTMLElement | string>(parser: Parser<T>): Pa
154
158
  export function trimBlankStart<P extends Parser<unknown>>(parser: P): P;
155
159
  export function trimBlankStart<T>(parser: Parser<T>): Parser<T> {
156
160
  return convert(
157
- reduce(source => source.replace(regBlankStart, '')),
161
+ source => source.replace(blank.start, ''),
158
162
  parser);
159
163
  }
160
164
  function trimBlankEnd<P extends Parser<HTMLElement | string>>(parser: P): P;