securemark 0.293.0 → 0.293.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/index.js +254 -193
- package/markdown.d.ts +13 -21
- package/package.json +1 -1
- package/src/combinator/control/manipulation/scope.ts +3 -4
- package/src/combinator/data/parser/context.ts +5 -5
- package/src/combinator.ts +0 -1
- package/src/parser/api/parse.test.ts +2 -2
- package/src/parser/autolink.test.ts +7 -7
- package/src/parser/block/blockquote.ts +2 -2
- package/src/parser/block/codeblock.ts +7 -7
- package/src/parser/block/dlist.ts +1 -2
- package/src/parser/block/extension/aside.ts +3 -3
- package/src/parser/block/extension/example.ts +3 -3
- package/src/parser/block/extension/fig.ts +2 -2
- package/src/parser/block/extension/figure.test.ts +1 -1
- package/src/parser/block/extension/figure.ts +2 -2
- package/src/parser/block/extension/message.ts +3 -3
- package/src/parser/block/extension/placeholder.ts +7 -7
- package/src/parser/block/extension/table.ts +26 -16
- package/src/parser/block/extension.ts +3 -3
- package/src/parser/block/ilist.ts +3 -3
- package/src/parser/block/mathblock.ts +7 -7
- package/src/parser/block/mediablock.ts +6 -6
- package/src/parser/block/olist.ts +3 -3
- package/src/parser/block/paragraph.test.ts +1 -2
- package/src/parser/block/paragraph.ts +1 -2
- package/src/parser/block/reply/cite.ts +3 -5
- package/src/parser/block/reply/quote.ts +2 -3
- package/src/parser/block/sidefence.ts +2 -2
- package/src/parser/block/table.ts +5 -5
- package/src/parser/block/ulist.ts +2 -3
- package/src/parser/block.ts +2 -2
- package/src/parser/context.ts +4 -4
- package/src/parser/inline/annotation.ts +1 -1
- package/src/parser/inline/autolink/url.test.ts +7 -7
- package/src/parser/inline/autolink/url.ts +1 -2
- package/src/parser/inline/autolink.ts +1 -1
- package/src/parser/inline/bracket.test.ts +2 -2
- package/src/parser/inline/extension/index.ts +5 -4
- package/src/parser/inline/extension/indexer.test.ts +0 -1
- package/src/parser/inline/extension/indexer.ts +1 -1
- package/src/parser/inline/html.ts +7 -6
- package/src/parser/inline/htmlentity.ts +3 -3
- package/src/parser/inline/italic.test.ts +11 -11
- package/src/parser/inline/link.ts +1 -6
- package/src/parser/inline/mark.test.ts +5 -5
- package/src/parser/inline/math.ts +3 -3
- package/src/parser/inline/media.ts +3 -8
- package/src/parser/inline/reference.ts +1 -1
- package/src/parser/inline/remark.test.ts +14 -18
- package/src/parser/inline/remark.ts +17 -19
- package/src/parser/inline/ruby.ts +3 -3
- package/src/parser/inline/shortmedia.ts +1 -1
- package/src/parser/inline.test.ts +25 -24
- package/src/parser/inline.ts +21 -9
- package/src/parser/segment.ts +23 -5
- package/src/parser/source/escapable.test.ts +1 -1
- package/src/parser/source/escapable.ts +4 -12
- package/src/parser/source/text.test.ts +40 -40
- package/src/parser/source/text.ts +77 -24
- package/src/parser/source/unescapable.test.ts +3 -3
- package/src/parser/source/unescapable.ts +4 -12
- package/src/parser/visibility.ts +32 -32
- package/src/combinator/control/manipulation/trim.test.ts +0 -23
- package/src/combinator/control/manipulation/trim.ts +0 -17
|
@@ -15,7 +15,7 @@ describe('Unit: parser/source/unescapable', () => {
|
|
|
15
15
|
it('basic', () => {
|
|
16
16
|
assert.deepStrictEqual(inspect(parser('a'), ctx), [['a'], '']);
|
|
17
17
|
assert.deepStrictEqual(inspect(parser('ab'), ctx), [['ab'], '']);
|
|
18
|
-
assert.deepStrictEqual(inspect(parser('09あいAZaz'), ctx), [['09', 'あい
|
|
18
|
+
assert.deepStrictEqual(inspect(parser('09あいAZaz'), ctx), [['09', 'あいAZaz'], '']);
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
it('space', () => {
|
|
@@ -37,8 +37,8 @@ describe('Unit: parser/source/unescapable', () => {
|
|
|
37
37
|
assert.deepStrictEqual(inspect(parser('\\\\\\'), ctx), [['\\', '\\', '\\'], '']);
|
|
38
38
|
assert.deepStrictEqual(inspect(parser('\\ '), ctx), [['\\', ' '], '']);
|
|
39
39
|
assert.deepStrictEqual(inspect(parser('\\_'), ctx), [['\\', '_'], '']);
|
|
40
|
-
assert.deepStrictEqual(inspect(parser('\\0'), ctx), [['\\
|
|
41
|
-
assert.deepStrictEqual(inspect(parser('\\a'), ctx), [['\\
|
|
40
|
+
assert.deepStrictEqual(inspect(parser('\\0'), ctx), [['\\0'], '']);
|
|
41
|
+
assert.deepStrictEqual(inspect(parser('\\a'), ctx), [['\\a'], '']);
|
|
42
42
|
assert.deepStrictEqual(inspect(parser('\\`'), ctx), [['\\', '`'], '']);
|
|
43
43
|
assert.deepStrictEqual(inspect(parser('\\ '), ctx), [['\\', ' '], '']);
|
|
44
44
|
assert.deepStrictEqual(inspect(parser('\\\n'), ctx), [['\\', '<br>'], '']);
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { UnescapableSourceParser } from '../source';
|
|
2
2
|
import { Command } from '../context';
|
|
3
3
|
import { consume } from '../../combinator';
|
|
4
|
-
import { nonWhitespace,
|
|
4
|
+
import { nonWhitespace, isBlank, next } from './text';
|
|
5
5
|
import { html } from 'typed-dom/dom';
|
|
6
6
|
|
|
7
|
+
export const delimiter = /(?=(?=[\x00-\x7F])[^0-9A-Za-z]|(?<=[\x00-\x7F])[^\x00-\x7F])/g;
|
|
8
|
+
|
|
7
9
|
export const unescsource: UnescapableSourceParser = ({ context }) => {
|
|
8
10
|
const { source, position } = context;
|
|
9
11
|
if (position === source.length) return;
|
|
@@ -25,23 +27,13 @@ export const unescsource: UnescapableSourceParser = ({ context }) => {
|
|
|
25
27
|
default:
|
|
26
28
|
assert(char !== '\n');
|
|
27
29
|
if (context.sequential) return [[char]];
|
|
28
|
-
nonAlphanumeric.lastIndex = position + 1;
|
|
29
30
|
nonWhitespace.lastIndex = position + 1;
|
|
30
|
-
ASCII.lastIndex = position + 1;
|
|
31
31
|
const b = isBlank(source, position);
|
|
32
32
|
let i = b
|
|
33
33
|
? nonWhitespace.test(source)
|
|
34
34
|
? nonWhitespace.lastIndex - 1
|
|
35
35
|
: source.length
|
|
36
|
-
:
|
|
37
|
-
? nonAlphanumeric.test(source)
|
|
38
|
-
? nonAlphanumeric.lastIndex - 1
|
|
39
|
-
: source.length
|
|
40
|
-
: !isASCII(char)
|
|
41
|
-
? ASCII.test(source)
|
|
42
|
-
? ASCII.lastIndex - 1
|
|
43
|
-
: source.length
|
|
44
|
-
: position + 1;
|
|
36
|
+
: next(source, position, delimiter);
|
|
45
37
|
assert(i > position);
|
|
46
38
|
i -= position;
|
|
47
39
|
consume(i - 1, context);
|
package/src/parser/visibility.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { MarkdownParser } from '../../markdown';
|
|
2
2
|
import { Command } from './context';
|
|
3
3
|
import { Parser, Input, eval, failsafe } from '../combinator/data/parser';
|
|
4
|
-
import {
|
|
4
|
+
import { convert, fmap } from '../combinator';
|
|
5
5
|
import { unsafehtmlentity } from './inline/htmlentity';
|
|
6
|
-
import { linebreak, unescsource } from './source';
|
|
7
6
|
import { invisibleHTMLEntityNames } from './api/normalize';
|
|
8
7
|
import { push } from 'spica/array';
|
|
9
8
|
|
|
10
9
|
export namespace blank {
|
|
11
10
|
export const line = new RegExp(
|
|
12
|
-
|
|
11
|
+
// TODO: 行全体をエスケープ
|
|
12
|
+
/^(?:[^\S\r\n])*(?!\s)(\\?[^\S\r\n]|&IHN;|<wbr[^\S\n]*>|\\$)+$/mg.source
|
|
13
13
|
.replace('IHN', `(?:${invisibleHTMLEntityNames.join('|')})`),
|
|
14
14
|
'gm');
|
|
15
15
|
export const start = new RegExp(
|
|
@@ -19,31 +19,28 @@ export namespace blank {
|
|
|
19
19
|
|
|
20
20
|
export function visualize<P extends Parser<HTMLElement | string>>(parser: P): P;
|
|
21
21
|
export function visualize<N extends HTMLElement | string>(parser: Parser<N>): Parser<N> {
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
false),
|
|
27
|
-
some(union([linebreak, unescsource])),
|
|
28
|
-
]);
|
|
29
|
-
}
|
|
30
|
-
function hasVisible(
|
|
31
|
-
nodes: readonly (HTMLElement | string)[],
|
|
32
|
-
): boolean {
|
|
33
|
-
for (let i = 0; i < nodes.length; ++i) {
|
|
34
|
-
const node = nodes[i];
|
|
35
|
-
if (typeof node === 'string') {
|
|
36
|
-
if (node && node.trimStart()) return true;
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
if (node.innerText.trimStart()) return true;
|
|
40
|
-
if (node.classList.contains('reference')) return true;
|
|
41
|
-
//if (state & State.media ^ State.media &&
|
|
42
|
-
// (node.classList.contains('media') || node.getElementsByClassName('media')[0])) return true;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return false;
|
|
22
|
+
return convert(
|
|
23
|
+
source => source.replace(blank.line, `${Command.Escape}$1`),
|
|
24
|
+
parser,
|
|
25
|
+
false);
|
|
46
26
|
}
|
|
27
|
+
//function hasVisible(
|
|
28
|
+
// nodes: readonly (HTMLElement | string)[],
|
|
29
|
+
//): boolean {
|
|
30
|
+
// for (let i = 0; i < nodes.length; ++i) {
|
|
31
|
+
// const node = nodes[i];
|
|
32
|
+
// if (typeof node === 'string') {
|
|
33
|
+
// if (node && node.trimStart()) return true;
|
|
34
|
+
// }
|
|
35
|
+
// else {
|
|
36
|
+
// if (node.innerText.trimStart()) return true;
|
|
37
|
+
// if (node.classList.contains('reference')) return true;
|
|
38
|
+
// //if (state & State.media ^ State.media &&
|
|
39
|
+
// // (node.classList.contains('media') || node.getElementsByClassName('media')[0])) return true;
|
|
40
|
+
// }
|
|
41
|
+
// }
|
|
42
|
+
// return false;
|
|
43
|
+
//}
|
|
47
44
|
|
|
48
45
|
export function blankWith(delimiter: string | RegExp): RegExp;
|
|
49
46
|
export function blankWith(starts: '' | '\n', delimiter: string | RegExp): RegExp;
|
|
@@ -79,6 +76,7 @@ export function tightStart<N>(parser: Parser<N>, except?: string): Parser<N> {
|
|
|
79
76
|
? parser(input)
|
|
80
77
|
: undefined;
|
|
81
78
|
}
|
|
79
|
+
const wbr = /<wbr[^\S\n]*>/y;
|
|
82
80
|
function isTightStart(input: Input<MarkdownParser.Context>, except?: string): boolean {
|
|
83
81
|
const { context } = input;
|
|
84
82
|
const { source, position } = context;
|
|
@@ -103,10 +101,11 @@ function isTightStart(input: Input<MarkdownParser.Context>, except?: string): bo
|
|
|
103
101
|
context.position = position;
|
|
104
102
|
return true;
|
|
105
103
|
case '<':
|
|
104
|
+
wbr.lastIndex = position;
|
|
106
105
|
switch (true) {
|
|
107
106
|
case source.length - position >= 5
|
|
108
107
|
&& source.startsWith('<wbr', position)
|
|
109
|
-
&& (source[position + 5] === '>' ||
|
|
108
|
+
&& (source[position + 5] === '>' || wbr.test(source)):
|
|
110
109
|
return false;
|
|
111
110
|
}
|
|
112
111
|
return true;
|
|
@@ -168,18 +167,19 @@ export function trimBlankStart<N>(parser: Parser<N>): Parser<N> {
|
|
|
168
167
|
return failsafe(input => {
|
|
169
168
|
const { context } = input;
|
|
170
169
|
const { source, position } = context;
|
|
170
|
+
if (position === source.length) return;
|
|
171
171
|
const reg = blank.start;
|
|
172
172
|
reg.lastIndex = position;
|
|
173
173
|
reg.test(source);
|
|
174
174
|
context.position = reg.lastIndex || position;
|
|
175
|
-
return
|
|
175
|
+
return context.position === source.length
|
|
176
|
+
? [[]]
|
|
177
|
+
: parser(input);
|
|
176
178
|
});
|
|
177
179
|
}
|
|
178
180
|
export function trimBlankEnd<P extends Parser<HTMLElement | string>>(parser: P): P;
|
|
179
181
|
export function trimBlankEnd<N extends HTMLElement | string>(parser: Parser<N>): Parser<N> {
|
|
180
|
-
return fmap(
|
|
181
|
-
parser,
|
|
182
|
-
trimBlankNodeEnd);
|
|
182
|
+
return fmap(parser, trimBlankNodeEnd);
|
|
183
183
|
}
|
|
184
184
|
//export function trimBlankNode<N extends HTMLElement | string>(nodes: N[]): N[] {
|
|
185
185
|
// return trimBlankNodeStart(trimBlankNodeEnd(nodes));
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { trim } from './trim';
|
|
2
|
-
import { input } from '../../data/parser';
|
|
3
|
-
import { inspect } from '../../../debug.test';
|
|
4
|
-
|
|
5
|
-
describe('Unit: combinator/trim', () => {
|
|
6
|
-
describe('trim', () => {
|
|
7
|
-
const { context: ctx } = input('', {});
|
|
8
|
-
|
|
9
|
-
it('', () => {
|
|
10
|
-
const parser = trim(({ context }) => { context.position = context.source.length; return [[context.source]]; });
|
|
11
|
-
assert.deepStrictEqual(inspect(parser(input('', ctx)), ctx), undefined);
|
|
12
|
-
assert.deepStrictEqual(inspect(parser(input('a', ctx)), ctx), [['a'], '']);
|
|
13
|
-
assert.deepStrictEqual(inspect(parser(input('a\n', ctx)), ctx), [['a'], '']);
|
|
14
|
-
assert.deepStrictEqual(inspect(parser(input('a ', ctx)), ctx), [['a'], '']);
|
|
15
|
-
assert.deepStrictEqual(inspect(parser(input('a \n', ctx)), ctx), [['a'], '']);
|
|
16
|
-
assert.deepStrictEqual(inspect(parser(input(' a', ctx)), ctx), [['a'], '']);
|
|
17
|
-
assert.deepStrictEqual(inspect(parser(input(' a ', ctx)), ctx), [['a'], '']);
|
|
18
|
-
assert.deepStrictEqual(inspect(parser(input(' a \n b \n', ctx)), ctx), [['a \n b'], '']);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Parser } from '../../data/parser';
|
|
2
|
-
import { convert } from './convert';
|
|
3
|
-
|
|
4
|
-
export function trim<P extends Parser<unknown>>(parser: P): P;
|
|
5
|
-
export function trim<N>(parser: Parser<N>): Parser<N> {
|
|
6
|
-
return convert(source => source.trim(), parser, false);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function trimStart<P extends Parser<unknown>>(parser: P): P;
|
|
10
|
-
export function trimStart<N>(parser: Parser<N>): Parser<N> {
|
|
11
|
-
return convert(source => source.trimStart(), parser, true);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export function trimEnd<P extends Parser<unknown>>(parser: P): P;
|
|
15
|
-
export function trimEnd<N>(parser: Parser<N>): Parser<N> {
|
|
16
|
-
return convert(source => source.trimEnd(), parser, false);
|
|
17
|
-
}
|