securemark 0.243.0 → 0.243.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 +4 -0
- package/dist/securemark.js +56 -30
- package/markdown.d.ts +0 -1
- package/package-lock.json +1 -1
- package/package.json +1 -1
- package/src/parser/block/extension/example.ts +1 -1
- package/src/parser/block/extension/fig.ts +1 -1
- package/src/parser/block/extension/figure.test.ts +21 -21
- package/src/parser/block/extension/figure.ts +76 -39
- package/src/parser/block/extension/placeholder.ts +2 -8
- package/src/parser/block/table.ts +2 -2
package/CHANGELOG.md
CHANGED
package/dist/securemark.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! securemark v0.243.
|
|
1
|
+
/*! securemark v0.243.1 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED */
|
|
2
2
|
require = function () {
|
|
3
3
|
function r(e, n, t) {
|
|
4
4
|
function o(i, f) {
|
|
@@ -3609,7 +3609,7 @@ require = function () {
|
|
|
3609
3609
|
const parse_1 = _dereq_('../../api/parse');
|
|
3610
3610
|
const mathblock_1 = _dereq_('../mathblock');
|
|
3611
3611
|
const dom_1 = _dereq_('typed-dom/dom');
|
|
3612
|
-
const opener = /^(~{3,})(?:example\/(\S+)
|
|
3612
|
+
const opener = /^(~{3,})(?:example\/(\S+))?(?!\S)([^\n]*)(?:$|\n)/;
|
|
3613
3613
|
exports.example = (0, combinator_1.creator)(100, (0, combinator_1.block)((0, combinator_1.validate)('~~~', (0, combinator_1.fmap)((0, combinator_1.fence)(opener, 300), ([body, closer, opener, delim, type = 'markdown', param], _, context) => {
|
|
3614
3614
|
if (!closer || param.trimStart())
|
|
3615
3615
|
return [(0, dom_1.html)('pre', {
|
|
@@ -3701,7 +3701,7 @@ require = function () {
|
|
|
3701
3701
|
exports.fig = (0, combinator_1.block)((0, combinator_1.rewrite)(exports.segment, (0, combinator_1.verify)((0, combinator_1.convert)(source => {
|
|
3702
3702
|
const fence = (/^[^\n]*\n!?>+\s/.test(source) && source.match(/^~{3,}(?=[^\S\n]*$)/mg) || []).reduce((max, fence) => fence > max ? fence : max, '~~') + '~';
|
|
3703
3703
|
return `${ fence }figure ${ source }\n\n${ fence }`;
|
|
3704
|
-
}, (0, combinator_1.union)([figure_1.figure])), ([el]) => el.
|
|
3704
|
+
}, (0, combinator_1.union)([figure_1.figure])), ([el]) => el.tagName === 'FIGURE')));
|
|
3705
3705
|
},
|
|
3706
3706
|
{
|
|
3707
3707
|
'../../../combinator': 25,
|
|
@@ -3764,7 +3764,7 @@ require = function () {
|
|
|
3764
3764
|
const dom_1 = _dereq_('typed-dom/dom');
|
|
3765
3765
|
const memoize_1 = _dereq_('spica/memoize');
|
|
3766
3766
|
const array_1 = _dereq_('spica/array');
|
|
3767
|
-
exports.segment = (0, combinator_1.block)((0, combinator_1.match)(/^(~{3,})(?:figure[^\S\n]
|
|
3767
|
+
exports.segment = (0, combinator_1.block)((0, combinator_1.match)(/^(~{3,})(?:figure[^\S\n]|(?=\[?\$))/, (0, memoize_1.memoize)(([, fence], closer = new RegExp(String.raw`^${ fence }[^\S\n]*(?:$|\n)`)) => (0, combinator_1.close)((0, combinator_1.sequence)([
|
|
3768
3768
|
source_1.contentline,
|
|
3769
3769
|
(0, combinator_1.inits)([
|
|
3770
3770
|
(0, combinator_1.union)([
|
|
@@ -3782,10 +3782,10 @@ require = function () {
|
|
|
3782
3782
|
])
|
|
3783
3783
|
])
|
|
3784
3784
|
]), closer), ([, fence]) => fence.length, [])));
|
|
3785
|
-
exports.figure = (0, combinator_1.block)((0, combinator_1.rewrite)(exports.segment, (0, combinator_1.fmap)((0, combinator_1.convert)(source => source.slice(source.
|
|
3785
|
+
exports.figure = (0, combinator_1.block)((0, combinator_1.fallback)((0, combinator_1.rewrite)(exports.segment, (0, combinator_1.fallback)((0, combinator_1.fmap)((0, combinator_1.convert)(source => source.slice(source.match(/^~+(?:figure[^\S\n]+)?/)[0].length, source.trimEnd().lastIndexOf('\n')), (0, combinator_1.sequence)([
|
|
3786
3786
|
(0, combinator_1.line)((0, combinator_1.sequence)([
|
|
3787
3787
|
label_1.label,
|
|
3788
|
-
(0, source_1.str)(
|
|
3788
|
+
(0, source_1.str)(/^(?=\s).*\n/)
|
|
3789
3789
|
])),
|
|
3790
3790
|
(0, combinator_1.inits)([
|
|
3791
3791
|
(0, combinator_1.block)((0, combinator_1.union)([
|
|
@@ -3799,9 +3799,8 @@ require = function () {
|
|
|
3799
3799
|
table_2.table,
|
|
3800
3800
|
blockquote_1.blockquote,
|
|
3801
3801
|
placeholder_1.placeholder,
|
|
3802
|
-
(0, combinator_1.
|
|
3803
|
-
(0, combinator_1.
|
|
3804
|
-
(0, combinator_1.fmap)((0, combinator_1.some)(source_1.contentline), () => [(0, dom_1.html)('br')])
|
|
3802
|
+
(0, combinator_1.line)(inline_1.media),
|
|
3803
|
+
(0, combinator_1.line)(inline_1.shortmedia)
|
|
3805
3804
|
])),
|
|
3806
3805
|
source_1.emptyline,
|
|
3807
3806
|
(0, combinator_1.block)((0, locale_1.localize)((0, combinator_1.context)({ syntax: { inline: { media: false } } }, (0, combinator_1.trim)((0, util_1.visualize)((0, combinator_1.some)(inline_1.inline))))))
|
|
@@ -3809,7 +3808,47 @@ require = function () {
|
|
|
3809
3808
|
])), ([label, param, content, ...caption]) => [(0, dom_1.html)('figure', attributes(label.getAttribute('data-label'), param, content, caption), [
|
|
3810
3809
|
(0, dom_1.html)('figcaption', (0, array_1.unshift)([(0, dom_1.html)('span', { class: 'figindex' })], (0, dom_1.defrag)(caption))),
|
|
3811
3810
|
(0, dom_1.html)('div', [content])
|
|
3812
|
-
])]))
|
|
3811
|
+
])]), (source, context) => {
|
|
3812
|
+
var _a, _b;
|
|
3813
|
+
return [
|
|
3814
|
+
[(0, dom_1.html)('pre', {
|
|
3815
|
+
class: 'invalid',
|
|
3816
|
+
translate: 'no',
|
|
3817
|
+
'data-invalid-syntax': 'figure',
|
|
3818
|
+
...!(0, label_1.segment)((_b = (_a = source.match(/^~+(?:figure[^\S\n]+)?(\[?\$\S+)/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : '', context) && {
|
|
3819
|
+
'data-invalid-type': 'label',
|
|
3820
|
+
'data-invalid-message': 'Invalid label'
|
|
3821
|
+
} || /^~+(?:figure[^\S\n]+)?(\[?\$\S+)[^\S\n]+\S/.test(source) && {
|
|
3822
|
+
'data-invalid-type': 'argument',
|
|
3823
|
+
'data-invalid-message': 'Invalid argument'
|
|
3824
|
+
} || {
|
|
3825
|
+
'data-invalid-type': 'content',
|
|
3826
|
+
'data-invalid-message': 'Invalid content'
|
|
3827
|
+
}
|
|
3828
|
+
}, source)],
|
|
3829
|
+
''
|
|
3830
|
+
];
|
|
3831
|
+
})), (0, combinator_1.fmap)((0, combinator_1.fence)(/^(~{3,})(?:figure|\[?\$\S*)(?!\S)[^\n]*(?:$|\n)/, 300), ([body, closer, opener, delim], _, context) => {
|
|
3832
|
+
var _a, _b;
|
|
3833
|
+
return [(0, dom_1.html)('pre', {
|
|
3834
|
+
class: 'invalid',
|
|
3835
|
+
translate: 'no',
|
|
3836
|
+
'data-invalid-syntax': 'figure',
|
|
3837
|
+
...!closer && {
|
|
3838
|
+
'data-invalid-type': 'fence',
|
|
3839
|
+
'data-invalid-message': `Missing the closing delimiter "${ delim }"`
|
|
3840
|
+
} || !(0, label_1.segment)((_b = (_a = opener.match(/^~+(?:figure[^\S\n]+)?(\[?\$\S+)/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : '', context) && {
|
|
3841
|
+
'data-invalid-type': 'label',
|
|
3842
|
+
'data-invalid-message': 'Invalid label'
|
|
3843
|
+
} || /^~+(?:figure[^\S\n]+)?(\[?\$\S+)[^\S\n]+\S/.test(opener) && {
|
|
3844
|
+
'data-invalid-type': 'argument',
|
|
3845
|
+
'data-invalid-message': 'Invalid argument'
|
|
3846
|
+
} || {
|
|
3847
|
+
'data-invalid-type': 'content',
|
|
3848
|
+
'data-invalid-message': 'Invalid content'
|
|
3849
|
+
}
|
|
3850
|
+
}, `${ opener }${ body }${ closer }`)];
|
|
3851
|
+
})));
|
|
3813
3852
|
function attributes(label, param, content, caption) {
|
|
3814
3853
|
const group = label.split('-', 1)[0];
|
|
3815
3854
|
let type = content.className.split(/\s/)[0];
|
|
@@ -3828,9 +3867,6 @@ require = function () {
|
|
|
3828
3867
|
case 'A':
|
|
3829
3868
|
type = 'media';
|
|
3830
3869
|
break;
|
|
3831
|
-
case 'BR':
|
|
3832
|
-
type = 'invalid';
|
|
3833
|
-
break;
|
|
3834
3870
|
case 'text':
|
|
3835
3871
|
case 'code':
|
|
3836
3872
|
case 'math':
|
|
@@ -3839,15 +3875,12 @@ require = function () {
|
|
|
3839
3875
|
break;
|
|
3840
3876
|
default:
|
|
3841
3877
|
}
|
|
3842
|
-
const invalid =
|
|
3843
|
-
'data-invalid-type': '
|
|
3844
|
-
'data-invalid-message': 'Invalid
|
|
3878
|
+
const invalid = param.trimStart() !== '' && {
|
|
3879
|
+
'data-invalid-type': 'argument',
|
|
3880
|
+
'data-invalid-message': 'Invalid argument'
|
|
3845
3881
|
} || /^[^-]+-(?:[0-9]+\.)*0$/.test(label) && {
|
|
3846
3882
|
'data-invalid-type': 'label',
|
|
3847
3883
|
'data-invalid-message': 'The last part of the fixed label numbers must not be 0'
|
|
3848
|
-
} || param.trimStart() !== '' && {
|
|
3849
|
-
'data-invalid-type': 'argument',
|
|
3850
|
-
'data-invalid-message': 'Invalid argument'
|
|
3851
3884
|
} || group === '$' && (type !== 'math' || caption.length > 0) && {
|
|
3852
3885
|
'data-invalid-type': 'label',
|
|
3853
3886
|
'data-invalid-message': '"$" label group must be used to math formulas with no caption'
|
|
@@ -4008,27 +4041,20 @@ require = function () {
|
|
|
4008
4041
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4009
4042
|
exports.placeholder = exports.segment_ = exports.segment = void 0;
|
|
4010
4043
|
const combinator_1 = _dereq_('../../../combinator');
|
|
4011
|
-
const label_1 = _dereq_('../../inline/extension/label');
|
|
4012
4044
|
const dom_1 = _dereq_('typed-dom/dom');
|
|
4013
4045
|
const opener = /^(~{3,})(?!~)[^\n]*(?:$|\n)/;
|
|
4014
4046
|
exports.segment = (0, combinator_1.block)((0, combinator_1.validate)('~~~', (0, combinator_1.clear)((0, combinator_1.fence)(opener, 300))));
|
|
4015
4047
|
exports.segment_ = (0, combinator_1.block)((0, combinator_1.validate)('~~~', (0, combinator_1.clear)((0, combinator_1.fence)(opener, 300, false))), false);
|
|
4016
|
-
exports.placeholder = (0, combinator_1.block)((0, combinator_1.validate)('~~~', (0, combinator_1.fmap)((0, combinator_1.fence)(opener, Infinity), ([body, closer, opener, delim]
|
|
4048
|
+
exports.placeholder = (0, combinator_1.block)((0, combinator_1.validate)('~~~', (0, combinator_1.fmap)((0, combinator_1.fence)(opener, Infinity), ([body, closer, opener, delim]) => [(0, dom_1.html)('pre', {
|
|
4017
4049
|
class: 'invalid',
|
|
4018
4050
|
translate: 'no',
|
|
4019
4051
|
'data-invalid-syntax': 'extension',
|
|
4020
4052
|
'data-invalid-type': !closer ? 'fence' : 'syntax',
|
|
4021
|
-
'data-invalid-message': !closer ? `Missing the closing delimiter "${ delim }"` : 'Invalid extension name'
|
|
4022
|
-
...closer && (opener.slice(delim.length).split(/\s/, 1)[0] === 'figure' || (0, label_1.segment)(opener.slice(delim.length), context)) && {
|
|
4023
|
-
'data-invalid-syntax': 'figure',
|
|
4024
|
-
'data-invalid-type': 'content',
|
|
4025
|
-
'data-invalid-message': 'Invalid content'
|
|
4026
|
-
}
|
|
4053
|
+
'data-invalid-message': !closer ? `Missing the closing delimiter "${ delim }"` : 'Invalid extension name'
|
|
4027
4054
|
}, `${ opener }${ body }${ closer }`)])));
|
|
4028
4055
|
},
|
|
4029
4056
|
{
|
|
4030
4057
|
'../../../combinator': 25,
|
|
4031
|
-
'../../inline/extension/label': 109,
|
|
4032
4058
|
'typed-dom/dom': 23
|
|
4033
4059
|
}
|
|
4034
4060
|
],
|
|
@@ -4812,9 +4838,9 @@ require = function () {
|
|
|
4812
4838
|
const row = (parser, optional) => (0, combinator_1.creator)((0, combinator_1.fallback)((0, combinator_1.fmap)((0, combinator_1.line)((0, combinator_1.surround)(/^(?=\|)/, (0, combinator_1.some)((0, combinator_1.union)([parser])), /^\|?\s*$/, optional)), es => [(0, dom_1.html)('tr', es)]), (0, combinator_1.rewrite)(source_1.contentline, source => [
|
|
4813
4839
|
[(0, dom_1.html)('tr', {
|
|
4814
4840
|
class: 'invalid',
|
|
4815
|
-
'data-invalid-syntax': '
|
|
4841
|
+
'data-invalid-syntax': 'table-row',
|
|
4816
4842
|
'data-invalid-type': 'syntax',
|
|
4817
|
-
'data-invalid-message': '
|
|
4843
|
+
'data-invalid-message': 'Missing the start symbol of the table row'
|
|
4818
4844
|
}, [(0, dom_1.html)('td', source.replace('\n', ''))])],
|
|
4819
4845
|
''
|
|
4820
4846
|
])));
|
package/markdown.d.ts
CHANGED
package/package-lock.json
CHANGED
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ import { parse } from '../../api/parse';
|
|
|
5
5
|
import { mathblock } from '../mathblock';
|
|
6
6
|
import { html } from 'typed-dom/dom';
|
|
7
7
|
|
|
8
|
-
const opener = /^(~{3,})(?:example\/(\S+)
|
|
8
|
+
const opener = /^(~{3,})(?:example\/(\S+))?(?!\S)([^\n]*)(?:$|\n)/;
|
|
9
9
|
|
|
10
10
|
export const example: ExtensionParser.ExampleParser = creator(100, block(validate('~~~', fmap(
|
|
11
11
|
fence(opener, 300),
|
|
@@ -31,4 +31,4 @@ export const fig: FigParser = block(rewrite(segment, verify(convert(
|
|
|
31
31
|
return `${fence}figure ${source}\n\n${fence}`;
|
|
32
32
|
},
|
|
33
33
|
union([figure])),
|
|
34
|
-
([el]) => el.
|
|
34
|
+
([el]) => el.tagName === 'FIGURE')));
|
|
@@ -7,25 +7,24 @@ describe('Unit: parser/block/extension/figure', () => {
|
|
|
7
7
|
const parser = (source: string) => some(figure)(source, {});
|
|
8
8
|
|
|
9
9
|
it('invalid', () => {
|
|
10
|
-
assert.deepStrictEqual(inspect(parser('~~~figure\n!https://host\n~~~')),
|
|
11
|
-
assert.deepStrictEqual(inspect(parser('~~~figure $group-name]\n!https://host\n~~~')), [['<
|
|
12
|
-
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name\n!https://host\n~~~')),
|
|
13
|
-
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\nhttps://host\n~~~')), [['<
|
|
14
|
-
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\\\n~~~')), [['<
|
|
15
|
-
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\n\\\n~~~')), [['<
|
|
16
|
-
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\na\n~~~')), [['<
|
|
17
|
-
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\n\n\n\n~~~')),
|
|
18
|
-
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n !https://host\n~~~')), [['<
|
|
19
|
-
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n
|
|
20
|
-
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\n
|
|
21
|
-
assert.deepStrictEqual(inspect(parser('
|
|
22
|
-
assert.deepStrictEqual(inspect(parser('
|
|
23
|
-
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]a\
|
|
24
|
-
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]a\
|
|
25
|
-
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name] a\nhttps://host\n~~~')), [['<figure data-type="invalid" data-label="group-name" data-group="group" class="invalid"><figcaption><span class="figindex"></span></figcaption><div><br></div></figure>'], '']);
|
|
10
|
+
assert.deepStrictEqual(inspect(parser('~~~figure\n!https://host\n~~~')), [['<pre class="invalid" translate="no">~~~figure\n!https://host\n~~~</pre>'], '']);
|
|
11
|
+
assert.deepStrictEqual(inspect(parser('~~~figure $group-name]\n!https://host\n~~~')), [['<pre class="invalid" translate="no">~~~figure $group-name]\n!https://host\n~~~</pre>'], '']);
|
|
12
|
+
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name\n!https://host\n~~~')), [['<pre class="invalid" translate="no">~~~figure [$group-name\n!https://host\n~~~</pre>'], '']);
|
|
13
|
+
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\nhttps://host\n~~~')), [['<pre class="invalid" translate="no">~~~figure [$group-name]\nhttps://host\n~~~</pre>'], '']);
|
|
14
|
+
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\\\n~~~')), [['<pre class="invalid" translate="no">~~~figure [$group-name]\n!https://host\\\n~~~</pre>'], '']);
|
|
15
|
+
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\n\\\n~~~')), [['<pre class="invalid" translate="no">~~~figure [$group-name]\n!https://host\n\\\n~~~</pre>'], '']);
|
|
16
|
+
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\na\n~~~')), [['<pre class="invalid" translate="no">~~~figure [$group-name]\n!https://host\na\n~~~</pre>'], '']);
|
|
17
|
+
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\n\n\n\n~~~')), [['<pre class="invalid" translate="no">~~~figure [$group-name]\n!https://host\n\n\n\n~~~</pre>'], '']);
|
|
18
|
+
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n !https://host\n~~~')), [['<pre class="invalid" translate="no">~~~figure [$group-name]\n !https://host\n~~~</pre>'], '']);
|
|
19
|
+
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\n~~~\n~~~')), [['<pre class="invalid" translate="no">~~~figure [$group-name]\n!https://host\n~~~\n~~~</pre>'], '']);
|
|
20
|
+
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]\n!https://host\n~~~~')), [['<pre class="invalid" translate="no">~~~figure [$group-name]\n!https://host\n~~~~</pre>'], '']);
|
|
21
|
+
assert.deepStrictEqual(inspect(parser('~~~~figure [$group-name]\n!https://host\n~~~')), [['<pre class="invalid" translate="no">~~~~figure [$group-name]\n!https://host\n~~~</pre>'], '']);
|
|
22
|
+
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]a\nhttps://host\n~~~')), [['<pre class="invalid" translate="no">~~~figure [$group-name]a\nhttps://host\n~~~</pre>'], '']);
|
|
23
|
+
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name]a\n!https://host\n~~~')), [['<pre class="invalid" translate="no">~~~figure [$group-name]a\n!https://host\n~~~</pre>'], '']);
|
|
24
|
+
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name] a\nhttps://host\n~~~')), [['<pre class="invalid" translate="no">~~~figure [$group-name] a\nhttps://host\n~~~</pre>'], '']);
|
|
26
25
|
assert.deepStrictEqual(inspect(parser('~~~figure [$group-name] a\n!https://host\n~~~')), [['<figure data-type="media" data-label="group-name" data-group="group" class="invalid"><figcaption><span class="figindex"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure>'], '']);
|
|
27
|
-
assert.deepStrictEqual(inspect(parser('~~~figure a[$group-name]\n!https://host\n~~~')),
|
|
28
|
-
assert.deepStrictEqual(inspect(parser('~~~figure a [$group-name]\n!https://host\n~~~')),
|
|
26
|
+
assert.deepStrictEqual(inspect(parser('~~~figure a[$group-name]\n!https://host\n~~~')), [['<pre class="invalid" translate="no">~~~figure a[$group-name]\n!https://host\n~~~</pre>'], '']);
|
|
27
|
+
assert.deepStrictEqual(inspect(parser('~~~figure a [$group-name]\n!https://host\n~~~')), [['<pre class="invalid" translate="no">~~~figure a [$group-name]\n!https://host\n~~~</pre>'], '']);
|
|
29
28
|
assert.deepStrictEqual(inspect(parser('~~~ [$group-name]\n!https://host\n~~~')), undefined);
|
|
30
29
|
assert.deepStrictEqual(inspect(parser('~~~ $group-name\n!https://host\n~~~')), undefined);
|
|
31
30
|
assert.deepStrictEqual(inspect(parser(' ~~~figure [$group-name]\n!https://host\n~~~')), undefined);
|
|
@@ -33,7 +32,8 @@ describe('Unit: parser/block/extension/figure', () => {
|
|
|
33
32
|
assert.deepStrictEqual(inspect(parser('~~~figure [$fig-name]\n> \n\n~~~')), [['<figure data-type="quote" data-label="fig-name" data-group="fig" class="invalid"><figcaption><span class="figindex"></span></figcaption><div><blockquote></blockquote></div></figure>'], '']);
|
|
34
33
|
assert.deepStrictEqual(inspect(parser('~~~figure [$figure-name]\n> \n\n~~~')), [['<figure data-type="quote" data-label="figure-name" data-group="figure" class="invalid"><figcaption><span class="figindex"></span></figcaption><div><blockquote></blockquote></div></figure>'], '']);
|
|
35
34
|
assert.deepStrictEqual(inspect(parser('~~~figure [$table-name]\n> \n\n~~~')), [['<figure data-type="quote" data-label="table-name" data-group="table" class="invalid"><figcaption><span class="figindex"></span></figcaption><div><blockquote></blockquote></div></figure>'], '']);
|
|
36
|
-
assert(
|
|
35
|
+
assert.deepStrictEqual(inspect(parser(`~~~figure [$group-name]\n0${'\n'.repeat(301)}~~~`), '>'), [['<pre class="invalid" translate="no">'], '']);
|
|
36
|
+
assert.deepStrictEqual(inspect(parser(`~~~figure [$group-name]\n~~~\n0${'\n'.repeat(301)}~~~\n~~~`), '>'), [['<pre class="invalid" translate="no">'], '\n~~~\n~~~']);
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
it('valid', () => {
|
|
@@ -67,8 +67,8 @@ describe('Unit: parser/block/extension/figure', () => {
|
|
|
67
67
|
assert.deepStrictEqual(inspect(parser('~~~figure [$-0.0]\n$$\n\n$$\n~~~')), [['<figure data-type="math" data-label="$-0.0" data-group="$" class="invalid"><figcaption><span class="figindex"></span></figcaption><div><div class="math" translate="no">$$\n\n$$</div></div></figure>'], '']);
|
|
68
68
|
assert.deepStrictEqual(inspect(parser('~~~figure [$-name]\n!https://host\n~~~')), [['<figure data-type="media" data-label="$-name" data-group="$" class="invalid"><figcaption><span class="figindex"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure>'], '']);
|
|
69
69
|
assert.deepStrictEqual(inspect(parser('~~~figure [$-name]\n$$\n\n$$\n\ncaption\n~~~')), [['<figure data-type="math" data-label="$-name" data-group="$" class="invalid"><figcaption><span class="figindex"></span>caption</figcaption><div><div class="math" translate="no">$$\n\n$$</div></div></figure>'], '']);
|
|
70
|
-
assert(parser(
|
|
71
|
-
assert(parser(
|
|
70
|
+
assert.deepStrictEqual(inspect(parser(`~~~figure [$group-name]\n${'>\n'.repeat(500)}\n~~~`), '>'), [['<figure data-type="quote" data-label="group-name" data-group="group">'], '']);
|
|
71
|
+
assert.deepStrictEqual(inspect(parser(`~~~figure [$group-name]\n~~~\n0${'\n'.repeat(300)}~~~\n~~~`), '>'), [['<figure data-type="example" data-label="group-name" data-group="group">'], '']);
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { undefined } from 'spica/global';
|
|
2
2
|
import { ExtensionParser } from '../../block';
|
|
3
|
-
import { union, inits, sequence, some, block, line, rewrite, context, close, match, convert, trim, fmap } from '../../../combinator';
|
|
3
|
+
import { union, inits, sequence, some, block, line, fence, rewrite, context, close, match, convert, trim, fallback, fmap } from '../../../combinator';
|
|
4
4
|
import { str, contentline, emptyline } from '../../source';
|
|
5
|
-
import { label } from '../../inline/extension/label';
|
|
5
|
+
import { label, segment as seg_label } from '../../inline/extension/label';
|
|
6
6
|
import { ulist } from '../ulist';
|
|
7
7
|
import { olist } from '../olist';
|
|
8
8
|
import { table as styled_table } from '../table';
|
|
@@ -23,36 +23,35 @@ import { unshift } from 'spica/array';
|
|
|
23
23
|
import FigureParser = ExtensionParser.FigureParser;
|
|
24
24
|
|
|
25
25
|
export const segment: FigureParser.SegmentParser = block(match(
|
|
26
|
-
/^(~{3,})(?:figure[^\S\n]
|
|
26
|
+
/^(~{3,})(?:figure[^\S\n]|(?=\[?\$))/,
|
|
27
27
|
memoize(
|
|
28
|
-
([, fence], closer = new RegExp(String.raw`^${fence}[^\S\n]*(?:$|\n)`)) =>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
28
|
+
([, fence], closer = new RegExp(String.raw`^${fence}[^\S\n]*(?:$|\n)`)) => close(
|
|
29
|
+
sequence([
|
|
30
|
+
contentline,
|
|
31
|
+
inits([
|
|
32
|
+
// All parsers which can include closing terms.
|
|
33
|
+
union([
|
|
34
|
+
seg_code,
|
|
35
|
+
seg_math,
|
|
36
|
+
seg_table,
|
|
37
|
+
seg_blockquote,
|
|
38
|
+
seg_placeholder,
|
|
39
|
+
some(contentline, closer),
|
|
40
|
+
]),
|
|
41
|
+
emptyline,
|
|
42
|
+
union([
|
|
42
43
|
emptyline,
|
|
43
|
-
|
|
44
|
-
emptyline,
|
|
45
|
-
some(contentline, closer),
|
|
46
|
-
]),
|
|
44
|
+
some(contentline, closer),
|
|
47
45
|
]),
|
|
48
46
|
]),
|
|
49
|
-
|
|
47
|
+
]),
|
|
48
|
+
closer),
|
|
50
49
|
([, fence]) => fence.length, [])));
|
|
51
50
|
|
|
52
|
-
export const figure: FigureParser = block(rewrite(segment, fmap(
|
|
53
|
-
convert(source => source.slice(source.
|
|
51
|
+
export const figure: FigureParser = block(fallback(rewrite(segment, fallback(fmap(
|
|
52
|
+
convert(source => source.slice(source.match(/^~+(?:figure[^\S\n]+)?/)![0].length, source.trimEnd().lastIndexOf('\n')),
|
|
54
53
|
sequence([
|
|
55
|
-
line(sequence([label, str(
|
|
54
|
+
line(sequence([label, str(/^(?=\s).*\n/)])),
|
|
56
55
|
inits([
|
|
57
56
|
block(union([
|
|
58
57
|
ulist,
|
|
@@ -65,9 +64,8 @@ export const figure: FigureParser = block(rewrite(segment, fmap(
|
|
|
65
64
|
table,
|
|
66
65
|
blockquote,
|
|
67
66
|
placeholder,
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
fmap(some(contentline), () => [html('br')]),
|
|
67
|
+
line(media),
|
|
68
|
+
line(shortmedia),
|
|
71
69
|
])),
|
|
72
70
|
emptyline,
|
|
73
71
|
block(localize(
|
|
@@ -84,7 +82,53 @@ export const figure: FigureParser = block(rewrite(segment, fmap(
|
|
|
84
82
|
defrag(caption))),
|
|
85
83
|
html('div', [content]),
|
|
86
84
|
])
|
|
87
|
-
])
|
|
85
|
+
]),
|
|
86
|
+
(source, context) => [[
|
|
87
|
+
html('pre', {
|
|
88
|
+
class: 'invalid',
|
|
89
|
+
translate: 'no',
|
|
90
|
+
'data-invalid-syntax': 'figure',
|
|
91
|
+
...
|
|
92
|
+
!seg_label(source.match(/^~+(?:figure[^\S\n]+)?(\[?\$\S+)/)?.[1] ?? '', context) && {
|
|
93
|
+
'data-invalid-type': 'label',
|
|
94
|
+
'data-invalid-message': 'Invalid label',
|
|
95
|
+
} ||
|
|
96
|
+
/^~+(?:figure[^\S\n]+)?(\[?\$\S+)[^\S\n]+\S/.test(source) && {
|
|
97
|
+
'data-invalid-type': 'argument',
|
|
98
|
+
'data-invalid-message': 'Invalid argument',
|
|
99
|
+
} ||
|
|
100
|
+
{
|
|
101
|
+
'data-invalid-type': 'content',
|
|
102
|
+
'data-invalid-message': 'Invalid content',
|
|
103
|
+
},
|
|
104
|
+
}, source),
|
|
105
|
+
], ''])),
|
|
106
|
+
fmap(
|
|
107
|
+
fence(/^(~{3,})(?:figure|\[?\$\S*)(?!\S)[^\n]*(?:$|\n)/, 300),
|
|
108
|
+
([body, closer, opener, delim]: string[], _, context) => [
|
|
109
|
+
html('pre', {
|
|
110
|
+
class: 'invalid',
|
|
111
|
+
translate: 'no',
|
|
112
|
+
'data-invalid-syntax': 'figure',
|
|
113
|
+
...
|
|
114
|
+
!closer && {
|
|
115
|
+
'data-invalid-type': 'fence',
|
|
116
|
+
'data-invalid-message': `Missing the closing delimiter "${delim}"`,
|
|
117
|
+
} ||
|
|
118
|
+
!seg_label(opener.match(/^~+(?:figure[^\S\n]+)?(\[?\$\S+)/)?.[1] ?? '', context) && {
|
|
119
|
+
'data-invalid-type': 'label',
|
|
120
|
+
'data-invalid-message': 'Invalid label',
|
|
121
|
+
} ||
|
|
122
|
+
/^~+(?:figure[^\S\n]+)?(\[?\$\S+)[^\S\n]+\S/.test(opener) && {
|
|
123
|
+
'data-invalid-type': 'argument',
|
|
124
|
+
'data-invalid-message': 'Invalid argument',
|
|
125
|
+
} ||
|
|
126
|
+
{
|
|
127
|
+
'data-invalid-type': 'content',
|
|
128
|
+
'data-invalid-message': 'Invalid content',
|
|
129
|
+
},
|
|
130
|
+
}, `${opener}${body}${closer}`),
|
|
131
|
+
])));
|
|
88
132
|
|
|
89
133
|
function attributes(label: string, param: string, content: HTMLElement, caption: readonly HTMLElement[]): Record<string, string | undefined> {
|
|
90
134
|
const group = label.split('-', 1)[0];
|
|
@@ -104,9 +148,6 @@ function attributes(label: string, param: string, content: HTMLElement, caption:
|
|
|
104
148
|
case 'A':
|
|
105
149
|
type = 'media';
|
|
106
150
|
break;
|
|
107
|
-
case 'BR':
|
|
108
|
-
type = 'invalid';
|
|
109
|
-
break;
|
|
110
151
|
case 'text':
|
|
111
152
|
case 'code':
|
|
112
153
|
case 'math':
|
|
@@ -117,18 +158,14 @@ function attributes(label: string, param: string, content: HTMLElement, caption:
|
|
|
117
158
|
assert(false);
|
|
118
159
|
}
|
|
119
160
|
const invalid =
|
|
120
|
-
|
|
121
|
-
'data-invalid-type': '
|
|
122
|
-
'data-invalid-message': 'Invalid
|
|
161
|
+
param.trimStart() !== '' && {
|
|
162
|
+
'data-invalid-type': 'argument',
|
|
163
|
+
'data-invalid-message': 'Invalid argument',
|
|
123
164
|
} ||
|
|
124
165
|
/^[^-]+-(?:[0-9]+\.)*0$/.test(label) && {
|
|
125
166
|
'data-invalid-type': 'label',
|
|
126
167
|
'data-invalid-message': 'The last part of the fixed label numbers must not be 0',
|
|
127
168
|
} ||
|
|
128
|
-
param.trimStart() !== '' && {
|
|
129
|
-
'data-invalid-type': 'argument',
|
|
130
|
-
'data-invalid-message': 'Invalid argument',
|
|
131
|
-
} ||
|
|
132
169
|
group === '$' && (type !== 'math' || caption.length > 0) && {
|
|
133
170
|
'data-invalid-type': 'label',
|
|
134
171
|
'data-invalid-message': '"$" label group must be used to math formulas with no caption',
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ExtensionParser } from '../../block';
|
|
2
2
|
import { block, validate, fence, clear, fmap } from '../../../combinator';
|
|
3
|
-
import { segment as label } from '../../inline/extension/label';
|
|
4
3
|
import { html } from 'typed-dom/dom';
|
|
5
4
|
|
|
6
5
|
const opener = /^(~{3,})(?!~)[^\n]*(?:$|\n)/;
|
|
@@ -13,17 +12,12 @@ export const segment_: ExtensionParser.PlaceholderParser.SegmentParser = block(v
|
|
|
13
12
|
|
|
14
13
|
export const placeholder: ExtensionParser.PlaceholderParser = block(validate('~~~', fmap(
|
|
15
14
|
fence(opener, Infinity),
|
|
16
|
-
([body, closer, opener, delim]
|
|
15
|
+
([body, closer, opener, delim]) => [
|
|
17
16
|
html('pre', {
|
|
18
17
|
class: 'invalid',
|
|
19
18
|
translate: 'no',
|
|
20
19
|
'data-invalid-syntax': 'extension',
|
|
21
20
|
'data-invalid-type': !closer ? 'fence' : 'syntax',
|
|
22
21
|
'data-invalid-message': !closer ? `Missing the closing delimiter "${delim}"` : 'Invalid extension name',
|
|
23
|
-
|
|
24
|
-
'data-invalid-syntax': 'figure',
|
|
25
|
-
'data-invalid-type': 'content',
|
|
26
|
-
'data-invalid-message': 'Invalid content',
|
|
27
|
-
},
|
|
28
|
-
}, `${opener}${body}${closer}`)
|
|
22
|
+
}, `${opener}${body}${closer}`),
|
|
29
23
|
])));
|
|
@@ -29,9 +29,9 @@ const row = <P extends CellParser | AlignParser>(parser: P, optional: boolean):
|
|
|
29
29
|
rewrite(contentline, source => [[
|
|
30
30
|
html('tr', {
|
|
31
31
|
class: 'invalid',
|
|
32
|
-
'data-invalid-syntax': '
|
|
32
|
+
'data-invalid-syntax': 'table-row',
|
|
33
33
|
'data-invalid-type': 'syntax',
|
|
34
|
-
'data-invalid-message': '
|
|
34
|
+
'data-invalid-message': 'Missing the start symbol of the table row',
|
|
35
35
|
}, [html('td', source.replace('\n', ''))])
|
|
36
36
|
], ''])));
|
|
37
37
|
|