securemark 0.274.3 → 0.274.4
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 +4 -0
- package/dist/index.js +25 -16
- package/markdown.d.ts +14 -4
- package/package.json +8 -8
- package/src/parser/block/olist.test.ts +2 -2
- package/src/parser/block/olist.ts +11 -5
- package/src/parser/block/ulist.test.ts +2 -2
- package/src/parser/block/ulist.ts +9 -3
- package/src/parser/inline/extension/index.ts +1 -2
- package/src/parser/inline/extension/indexee.ts +1 -1
- package/src/parser/inline/reference.ts +1 -4
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! securemark v0.274.
|
|
1
|
+
/*! securemark v0.274.4 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"));
|
|
@@ -5259,6 +5259,7 @@ const combinator_1 = __webpack_require__(2087);
|
|
|
5259
5259
|
const ulist_1 = __webpack_require__(5425);
|
|
5260
5260
|
const ilist_1 = __webpack_require__(238);
|
|
5261
5261
|
const inline_1 = __webpack_require__(1160);
|
|
5262
|
+
const index_1 = __webpack_require__(4479);
|
|
5262
5263
|
const source_1 = __webpack_require__(6743);
|
|
5263
5264
|
const visibility_1 = __webpack_require__(7618);
|
|
5264
5265
|
const memoize_1 = __webpack_require__(1808);
|
|
@@ -5269,8 +5270,11 @@ const openers = {
|
|
|
5269
5270
|
'(': /^\(([0-9]*|[a-z]*)(?![^)\n])\)?(?:-(?!-)[0-9]*)*(?:$|\s)/
|
|
5270
5271
|
};
|
|
5271
5272
|
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_))));
|
|
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 =>
|
|
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,
|
|
5273
|
+
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, {
|
|
5275
|
+
class: void el.classList.add('indexer'),
|
|
5276
|
+
'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', {
|
|
5274
5278
|
'data-marker': ns[0] || undefined
|
|
5275
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
5280
|
const heads = {
|
|
@@ -5291,7 +5295,7 @@ exports.invalid = (0, combinator_1.rewrite)((0, combinator_1.inits)([source_1.co
|
|
|
5291
5295
|
'data-invalid-type': 'syntax',
|
|
5292
5296
|
'data-invalid-message': 'Fix the indent or the head of the list item'
|
|
5293
5297
|
}, source.replace('\n', ''))], '']);
|
|
5294
|
-
function
|
|
5298
|
+
function idx(value) {
|
|
5295
5299
|
switch (value) {
|
|
5296
5300
|
case 'i':
|
|
5297
5301
|
return 1;
|
|
@@ -5632,11 +5636,15 @@ const combinator_1 = __webpack_require__(2087);
|
|
|
5632
5636
|
const olist_1 = __webpack_require__(7471);
|
|
5633
5637
|
const ilist_1 = __webpack_require__(238);
|
|
5634
5638
|
const inline_1 = __webpack_require__(1160);
|
|
5639
|
+
const index_1 = __webpack_require__(4479);
|
|
5635
5640
|
const visibility_1 = __webpack_require__(7618);
|
|
5636
5641
|
const array_1 = __webpack_require__(8112);
|
|
5637
5642
|
const dom_1 = __webpack_require__(3252);
|
|
5638
5643
|
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_))));
|
|
5639
|
-
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,
|
|
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, {
|
|
5645
|
+
class: void el.classList.add('indexer'),
|
|
5646
|
+
'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))])));
|
|
5640
5648
|
exports.checkbox = (0, combinator_1.creation)(1, false, (0, combinator_1.focus)(/^\[[xX ]\](?=$|\s)/, ({
|
|
5641
5649
|
source
|
|
5642
5650
|
}) => [[(0, dom_1.html)('span', {
|
|
@@ -6143,7 +6151,7 @@ exports.index = (0, combinator_1.lazy)(() => (0, combinator_1.validate)('[#', (0
|
|
|
6143
6151
|
id: el.id ? null : undefined,
|
|
6144
6152
|
class: 'index',
|
|
6145
6153
|
href: el.id ? `#${el.id}` : undefined
|
|
6146
|
-
}
|
|
6154
|
+
})])));
|
|
6147
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', {
|
|
6148
6156
|
class: 'indexer',
|
|
6149
6157
|
'data-index': (0, indexee_1.identity)(undefined, ns.join('')).slice(7)
|
|
@@ -8409,7 +8417,7 @@ function unlink(h) {
|
|
|
8409
8417
|
/***/ 3252:
|
|
8410
8418
|
/***/ (function(module) {
|
|
8411
8419
|
|
|
8412
|
-
/*! typed-dom v0.0.
|
|
8420
|
+
/*! typed-dom v0.0.333 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
|
|
8413
8421
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
8414
8422
|
if(true)
|
|
8415
8423
|
module.exports = factory();
|
|
@@ -8522,7 +8530,7 @@ exports.reduce = reduce;
|
|
|
8522
8530
|
Object.defineProperty(exports, "__esModule", ({
|
|
8523
8531
|
value: true
|
|
8524
8532
|
}));
|
|
8525
|
-
exports.defrag = exports.prepend = exports.append = exports.isChildren = exports.define = exports.element = exports.text = exports.svg = exports.html = exports.frag = exports.shadow = void 0;
|
|
8533
|
+
exports.defrag = exports.prepend = exports.append = exports.isChildren = exports.define = exports.element = exports.text = exports.math = exports.svg = exports.html = exports.frag = exports.shadow = void 0;
|
|
8526
8534
|
const alias_1 = __nested_webpack_require_4668__(5406);
|
|
8527
8535
|
const memoize_1 = __nested_webpack_require_4668__(1808);
|
|
8528
8536
|
var caches;
|
|
@@ -8547,6 +8555,7 @@ function frag(children) {
|
|
|
8547
8555
|
exports.frag = frag;
|
|
8548
8556
|
exports.html = element(document, "HTML" /* NS.HTML */);
|
|
8549
8557
|
exports.svg = element(document, "SVG" /* NS.SVG */);
|
|
8558
|
+
exports.math = element(document, "MathML" /* NS.Math */);
|
|
8550
8559
|
function text(source) {
|
|
8551
8560
|
return document.createTextNode(source);
|
|
8552
8561
|
}
|
|
@@ -8558,7 +8567,7 @@ function element(context, ns) {
|
|
|
8558
8567
|
}
|
|
8559
8568
|
exports.element = element;
|
|
8560
8569
|
function elem(context, ns, tag, attrs) {
|
|
8561
|
-
if (!('createElement' in context)) throw new Error(`TypedDOM: Scoped custom elements are not supported on this browser
|
|
8570
|
+
if (!('createElement' in context)) throw new Error(`TypedDOM: Scoped custom elements are not supported on this browser`);
|
|
8562
8571
|
const opts = 'is' in attrs ? {
|
|
8563
8572
|
is: attrs['is']
|
|
8564
8573
|
} : undefined;
|
|
@@ -8567,7 +8576,7 @@ function elem(context, ns, tag, attrs) {
|
|
|
8567
8576
|
return context.createElement(tag, opts);
|
|
8568
8577
|
case "SVG" /* NS.SVG */:
|
|
8569
8578
|
return context.createElementNS('http://www.w3.org/2000/svg', tag, opts);
|
|
8570
|
-
case "MathML" /* NS.
|
|
8579
|
+
case "MathML" /* NS.Math */:
|
|
8571
8580
|
return context.createElementNS('http://www.w3.org/1998/Math/MathML', tag, opts);
|
|
8572
8581
|
}
|
|
8573
8582
|
}
|
|
@@ -8609,10 +8618,10 @@ function defineAttrs(el, attrs) {
|
|
|
8609
8618
|
}
|
|
8610
8619
|
continue;
|
|
8611
8620
|
case 'function':
|
|
8612
|
-
if (name.length < 3) throw new Error(`TypedDOM: Attribute names for event listeners must have an event name but got "${name}"
|
|
8621
|
+
if (name.length < 3) throw new Error(`TypedDOM: Attribute names for event listeners must have an event name but got "${name}"`);
|
|
8613
8622
|
const names = name.split(/\s+/);
|
|
8614
8623
|
for (const name of names) {
|
|
8615
|
-
if (!name.startsWith('on')) throw new Error(`TypedDOM: Attribute names for event listeners must start with "on" but got "${name}"
|
|
8624
|
+
if (!name.startsWith('on')) throw new Error(`TypedDOM: Attribute names for event listeners must start with "on" but got "${name}"`);
|
|
8616
8625
|
const type = name.slice(2).toLowerCase();
|
|
8617
8626
|
el.addEventListener(type, value, {
|
|
8618
8627
|
passive: ['wheel', 'mousewheel', 'touchstart', 'touchmove', 'touchend', 'touchcancel'].includes(type)
|
|
@@ -8708,7 +8717,7 @@ exports.defrag = defrag;
|
|
|
8708
8717
|
/******/ var __webpack_module_cache__ = {};
|
|
8709
8718
|
/******/
|
|
8710
8719
|
/******/ // The require function
|
|
8711
|
-
/******/ function
|
|
8720
|
+
/******/ function __nested_webpack_require_11657__(moduleId) {
|
|
8712
8721
|
/******/ // Check if module is in cache
|
|
8713
8722
|
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
8714
8723
|
/******/ if (cachedModule !== undefined) {
|
|
@@ -8722,7 +8731,7 @@ exports.defrag = defrag;
|
|
|
8722
8731
|
/******/ };
|
|
8723
8732
|
/******/
|
|
8724
8733
|
/******/ // Execute the module function
|
|
8725
|
-
/******/ __webpack_modules__[moduleId](module, module.exports,
|
|
8734
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_11657__);
|
|
8726
8735
|
/******/
|
|
8727
8736
|
/******/ // Return the exports of the module
|
|
8728
8737
|
/******/ return module.exports;
|
|
@@ -8733,7 +8742,7 @@ exports.defrag = defrag;
|
|
|
8733
8742
|
/******/ // startup
|
|
8734
8743
|
/******/ // Load entry module and return exports
|
|
8735
8744
|
/******/ // This entry module is referenced by other modules so it can't be inlined
|
|
8736
|
-
/******/ var __nested_webpack_exports__ =
|
|
8745
|
+
/******/ var __nested_webpack_exports__ = __nested_webpack_require_11657__(7521);
|
|
8737
8746
|
/******/
|
|
8738
8747
|
/******/ return __nested_webpack_exports__;
|
|
8739
8748
|
/******/ })()
|
|
@@ -8745,7 +8754,7 @@ exports.defrag = defrag;
|
|
|
8745
8754
|
/***/ 6120:
|
|
8746
8755
|
/***/ (function(module) {
|
|
8747
8756
|
|
|
8748
|
-
/*! typed-dom v0.0.
|
|
8757
|
+
/*! typed-dom v0.0.333 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
|
|
8749
8758
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
8750
8759
|
if(true)
|
|
8751
8760
|
module.exports = factory();
|
package/markdown.d.ts
CHANGED
|
@@ -118,8 +118,13 @@ export namespace MarkdownParser {
|
|
|
118
118
|
Parser<HTMLElement | string, Context, [
|
|
119
119
|
InlineParser,
|
|
120
120
|
Parser<HTMLElement | string, Context, [
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
Parser<HTMLElement, Context, [
|
|
122
|
+
InlineParser.ExtensionParser.IndexParser,
|
|
123
|
+
]>,
|
|
124
|
+
Parser<HTMLElement | string, Context, [
|
|
125
|
+
InlineParser.ExtensionParser.IndexerParser,
|
|
126
|
+
InlineParser,
|
|
127
|
+
]>,
|
|
123
128
|
]>,
|
|
124
129
|
]>,
|
|
125
130
|
Parser<HTMLUListElement | HTMLOListElement, Context, [
|
|
@@ -153,8 +158,13 @@ export namespace MarkdownParser {
|
|
|
153
158
|
Parser<HTMLElement | string, Context, [
|
|
154
159
|
InlineParser,
|
|
155
160
|
Parser<HTMLElement | string, Context, [
|
|
156
|
-
|
|
157
|
-
|
|
161
|
+
Parser<HTMLElement, Context, [
|
|
162
|
+
InlineParser.ExtensionParser.IndexParser,
|
|
163
|
+
]>,
|
|
164
|
+
Parser<HTMLElement | string, Context, [
|
|
165
|
+
InlineParser.ExtensionParser.IndexerParser,
|
|
166
|
+
InlineParser,
|
|
167
|
+
]>,
|
|
158
168
|
]>,
|
|
159
169
|
]>,
|
|
160
170
|
Parser<HTMLUListElement | HTMLOListElement, Context, [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "securemark",
|
|
3
|
-
"version": "0.274.
|
|
3
|
+
"version": "0.274.4",
|
|
4
4
|
"description": "Secure markdown renderer working on browsers for user input data.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/falsandtru/securemark",
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"@types/mocha": "10.0.1",
|
|
35
35
|
"@types/power-assert": "1.5.8",
|
|
36
36
|
"@types/prismjs": "1.26.0",
|
|
37
|
-
"@typescript-eslint/parser": "^5.59.
|
|
37
|
+
"@typescript-eslint/parser": "^5.59.5",
|
|
38
38
|
"babel-loader": "^9.1.2",
|
|
39
39
|
"babel-plugin-unassert": "^3.2.0",
|
|
40
40
|
"concurrently": "^8.0.1",
|
|
41
|
-
"eslint": "^8.
|
|
41
|
+
"eslint": "^8.40.0",
|
|
42
42
|
"eslint-plugin-redos": "^4.4.5",
|
|
43
43
|
"eslint-webpack-plugin": "^4.0.1",
|
|
44
|
-
"glob": "^10.2.
|
|
44
|
+
"glob": "^10.2.3",
|
|
45
45
|
"karma": "^6.4.2",
|
|
46
46
|
"karma-chrome-launcher": "^3.2.0",
|
|
47
47
|
"karma-coverage": "^2.2.0",
|
|
@@ -49,14 +49,14 @@
|
|
|
49
49
|
"karma-mocha": "^2.0.1",
|
|
50
50
|
"karma-power-assert": "^1.0.0",
|
|
51
51
|
"mocha": "^10.2.0",
|
|
52
|
-
"npm-check-updates": "^16.10.
|
|
52
|
+
"npm-check-updates": "^16.10.12",
|
|
53
53
|
"semver": "^7.5.0",
|
|
54
54
|
"spica": "0.0.721",
|
|
55
55
|
"ts-loader": "^9.4.2",
|
|
56
|
-
"typed-dom": "^0.0.
|
|
56
|
+
"typed-dom": "^0.0.333",
|
|
57
57
|
"typescript": "5.0.4",
|
|
58
|
-
"webpack": "^5.
|
|
59
|
-
"webpack-cli": "^5.
|
|
58
|
+
"webpack": "^5.82.0",
|
|
59
|
+
"webpack-cli": "^5.1.1",
|
|
60
60
|
"webpack-merge": "^5.8.0"
|
|
61
61
|
},
|
|
62
62
|
"scripts": {
|
|
@@ -127,10 +127,10 @@ describe('Unit: parser/block/olist', () => {
|
|
|
127
127
|
});
|
|
128
128
|
|
|
129
129
|
it('indexer', () => {
|
|
130
|
-
assert.deepStrictEqual(inspect(parser('1. [#a]')), [['<ol><li
|
|
130
|
+
assert.deepStrictEqual(inspect(parser('1. [#a]')), [['<ol><li><a class="index indexer" href="#index::a" data-index="">a</a></li></ol>'], '']);
|
|
131
131
|
assert.deepStrictEqual(inspect(parser('1. a [#]')), [['<ol><li>a<span class="indexer" data-index=""></span></li></ol>'], '']);
|
|
132
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
|
|
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
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
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
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>'], '']);
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { OListParser } from '../block';
|
|
2
2
|
import { Parser } from '../../combinator/data/parser';
|
|
3
|
-
import { union, inits, subsequence, some, creation, state, block, line, validate, indent, focus, rewrite, open, match, fallback, lazy, fmap } from '../../combinator';
|
|
3
|
+
import { union, inits, subsequence, some, creation, state, block, line, validate, indent, focus, rewrite, open, close, match, trim, fallback, lazy, fmap } from '../../combinator';
|
|
4
4
|
import { checkbox, ulist_, fillFirstLine } from './ulist';
|
|
5
5
|
import { ilist_ } from './ilist';
|
|
6
6
|
import { inline, indexee, indexer } from '../inline';
|
|
7
|
+
import { index } from '../inline/extension/index';
|
|
7
8
|
import { contentline } from '../source';
|
|
8
9
|
import { State } from '../context';
|
|
9
10
|
import { visualize, trimBlank } from '../visibility';
|
|
@@ -27,17 +28,22 @@ export const olist: OListParser = lazy(() => block(validate(
|
|
|
27
28
|
export const olist_: OListParser = lazy(() => block(union([
|
|
28
29
|
match(
|
|
29
30
|
openers['.'],
|
|
30
|
-
memoize(ms => list(type(ms[1]), '.'), ms =>
|
|
31
|
+
memoize(ms => list(type(ms[1]), '.'), ms => idx(ms[1]), [])),
|
|
31
32
|
match(
|
|
32
33
|
openers['('],
|
|
33
|
-
memoize(ms => list(type(ms[1]), '('), ms =>
|
|
34
|
+
memoize(ms => list(type(ms[1]), '('), ms => idx(ms[1]), [])),
|
|
34
35
|
])));
|
|
35
36
|
|
|
36
37
|
const list = (type: string, form: string): OListParser.ListParser => fmap(
|
|
37
38
|
some(creation(1, false, union([
|
|
38
39
|
indexee(fmap(fallback(
|
|
39
40
|
inits([
|
|
40
|
-
line(open(heads[form], subsequence([checkbox,
|
|
41
|
+
line(open(heads[form], subsequence([checkbox, union([
|
|
42
|
+
trim(fmap(close(union([index]), /^$/), ([el]) => [
|
|
43
|
+
define(el, { class: void el.classList.add('indexer'), 'data-index': '' })
|
|
44
|
+
])),
|
|
45
|
+
trimBlank(visualize(some(union([indexer, inline])))),
|
|
46
|
+
])]), true)),
|
|
41
47
|
indent(union([ulist_, olist_, ilist_])),
|
|
42
48
|
]),
|
|
43
49
|
invalid),
|
|
@@ -67,7 +73,7 @@ export const invalid = rewrite(
|
|
|
67
73
|
}, source.replace('\n', ''))
|
|
68
74
|
], '']);
|
|
69
75
|
|
|
70
|
-
function
|
|
76
|
+
function idx(value: string): number {
|
|
71
77
|
switch (value) {
|
|
72
78
|
case 'i':
|
|
73
79
|
return 1;
|
|
@@ -67,10 +67,10 @@ describe('Unit: parser/block/ulist', () => {
|
|
|
67
67
|
});
|
|
68
68
|
|
|
69
69
|
it('indexer', () => {
|
|
70
|
-
assert.deepStrictEqual(inspect(parser('- [#a]')), [['<ul><li
|
|
70
|
+
assert.deepStrictEqual(inspect(parser('- [#a]')), [['<ul><li><a class="index indexer" href="#index::a" data-index="">a</a></li></ul>'], '']);
|
|
71
71
|
assert.deepStrictEqual(inspect(parser('- a [#]')), [['<ul><li>a<span class="indexer" data-index=""></span></li></ul>'], '']);
|
|
72
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
|
|
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
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
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
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>'], '']);
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { UListParser } from '../block';
|
|
2
|
-
import { union, inits, subsequence, some, creation, state, block, line, validate, indent, focus, open, fallback, lazy, fmap } from '../../combinator';
|
|
2
|
+
import { union, inits, subsequence, some, creation, state, block, line, validate, indent, focus, open, close, trim, fallback, lazy, fmap } from '../../combinator';
|
|
3
3
|
import { olist_, invalid } from './olist';
|
|
4
4
|
import { ilist_ } from './ilist';
|
|
5
5
|
import { inline, indexer, indexee } from '../inline';
|
|
6
|
+
import { index } from '../inline/extension/index';
|
|
6
7
|
import { State } from '../context';
|
|
7
8
|
import { visualize, trimBlank } from '../visibility';
|
|
8
9
|
import { unshift } from 'spica/array';
|
|
9
|
-
import { html, defrag } from 'typed-dom/dom';
|
|
10
|
+
import { html, define, defrag } from 'typed-dom/dom';
|
|
10
11
|
|
|
11
12
|
export const ulist: UListParser = lazy(() => block(validate(
|
|
12
13
|
/^-(?=[^\S\n]|\n[^\S\n]*\S)/,
|
|
@@ -18,7 +19,12 @@ export const ulist_: UListParser = lazy(() => block(fmap(validate(
|
|
|
18
19
|
some(creation(1, false, union([
|
|
19
20
|
indexee(fmap(fallback(
|
|
20
21
|
inits([
|
|
21
|
-
line(open(/^-(?:$|\s)/, subsequence([checkbox,
|
|
22
|
+
line(open(/^-(?:$|\s)/, subsequence([checkbox, union([
|
|
23
|
+
trim(fmap(close(union([index]), /^$/), ([el]) => [
|
|
24
|
+
define(el, { class: void el.classList.add('indexer'), 'data-index': '' })
|
|
25
|
+
])),
|
|
26
|
+
trimBlank(visualize(some(union([indexer, inline])))),
|
|
27
|
+
])]), true)),
|
|
22
28
|
indent(union([ulist_, olist_, ilist_])),
|
|
23
29
|
]),
|
|
24
30
|
invalid),
|
|
@@ -27,8 +27,7 @@ export const index: IndexParser = lazy(() => validate('[#', fmap(indexee(surroun
|
|
|
27
27
|
id: el.id ? null : undefined,
|
|
28
28
|
class: 'index',
|
|
29
29
|
href: el.id ? `#${el.id}` : undefined,
|
|
30
|
-
},
|
|
31
|
-
el.childNodes),
|
|
30
|
+
}),
|
|
32
31
|
])));
|
|
33
32
|
|
|
34
33
|
const signature: IndexParser.SignatureParser = lazy(() => creation(fmap(open(
|
|
@@ -32,7 +32,7 @@ assert(identity(undefined, '0'.repeat(100 - 1) + 1, 'mark')!.slice(6) === '0'.re
|
|
|
32
32
|
assert(identity(undefined, '0'.repeat(100) + 1, 'mark')!.slice(6) === '0'.repeat(50) + '...' + '0'.repeat(47 - 1) + 1);
|
|
33
33
|
assert(identity(undefined, '0'.repeat(200) + 1, 'mark')!.slice(6) === '0'.repeat(50) + '...' + '0'.repeat(47 - 1) + 1);
|
|
34
34
|
|
|
35
|
-
export function index(source: Element
|
|
35
|
+
export function index(source: Element, optional = false): string {
|
|
36
36
|
assert(source instanceof DocumentFragment || !source.matches('.indexer'));
|
|
37
37
|
assert(source.querySelectorAll(':scope > .indexer').length <= 1);
|
|
38
38
|
if (!source.firstChild) return '';
|
|
@@ -39,10 +39,7 @@ function attributes(ns: (string | HTMLElement)[]): Record<string, string | undef
|
|
|
39
39
|
case '\n':
|
|
40
40
|
const abbr = ns[1] as string;
|
|
41
41
|
ns[0] = ns[1] = '';
|
|
42
|
-
return {
|
|
43
|
-
class: 'reference',
|
|
44
|
-
'data-abbr': abbr,
|
|
45
|
-
};
|
|
42
|
+
return { class: 'reference', 'data-abbr': abbr };
|
|
46
43
|
default:
|
|
47
44
|
return { class: 'reference' };
|
|
48
45
|
}
|