securemark 0.274.3 → 0.275.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/index.js +71 -29
- package/markdown.d.ts +14 -4
- package/package.json +8 -8
- package/src/parser/api/parse.test.ts +2 -2
- 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 +44 -9
- package/src/parser/inline/mark.ts +2 -2
- package/src/parser/inline/reference.ts +1 -4
- package/src/parser/processor/figure.test.ts +7 -4
- package/src/parser/processor/note.ts +14 -13
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! securemark v0.
|
|
1
|
+
/*! securemark v0.275.0 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
|
|
2
2
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
3
3
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
4
4
|
module.exports = factory(require("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)
|
|
@@ -6161,7 +6169,7 @@ const bracket = (0, combinator_1.lazy)(() => (0, combinator_1.creation)((0, comb
|
|
|
6161
6169
|
Object.defineProperty(exports, "__esModule", ({
|
|
6162
6170
|
value: true
|
|
6163
6171
|
}));
|
|
6164
|
-
exports.text = exports.index = exports.identity = exports.indexee = void 0;
|
|
6172
|
+
exports.text = exports.signature = exports.index = exports.identity = exports.indexee = void 0;
|
|
6165
6173
|
const combinator_1 = __webpack_require__(2087);
|
|
6166
6174
|
const memoize_1 = __webpack_require__(1808);
|
|
6167
6175
|
const dom_1 = __webpack_require__(3252);
|
|
@@ -6173,17 +6181,18 @@ function indexee(parser, optional) {
|
|
|
6173
6181
|
})]);
|
|
6174
6182
|
}
|
|
6175
6183
|
exports.indexee = indexee;
|
|
6176
|
-
function identity(id, text,
|
|
6184
|
+
function identity(id, text, type = 'index') {
|
|
6177
6185
|
if (id === '') return undefined;
|
|
6178
6186
|
text &&= text.trim().replace(/\s+/g, '_');
|
|
6179
6187
|
if (text === '') return undefined;
|
|
6188
|
+
if (text.length <= 100 || type === '') return `${type}:${id ?? ''}:${text}`;
|
|
6180
6189
|
const cs = [...text];
|
|
6181
|
-
if (cs.length <= 100) return `${
|
|
6182
|
-
switch (
|
|
6190
|
+
if (cs.length <= 100) return `${type}:${id ?? ''}:${text}`;
|
|
6191
|
+
switch (type) {
|
|
6183
6192
|
case 'index':
|
|
6184
|
-
return `${
|
|
6193
|
+
return `${type}:${id ?? ''}:${cs.slice(0, 97).join('')}...`;
|
|
6185
6194
|
case 'mark':
|
|
6186
|
-
return `${
|
|
6195
|
+
return `${type}:${id ?? ''}:${cs.slice(0, 50).join('')}...${cs.slice(-47).join('')}`;
|
|
6187
6196
|
}
|
|
6188
6197
|
}
|
|
6189
6198
|
exports.identity = identity;
|
|
@@ -6193,9 +6202,43 @@ function index(source, optional = false) {
|
|
|
6193
6202
|
const index = indexer?.getAttribute('data-index');
|
|
6194
6203
|
if (index) return index;
|
|
6195
6204
|
if (index === '' && optional) return '';
|
|
6196
|
-
return (
|
|
6205
|
+
return signature(source);
|
|
6197
6206
|
}
|
|
6198
6207
|
exports.index = index;
|
|
6208
|
+
function signature(source) {
|
|
6209
|
+
const target = source.cloneNode(true);
|
|
6210
|
+
for (let es = target.querySelectorAll('code[data-src], .math[data-src], .label[data-label], .comment, rt, rp, br, .annotation, .reference, .checkbox, ul, ol'), len = es.length, i = 0; i < len; ++i) {
|
|
6211
|
+
const el = es[i];
|
|
6212
|
+
switch (el.tagName) {
|
|
6213
|
+
case 'CODE':
|
|
6214
|
+
el.replaceWith(el.getAttribute('data-src'));
|
|
6215
|
+
continue;
|
|
6216
|
+
case 'RT':
|
|
6217
|
+
case 'RP':
|
|
6218
|
+
case 'BR':
|
|
6219
|
+
case 'UL':
|
|
6220
|
+
case 'OL':
|
|
6221
|
+
el.remove();
|
|
6222
|
+
continue;
|
|
6223
|
+
}
|
|
6224
|
+
switch (el.className) {
|
|
6225
|
+
case 'math':
|
|
6226
|
+
el.replaceWith(el.getAttribute('data-src'));
|
|
6227
|
+
continue;
|
|
6228
|
+
case 'label':
|
|
6229
|
+
el.replaceWith(`[$${el.getAttribute('data-label').replace('$', '')}]`);
|
|
6230
|
+
continue;
|
|
6231
|
+
case 'comment':
|
|
6232
|
+
case 'checkbox':
|
|
6233
|
+
case 'annotation':
|
|
6234
|
+
case 'reference':
|
|
6235
|
+
el.remove();
|
|
6236
|
+
continue;
|
|
6237
|
+
}
|
|
6238
|
+
}
|
|
6239
|
+
return target.textContent.trim();
|
|
6240
|
+
}
|
|
6241
|
+
exports.signature = signature;
|
|
6199
6242
|
exports.text = (0, memoize_1.reduce)(source => {
|
|
6200
6243
|
const target = source.cloneNode(true);
|
|
6201
6244
|
for (let es = target.querySelectorAll('code[data-src], .math[data-src], .comment, rt, rp, br, .annotation, .reference, .checkbox, ul, ol'), len = es.length, i = 0; i < len; ++i) {
|
|
@@ -6224,8 +6267,6 @@ exports.text = (0, memoize_1.reduce)(source => {
|
|
|
6224
6267
|
continue;
|
|
6225
6268
|
}
|
|
6226
6269
|
}
|
|
6227
|
-
// Better:
|
|
6228
|
-
//return target.innerText;
|
|
6229
6270
|
return target.textContent;
|
|
6230
6271
|
});
|
|
6231
6272
|
|
|
@@ -6586,7 +6627,7 @@ exports.mark = (0, combinator_1.lazy)(() => (0, combinator_1.surround)((0, sourc
|
|
|
6586
6627
|
}) => {
|
|
6587
6628
|
const el = (0, dom_1.html)('mark', (0, dom_1.defrag)(bs));
|
|
6588
6629
|
return [[(0, dom_1.define)(el, {
|
|
6589
|
-
id: state & (256 /* State.annotation */ | 128 /* State.reference */) ? undefined : (0, indexee_1.identity)(id, (0, indexee_1.
|
|
6630
|
+
id: state & (256 /* State.annotation */ | 128 /* State.reference */) ? undefined : (0, indexee_1.identity)(id, (0, indexee_1.signature)(el), 'mark')
|
|
6590
6631
|
}), el.id && (0, dom_1.html)('a', {
|
|
6591
6632
|
href: `#${el.id}`
|
|
6592
6633
|
})], rest];
|
|
@@ -7106,7 +7147,7 @@ function build(syntax, marker, splitter = '') {
|
|
|
7106
7147
|
}
|
|
7107
7148
|
}
|
|
7108
7149
|
const abbr = ref.getAttribute('data-abbr') || undefined;
|
|
7109
|
-
const identifier = (0, indexee_1.identity)(undefined, abbr
|
|
7150
|
+
const identifier = abbr ? (0, indexee_1.identity)(undefined, abbr.match(/^(?:\S+ )+?(?:(?:January|February|March|April|May|June|August|September|October|November|December) \d{1,2}(?:-\d{0,2})?, \d{1,4}(?:-\d{0,4})?[a-z]?|n\.d\.)(?=,|$)/)?.[0] ?? abbr.match(/^[^,\s]+(?:,? [^,\s]+)*?(?: \d{1,4}(?:-\d{0,4})?[a-z]?(?=,|$)|(?=,(?: [a-z]+\.?)? [0-9]))/)?.[0] ?? abbr, '')?.slice(2) || '' : (0, indexee_1.identity)(undefined, (0, indexee_1.signature)(ref.firstElementChild), 'mark')?.slice(6) || '';
|
|
7110
7151
|
const refSubindex = refSubindexes.get(identifier) + 1 || 1;
|
|
7111
7152
|
refSubindexes.set(identifier, refSubindex);
|
|
7112
7153
|
const refId = opts.id !== '' ? `${syntax}:${opts.id ?? ''}:ref:${identifier}:${refSubindex}` : undefined;
|
|
@@ -7123,7 +7164,7 @@ function build(syntax, marker, splitter = '') {
|
|
|
7123
7164
|
initial && defs.set(identifier, def);
|
|
7124
7165
|
const defIndex = initial ? total + defs.size : defIndexes.get(def);
|
|
7125
7166
|
initial && defIndexes.set(def, defIndex);
|
|
7126
|
-
const title = initial ? (0, indexee_1.text)(ref.firstElementChild) : titles.get(identifier);
|
|
7167
|
+
const title = initial ? (0, indexee_1.text)(ref.firstElementChild).trim() : titles.get(identifier);
|
|
7127
7168
|
initial && titles.set(identifier, title);
|
|
7128
7169
|
ref.firstElementChild.hasAttribute('hidden') ? ref.lastElementChild.remove() : ref.firstElementChild.setAttribute('hidden', '');
|
|
7129
7170
|
(0, dom_1.define)(ref, {
|
|
@@ -7150,7 +7191,7 @@ function build(syntax, marker, splitter = '') {
|
|
|
7150
7191
|
}, marker(defIndex, abbr)));
|
|
7151
7192
|
def.lastElementChild.appendChild((0, dom_1.html)('a', {
|
|
7152
7193
|
href: refId && `#${refId}`,
|
|
7153
|
-
title: abbr && (0, indexee_1.text)(
|
|
7194
|
+
title: abbr && (initial ? title : (0, indexee_1.text)(ref.firstElementChild).trim()) || undefined
|
|
7154
7195
|
}, `^${++refIndex}`));
|
|
7155
7196
|
}
|
|
7156
7197
|
if (note || defs.size > 0) {
|
|
@@ -8409,7 +8450,7 @@ function unlink(h) {
|
|
|
8409
8450
|
/***/ 3252:
|
|
8410
8451
|
/***/ (function(module) {
|
|
8411
8452
|
|
|
8412
|
-
/*! typed-dom v0.0.
|
|
8453
|
+
/*! typed-dom v0.0.333 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
|
|
8413
8454
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
8414
8455
|
if(true)
|
|
8415
8456
|
module.exports = factory();
|
|
@@ -8522,7 +8563,7 @@ exports.reduce = reduce;
|
|
|
8522
8563
|
Object.defineProperty(exports, "__esModule", ({
|
|
8523
8564
|
value: true
|
|
8524
8565
|
}));
|
|
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;
|
|
8566
|
+
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
8567
|
const alias_1 = __nested_webpack_require_4668__(5406);
|
|
8527
8568
|
const memoize_1 = __nested_webpack_require_4668__(1808);
|
|
8528
8569
|
var caches;
|
|
@@ -8547,6 +8588,7 @@ function frag(children) {
|
|
|
8547
8588
|
exports.frag = frag;
|
|
8548
8589
|
exports.html = element(document, "HTML" /* NS.HTML */);
|
|
8549
8590
|
exports.svg = element(document, "SVG" /* NS.SVG */);
|
|
8591
|
+
exports.math = element(document, "MathML" /* NS.Math */);
|
|
8550
8592
|
function text(source) {
|
|
8551
8593
|
return document.createTextNode(source);
|
|
8552
8594
|
}
|
|
@@ -8558,7 +8600,7 @@ function element(context, ns) {
|
|
|
8558
8600
|
}
|
|
8559
8601
|
exports.element = element;
|
|
8560
8602
|
function elem(context, ns, tag, attrs) {
|
|
8561
|
-
if (!('createElement' in context)) throw new Error(`TypedDOM: Scoped custom elements are not supported on this browser
|
|
8603
|
+
if (!('createElement' in context)) throw new Error(`TypedDOM: Scoped custom elements are not supported on this browser`);
|
|
8562
8604
|
const opts = 'is' in attrs ? {
|
|
8563
8605
|
is: attrs['is']
|
|
8564
8606
|
} : undefined;
|
|
@@ -8567,7 +8609,7 @@ function elem(context, ns, tag, attrs) {
|
|
|
8567
8609
|
return context.createElement(tag, opts);
|
|
8568
8610
|
case "SVG" /* NS.SVG */:
|
|
8569
8611
|
return context.createElementNS('http://www.w3.org/2000/svg', tag, opts);
|
|
8570
|
-
case "MathML" /* NS.
|
|
8612
|
+
case "MathML" /* NS.Math */:
|
|
8571
8613
|
return context.createElementNS('http://www.w3.org/1998/Math/MathML', tag, opts);
|
|
8572
8614
|
}
|
|
8573
8615
|
}
|
|
@@ -8609,10 +8651,10 @@ function defineAttrs(el, attrs) {
|
|
|
8609
8651
|
}
|
|
8610
8652
|
continue;
|
|
8611
8653
|
case 'function':
|
|
8612
|
-
if (name.length < 3) throw new Error(`TypedDOM: Attribute names for event listeners must have an event name but got "${name}"
|
|
8654
|
+
if (name.length < 3) throw new Error(`TypedDOM: Attribute names for event listeners must have an event name but got "${name}"`);
|
|
8613
8655
|
const names = name.split(/\s+/);
|
|
8614
8656
|
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}"
|
|
8657
|
+
if (!name.startsWith('on')) throw new Error(`TypedDOM: Attribute names for event listeners must start with "on" but got "${name}"`);
|
|
8616
8658
|
const type = name.slice(2).toLowerCase();
|
|
8617
8659
|
el.addEventListener(type, value, {
|
|
8618
8660
|
passive: ['wheel', 'mousewheel', 'touchstart', 'touchmove', 'touchend', 'touchcancel'].includes(type)
|
|
@@ -8708,7 +8750,7 @@ exports.defrag = defrag;
|
|
|
8708
8750
|
/******/ var __webpack_module_cache__ = {};
|
|
8709
8751
|
/******/
|
|
8710
8752
|
/******/ // The require function
|
|
8711
|
-
/******/ function
|
|
8753
|
+
/******/ function __nested_webpack_require_11657__(moduleId) {
|
|
8712
8754
|
/******/ // Check if module is in cache
|
|
8713
8755
|
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
8714
8756
|
/******/ if (cachedModule !== undefined) {
|
|
@@ -8722,7 +8764,7 @@ exports.defrag = defrag;
|
|
|
8722
8764
|
/******/ };
|
|
8723
8765
|
/******/
|
|
8724
8766
|
/******/ // Execute the module function
|
|
8725
|
-
/******/ __webpack_modules__[moduleId](module, module.exports,
|
|
8767
|
+
/******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_11657__);
|
|
8726
8768
|
/******/
|
|
8727
8769
|
/******/ // Return the exports of the module
|
|
8728
8770
|
/******/ return module.exports;
|
|
@@ -8733,7 +8775,7 @@ exports.defrag = defrag;
|
|
|
8733
8775
|
/******/ // startup
|
|
8734
8776
|
/******/ // Load entry module and return exports
|
|
8735
8777
|
/******/ // This entry module is referenced by other modules so it can't be inlined
|
|
8736
|
-
/******/ var __nested_webpack_exports__ =
|
|
8778
|
+
/******/ var __nested_webpack_exports__ = __nested_webpack_require_11657__(7521);
|
|
8737
8779
|
/******/
|
|
8738
8780
|
/******/ return __nested_webpack_exports__;
|
|
8739
8781
|
/******/ })()
|
|
@@ -8745,7 +8787,7 @@ exports.defrag = defrag;
|
|
|
8745
8787
|
/***/ 6120:
|
|
8746
8788
|
/***/ (function(module) {
|
|
8747
8789
|
|
|
8748
|
-
/*! typed-dom v0.0.
|
|
8790
|
+
/*! typed-dom v0.0.333 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
|
|
8749
8791
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
8750
8792
|
if(true)
|
|
8751
8793
|
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.
|
|
3
|
+
"version": "0.275.0",
|
|
4
4
|
"description": "Secure markdown renderer working on browsers for user input data.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"homepage": "https://github.com/falsandtru/securemark",
|
|
@@ -34,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": {
|
|
@@ -207,8 +207,8 @@ describe('Unit: parser/api/parse', () => {
|
|
|
207
207
|
[...parse('$-a\n$$\n$$\n\n(($-a[[^B]]))[[^B|$-a]]', { notes }).children].map(el => el.outerHTML),
|
|
208
208
|
[
|
|
209
209
|
'<figure data-type="math" data-label="$-a" data-group="$" data-number="1" id="label:$-a"><figcaption><span class="figindex">(1)</span><span class="figtext"></span></figcaption><div><div class="math" translate="no">$$\n$$</div></div></figure>',
|
|
210
|
-
'<p><sup class="annotation" id="annotation::ref:
|
|
211
|
-
'<ol class="annotations"><li id="annotation::def:
|
|
210
|
+
'<p><sup class="annotation" id="annotation::ref:[$-a]:1" title="(1)"><span hidden=""><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" data-abbr="B"><span></span></sup></span><a href="#annotation::def:[$-a]:1">*1</a></sup><sup class="reference" data-abbr="B" id="reference::ref:B:1" title="(1)"><span hidden=""><a class="label" data-label="$-a" href="#label:$-a">(1)</a></span><a href="#reference::def:B">[B]</a></sup></p>',
|
|
211
|
+
'<ol class="annotations"><li id="annotation::def:[$-a]:1" data-marker="*1"><span><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" data-abbr="B" id="reference::ref:B:2" title="(1)"><span hidden=""></span><a href="#reference::def:B">[B]</a></sup></span><sup><a href="#annotation::ref:[$-a]:1">^1</a></sup></li></ol>',
|
|
212
212
|
]);
|
|
213
213
|
assert.deepStrictEqual(
|
|
214
214
|
notes.references.outerHTML,
|
|
@@ -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(
|
|
@@ -9,19 +9,20 @@ export function indexee(parser: Parser<HTMLElement, MarkdownParser.Context>, opt
|
|
|
9
9
|
return fmap(parser, ([el], _, { id }) => [define(el, { id: identity(id, index(el, optional)) })]);
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export function identity(id: string | undefined, text: string,
|
|
12
|
+
export function identity(id: string | undefined, text: string, type: 'index' | 'mark' | '' = 'index'): string | undefined {
|
|
13
13
|
assert(!id?.match(/[^0-9a-z/-]/i));
|
|
14
14
|
assert(!text.includes('\n'));
|
|
15
15
|
if (id === '') return undefined;
|
|
16
16
|
text &&= text.trim().replace(/\s+/g, '_');
|
|
17
17
|
if (text === '') return undefined;
|
|
18
|
+
if (text.length <= 100 || type === '') return `${type}:${id ?? ''}:${text}`;
|
|
18
19
|
const cs = [...text];
|
|
19
|
-
if (cs.length <= 100) return `${
|
|
20
|
-
switch (
|
|
20
|
+
if (cs.length <= 100) return `${type}:${id ?? ''}:${text}`;
|
|
21
|
+
switch (type) {
|
|
21
22
|
case 'index':
|
|
22
|
-
return `${
|
|
23
|
+
return `${type}:${id ?? ''}:${cs.slice(0, 97).join('')}...`;
|
|
23
24
|
case 'mark':
|
|
24
|
-
return `${
|
|
25
|
+
return `${type}:${id ?? ''}:${cs.slice(0, 50).join('')}...${cs.slice(-47).join('')}`;
|
|
25
26
|
}
|
|
26
27
|
assert(false);
|
|
27
28
|
}
|
|
@@ -32,7 +33,7 @@ assert(identity(undefined, '0'.repeat(100 - 1) + 1, 'mark')!.slice(6) === '0'.re
|
|
|
32
33
|
assert(identity(undefined, '0'.repeat(100) + 1, 'mark')!.slice(6) === '0'.repeat(50) + '...' + '0'.repeat(47 - 1) + 1);
|
|
33
34
|
assert(identity(undefined, '0'.repeat(200) + 1, 'mark')!.slice(6) === '0'.repeat(50) + '...' + '0'.repeat(47 - 1) + 1);
|
|
34
35
|
|
|
35
|
-
export function index(source: Element
|
|
36
|
+
export function index(source: Element, optional = false): string {
|
|
36
37
|
assert(source instanceof DocumentFragment || !source.matches('.indexer'));
|
|
37
38
|
assert(source.querySelectorAll(':scope > .indexer').length <= 1);
|
|
38
39
|
if (!source.firstChild) return '';
|
|
@@ -40,7 +41,43 @@ export function index(source: Element | DocumentFragment, optional = false): str
|
|
|
40
41
|
const index = indexer?.getAttribute('data-index');
|
|
41
42
|
if (index) return index;
|
|
42
43
|
if (index === '' && optional) return '';
|
|
43
|
-
return
|
|
44
|
+
return signature(source);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function signature(source: Element | DocumentFragment): string {
|
|
48
|
+
assert(!navigator.userAgent.includes('Chrome') || !source.querySelector('br:not(:has(+ :is(ul, ol)))'));
|
|
49
|
+
const target = source.cloneNode(true) as typeof source;
|
|
50
|
+
for (let es = target.querySelectorAll('code[data-src], .math[data-src], .label[data-label], .comment, rt, rp, br, .annotation, .reference, .checkbox, ul, ol'),
|
|
51
|
+
len = es.length, i = 0; i < len; ++i) {
|
|
52
|
+
const el = es[i];
|
|
53
|
+
switch (el.tagName) {
|
|
54
|
+
case 'CODE':
|
|
55
|
+
el.replaceWith(el.getAttribute('data-src')!);
|
|
56
|
+
continue;
|
|
57
|
+
case 'RT':
|
|
58
|
+
case 'RP':
|
|
59
|
+
case 'BR':
|
|
60
|
+
case 'UL':
|
|
61
|
+
case 'OL':
|
|
62
|
+
el.remove();
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
switch (el.className) {
|
|
66
|
+
case 'math':
|
|
67
|
+
el.replaceWith(el.getAttribute('data-src')!);
|
|
68
|
+
continue;
|
|
69
|
+
case 'label':
|
|
70
|
+
el.replaceWith(`[$${el.getAttribute('data-label')!.replace('$', '')}]`);
|
|
71
|
+
continue;
|
|
72
|
+
case 'comment':
|
|
73
|
+
case 'checkbox':
|
|
74
|
+
case 'annotation':
|
|
75
|
+
case 'reference':
|
|
76
|
+
el.remove();
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return target.textContent!.trim();
|
|
44
81
|
}
|
|
45
82
|
|
|
46
83
|
export const text = reduce((source: Element | DocumentFragment): string => {
|
|
@@ -73,7 +110,5 @@ export const text = reduce((source: Element | DocumentFragment): string => {
|
|
|
73
110
|
continue;
|
|
74
111
|
}
|
|
75
112
|
}
|
|
76
|
-
// Better:
|
|
77
|
-
//return target.innerText;
|
|
78
113
|
return target.textContent!;
|
|
79
114
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MarkParser } from '../inline';
|
|
2
2
|
import { union, some, syntax, constraint, surround, open, lazy } from '../../combinator';
|
|
3
3
|
import { inline } from '../inline';
|
|
4
|
-
import { identity,
|
|
4
|
+
import { identity, signature } from './extension/indexee';
|
|
5
5
|
import { str } from '../source';
|
|
6
6
|
import { startTight, blankWith } from '../visibility';
|
|
7
7
|
import { Syntax, State } from '../context';
|
|
@@ -23,7 +23,7 @@ export const mark: MarkParser = lazy(() => surround(
|
|
|
23
23
|
define(el, {
|
|
24
24
|
id: state! & (State.annotation | State.reference)
|
|
25
25
|
? undefined
|
|
26
|
-
: identity(id,
|
|
26
|
+
: identity(id, signature(el), 'mark'),
|
|
27
27
|
}),
|
|
28
28
|
el.id && html('a', { href: `#${el.id}` }),
|
|
29
29
|
], rest];
|
|
@@ -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
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { figure } from './figure';
|
|
2
|
+
import { ParserOptions } from '../../..';
|
|
2
3
|
import { parse as parse_ } from '../../parser';
|
|
3
4
|
import { html } from 'typed-dom/dom';
|
|
4
5
|
import { normalize } from '../../debug.test';
|
|
5
6
|
|
|
6
|
-
const parse = (s: string) => parse_(s, { test: true });
|
|
7
|
+
const parse = (s: string, o?: ParserOptions) => parse_(s, { test: true, ...o });
|
|
7
8
|
|
|
8
9
|
describe('Unit: parser/processor/figure', () => {
|
|
9
10
|
describe('figure', () => {
|
|
@@ -278,15 +279,17 @@ describe('Unit: parser/processor/figure', () => {
|
|
|
278
279
|
it('id', () => {
|
|
279
280
|
const target = parse([
|
|
280
281
|
'$test-a\n> ',
|
|
281
|
-
'
|
|
282
|
-
|
|
282
|
+
'==$test-a==',
|
|
283
|
+
'- $test-a',
|
|
284
|
+
].join('\n\n'), { id: '0' });
|
|
283
285
|
for (let i = 0; i < 3; ++i) {
|
|
284
286
|
[...figure(target, undefined, { id: '0' })];
|
|
285
287
|
assert.deepStrictEqual(
|
|
286
288
|
[...target.children].map(el => el.outerHTML),
|
|
287
289
|
[
|
|
288
290
|
'<figure data-type="quote" data-label="test-a" data-group="test" data-number="1" id="label:0:test-a"><figcaption><span class="figindex">Test 1. </span><span class="figtext"></span></figcaption><div><blockquote></blockquote></div></figure>',
|
|
289
|
-
'<p><a class="label" data-label="test-a" href="#label:0:test-a">Test 1</a></p>',
|
|
291
|
+
'<p><mark id="mark:0:[$test-a]"><a class="label" data-label="test-a" href="#label:0:test-a">Test 1</a></mark><a href="#mark:0:[$test-a]"></a></p>',
|
|
292
|
+
'<ul><li id="index:0:[$test-a]"><a class="label" data-label="test-a" href="#label:0:test-a">Test 1</a></li></ul>',
|
|
290
293
|
]);
|
|
291
294
|
}
|
|
292
295
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { identity, text } from '../inline/extension/indexee';
|
|
1
|
+
import { identity, signature, text } from '../inline/extension/indexee';
|
|
2
2
|
import { markInvalid, unmarkInvalid } from '../util';
|
|
3
|
-
import {
|
|
3
|
+
import { html, define } from 'typed-dom/dom';
|
|
4
4
|
|
|
5
5
|
export function* note(
|
|
6
6
|
target: ParentNode & Node,
|
|
@@ -70,15 +70,16 @@ function build(
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
const abbr = ref.getAttribute('data-abbr') || undefined;
|
|
73
|
-
const identifier =
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
const identifier = abbr
|
|
74
|
+
? identity(
|
|
75
|
+
undefined,
|
|
76
|
+
(
|
|
77
|
+
abbr.match(/^(?:\S+ )+?(?:(?:January|February|March|April|May|June|August|September|October|November|December) \d{1,2}(?:-\d{0,2})?, \d{1,4}(?:-\d{0,4})?[a-z]?|n\.d\.)(?=,|$)/)?.[0] ??
|
|
78
|
+
abbr.match(/^[^,\s]+(?:,? [^,\s]+)*?(?: \d{1,4}(?:-\d{0,4})?[a-z]?(?=,|$)|(?=,(?: [a-z]+\.?)? [0-9]))/)?.[0] ??
|
|
79
|
+
abbr
|
|
80
|
+
),
|
|
81
|
+
'')?.slice(2) || ''
|
|
82
|
+
: identity(undefined, signature(ref.firstElementChild!), 'mark')?.slice(6) || '';
|
|
82
83
|
const refSubindex = refSubindexes.get(identifier)! + 1 || 1;
|
|
83
84
|
refSubindexes.set(identifier, refSubindex);
|
|
84
85
|
const refId = opts.id !== ''
|
|
@@ -107,7 +108,7 @@ function build(
|
|
|
107
108
|
: defIndexes.get(def)!;
|
|
108
109
|
initial && defIndexes.set(def, defIndex);
|
|
109
110
|
const title = initial
|
|
110
|
-
? text(ref.firstElementChild!)
|
|
111
|
+
? text(ref.firstElementChild!).trim()
|
|
111
112
|
: titles.get(identifier)!;
|
|
112
113
|
initial && titles.set(identifier, title);
|
|
113
114
|
assert(syntax !== 'annotation' || title);
|
|
@@ -139,7 +140,7 @@ function build(
|
|
|
139
140
|
html('a',
|
|
140
141
|
{
|
|
141
142
|
href: refId && `#${refId}`,
|
|
142
|
-
title: abbr && text(
|
|
143
|
+
title: abbr && (initial ? title : text(ref.firstElementChild!).trim()) || undefined,
|
|
143
144
|
},
|
|
144
145
|
`^${++refIndex}`));
|
|
145
146
|
}
|