securemark 0.263.1 → 0.265.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 +11 -0
- package/dist/index.js +1218 -3058
- package/markdown.d.ts +1 -1
- package/package.json +18 -18
- package/src/combinator/data/parser/context.ts +3 -2
- package/src/combinator/data/parser/some.ts +2 -1
- package/src/parser/api/bind.test.ts +1 -1
- package/src/parser/api/normalize.ts +1 -1
- package/src/parser/api/parse.test.ts +3 -3
- package/src/parser/block/blockquote.test.ts +3 -3
- package/src/parser/block/blockquote.ts +1 -1
- package/src/parser/block/dlist.ts +2 -3
- package/src/parser/block/extension/aside.ts +0 -2
- package/src/parser/block/extension/example.test.ts +1 -1
- package/src/parser/block/extension/fig.ts +2 -1
- package/src/parser/block/extension/figure.test.ts +2 -2
- package/src/parser/block/extension/figure.ts +2 -3
- package/src/parser/block/extension/table.ts +2 -3
- package/src/parser/block/heading.test.ts +1 -1
- package/src/parser/block/olist.test.ts +27 -25
- package/src/parser/block/paragraph.test.ts +1 -1
- package/src/parser/block/paragraph.ts +2 -3
- package/src/parser/block/reply.ts +2 -3
- package/src/parser/block/sidefence.ts +1 -1
- package/src/parser/block/ulist.test.ts +23 -23
- package/src/parser/context.ts +15 -19
- package/src/parser/inline/annotation.ts +1 -1
- package/src/parser/inline/bracket.test.ts +1 -1
- package/src/parser/inline/bracket.ts +1 -1
- package/src/parser/inline/deletion.test.ts +2 -2
- package/src/parser/inline/emphasis.test.ts +2 -2
- package/src/parser/inline/emphasis.ts +2 -2
- package/src/parser/inline/extension/index.test.ts +28 -32
- package/src/parser/inline/extension/index.ts +1 -1
- package/src/parser/inline/extension/indexee.ts +23 -15
- package/src/parser/inline/extension/placeholder.test.ts +10 -12
- package/src/parser/inline/extension/placeholder.ts +7 -7
- package/src/parser/inline/html.test.ts +1 -1
- package/src/parser/inline/html.ts +2 -2
- package/src/parser/inline/insertion.test.ts +2 -2
- package/src/parser/inline/link.test.ts +32 -27
- package/src/parser/inline/link.ts +52 -56
- package/src/parser/inline/mark.test.ts +11 -11
- package/src/parser/inline/mark.ts +12 -6
- package/src/parser/inline/strong.test.ts +2 -2
- package/src/parser/inline/strong.ts +2 -2
- package/src/parser/inline.test.ts +11 -9
- package/src/parser/processor/figure.ts +0 -2
- package/src/parser/processor/footnote.ts +0 -4
- package/src/parser/source/escapable.test.ts +1 -1
- package/src/parser/source/escapable.ts +7 -1
- package/src/parser/source/text.test.ts +24 -35
- package/src/parser/source/text.ts +2 -15
- package/src/parser/visibility.ts +1 -6
- package/src/util/toc.ts +0 -2
- package/src/parser/locale/ja.test.ts +0 -14
- package/src/parser/locale/ja.ts +0 -3
- package/src/parser/locale.test.ts +0 -26
- package/src/parser/locale.ts +0 -61
|
@@ -3,10 +3,9 @@ import { union, creation, focus } from '../../combinator';
|
|
|
3
3
|
import { str } from './str';
|
|
4
4
|
import { html } from 'typed-dom/dom';
|
|
5
5
|
|
|
6
|
-
export const delimiter = /[\s\x00-\x7F]|\S[#>]
|
|
6
|
+
export const delimiter = /[\s\x00-\x7F]|\S[#>]/u;
|
|
7
7
|
export const nonWhitespace = /[\S\n]|$/;
|
|
8
8
|
export const nonAlphanumeric = /[^0-9A-Za-z]|\S[#>]|$/;
|
|
9
|
-
const nssb = /^[\p{Ideo}\p{scx=Hiragana}\p{scx=Katakana}~!?][^\S\n]*(?=\\\n)/u;
|
|
10
9
|
const repeat = str(/^(.)\1*/);
|
|
11
10
|
|
|
12
11
|
export const text: TextParser = creation(1, false, ({ source, context }) => {
|
|
@@ -16,26 +15,14 @@ export const text: TextParser = creation(1, false, ({ source, context }) => {
|
|
|
16
15
|
case -1:
|
|
17
16
|
return [[source], ''];
|
|
18
17
|
case 0:
|
|
19
|
-
switch (source[0]) {
|
|
20
|
-
case '\x1B':
|
|
21
|
-
case '\\':
|
|
22
|
-
if (!nssb.test(source.slice(1))) break;
|
|
23
|
-
assert(source[0] !== '\x1B');
|
|
24
|
-
return text({ source: source.slice(1), context });
|
|
25
|
-
default:
|
|
26
|
-
const i = source.match(nssb)?.[0].length ?? -1;
|
|
27
|
-
if (i !== -1) return [[source[0], html('span', { class: 'linebreak' })], source.slice(i + 2)];
|
|
28
|
-
}
|
|
29
18
|
switch (source[0]) {
|
|
30
19
|
case '\x1B':
|
|
31
20
|
case '\\':
|
|
32
21
|
switch (source[1]) {
|
|
33
22
|
case undefined:
|
|
34
|
-
assert(source[0] !== '\x1B');
|
|
35
|
-
return [[], ''];
|
|
36
23
|
case '\n':
|
|
37
24
|
assert(source[0] !== '\x1B');
|
|
38
|
-
return [[
|
|
25
|
+
return [[], source.slice(1)];
|
|
39
26
|
default:
|
|
40
27
|
return [[source.slice(1, 2)], source.slice(2)];
|
|
41
28
|
}
|
package/src/parser/visibility.ts
CHANGED
|
@@ -108,10 +108,7 @@ export function isStartLooseNodes(nodes: readonly (HTMLElement | string)[]): boo
|
|
|
108
108
|
for (let i = 0; i < nodes.length; ++i) {
|
|
109
109
|
const node = nodes[i];
|
|
110
110
|
if (isVisible(node)) return true;
|
|
111
|
-
if (typeof node === 'object')
|
|
112
|
-
if (node.tagName === 'BR') break;
|
|
113
|
-
if (node.className === 'linebreak') break;
|
|
114
|
-
}
|
|
111
|
+
if (typeof node === 'object' && node.tagName === 'BR') break;
|
|
115
112
|
}
|
|
116
113
|
return false;
|
|
117
114
|
}
|
|
@@ -143,8 +140,6 @@ function isVisible(node: HTMLElement | string, strpos?: number): boolean {
|
|
|
143
140
|
case 'BR':
|
|
144
141
|
case 'WBR':
|
|
145
142
|
return false;
|
|
146
|
-
case 'SPAN':
|
|
147
|
-
return node.className !== 'linebreak';
|
|
148
143
|
default:
|
|
149
144
|
return true;
|
|
150
145
|
}
|
package/src/util/toc.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { push } from 'spica/array';
|
|
2
2
|
import { html } from 'typed-dom/dom';
|
|
3
3
|
|
|
4
|
-
// Bug: Firefox
|
|
5
|
-
//const selector = `:scope > :is(h1, h2, h3, h4, h5, h6, aside.aside)[id]`;
|
|
6
4
|
const selector = ':is(h1, h2, h3, h4, h5, h6, aside.aside)[id]';
|
|
7
5
|
|
|
8
6
|
export function toc(source: DocumentFragment | HTMLElement | ShadowRoot): HTMLUListElement {
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { japanese } from './ja';
|
|
2
|
-
|
|
3
|
-
describe('Unit: parser/locale/ja', () => {
|
|
4
|
-
describe('japanese', () => {
|
|
5
|
-
it('ja', () => {
|
|
6
|
-
assert(japanese('、'));
|
|
7
|
-
assert(japanese('。'));
|
|
8
|
-
assert(japanese('!'));
|
|
9
|
-
assert(japanese('?'));
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
});
|
package/src/parser/locale/ja.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { block } from './block';
|
|
2
|
-
import { some } from '../combinator';
|
|
3
|
-
import { inspect } from '../debug.test';
|
|
4
|
-
|
|
5
|
-
describe('Unit: parser/locale', () => {
|
|
6
|
-
describe('locale', () => {
|
|
7
|
-
const parser = (source: string) => some(block)({ source, context: {} });
|
|
8
|
-
|
|
9
|
-
it('basic', () => {
|
|
10
|
-
assert.deepStrictEqual(inspect(parser('。\\\n0')), [['<p>。<span class="linebreak"></span>0</p>'], '']);
|
|
11
|
-
assert.deepStrictEqual(inspect(parser('。 \\\n0')), [['<p>。<span class="linebreak"></span>0</p>'], '']);
|
|
12
|
-
assert.deepStrictEqual(inspect(parser('_。_\\\n0')), [['<p><em>。</em><span class="linebreak"></span>0</p>'], '']);
|
|
13
|
-
assert.deepStrictEqual(inspect(parser('!> 。\\\n0')), [['<blockquote><section><p>。<span class="linebreak"></span>0</p><h2>References</h2><ol class="references"></ol></section></blockquote>'], '']);
|
|
14
|
-
assert.deepStrictEqual(inspect(parser('[。](a)\\\n0')), [['<p><ruby>。<rp>(</rp><rt>a</rt><rp>)</rp></ruby><span class="linebreak"></span>0</p>'], '']);
|
|
15
|
-
assert.deepStrictEqual(inspect(parser('[。 ](a )\\\n0')), [['<p><ruby>。<rp>(</rp><rt>a</rt><rp>)</rp></ruby><span class="linebreak"></span>0</p>'], '']);
|
|
16
|
-
assert.deepStrictEqual(inspect(parser('。<wbr>\\\n0')), [['<p>。<wbr><span class="linebreak"></span>0</p>'], '']);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('ja', () => {
|
|
20
|
-
assert.deepStrictEqual(inspect(parser('。\\\n0')), [['<p>。<span class="linebreak"></span>0</p>'], '']);
|
|
21
|
-
assert.deepStrictEqual(inspect(parser('\\。\\\n0')), [['<p>。<span class="linebreak"></span>0</p>'], '']);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
});
|
package/src/parser/locale.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { Parser } from '../combinator/data/parser';
|
|
2
|
-
import { fmap } from '../combinator';
|
|
3
|
-
import { japanese } from './locale/ja';
|
|
4
|
-
import { html } from 'typed-dom/dom';
|
|
5
|
-
|
|
6
|
-
export function localize<P extends Parser<HTMLElement | string>>(parser: P): P;
|
|
7
|
-
export function localize(parser: Parser<HTMLElement | string>): Parser<HTMLElement | string> {
|
|
8
|
-
return fmap(parser, ns => {
|
|
9
|
-
if (ns.length === 0) return ns;
|
|
10
|
-
const el = ns.length === 1 && typeof ns[0] === 'object'
|
|
11
|
-
? ns[0]
|
|
12
|
-
: html('div', ns);
|
|
13
|
-
for (let es = el.querySelectorAll('.linebreak:not(:empty)'),
|
|
14
|
-
len = es.length, i = 0; i < len; ++i) {
|
|
15
|
-
const el = es[i];
|
|
16
|
-
assert(el.firstChild!.textContent === ' ');
|
|
17
|
-
if (!check(el)) continue;
|
|
18
|
-
el.firstChild!.remove();
|
|
19
|
-
}
|
|
20
|
-
return ns;
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function check(el: Element): boolean {
|
|
25
|
-
const char = lastChar(el);
|
|
26
|
-
if (!char) return false;
|
|
27
|
-
assert([...char].length === 1);
|
|
28
|
-
return japanese(char);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function lastChar(node: Element | Text | null): string {
|
|
32
|
-
while (node = node?.previousSibling as typeof node) {
|
|
33
|
-
if (!('id' in node)) return [...node.data.slice(-2)].pop() ?? '';
|
|
34
|
-
if (node.firstChild) return [...text(node).slice(-2)].pop() ?? '';
|
|
35
|
-
switch (node.tagName) {
|
|
36
|
-
case 'BR':
|
|
37
|
-
return '';
|
|
38
|
-
case 'SPAN':
|
|
39
|
-
switch (node.className) {
|
|
40
|
-
case 'linebreak':
|
|
41
|
-
return '';
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
return '';
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function text(el: Element): string {
|
|
49
|
-
switch (el.tagName) {
|
|
50
|
-
case 'RUBY':
|
|
51
|
-
for (let ns = el.childNodes, i = ns.length; i--;) {
|
|
52
|
-
const child = ns[i] as Text | Element;
|
|
53
|
-
if ('id' in child) continue;
|
|
54
|
-
return child.data;
|
|
55
|
-
}
|
|
56
|
-
assert(false);
|
|
57
|
-
return '';
|
|
58
|
-
default:
|
|
59
|
-
return el.textContent!;
|
|
60
|
-
}
|
|
61
|
-
}
|