securemark 0.235.0 → 0.235.3
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 +12 -0
- package/dist/securemark.js +197 -177
- package/markdown.d.ts +5 -2
- package/package-lock.json +36 -60
- package/package.json +3 -3
- package/src/combinator/control/manipulation/context.test.ts +4 -4
- package/src/combinator/control/manipulation/resource.ts +6 -3
- package/src/combinator/control/manipulation/surround.ts +3 -4
- package/src/combinator/data/parser/inits.ts +1 -1
- package/src/combinator/data/parser/sequence.ts +1 -1
- package/src/combinator/data/parser/some.ts +23 -25
- package/src/combinator/data/parser.ts +33 -10
- package/src/parser/api/bind.test.ts +3 -3
- package/src/parser/api/parse.test.ts +12 -5
- package/src/parser/block/blockquote.test.ts +1 -1
- package/src/parser/block/extension/aside.test.ts +1 -1
- package/src/parser/block/extension/example.test.ts +2 -2
- package/src/parser/block/extension/fig.test.ts +20 -20
- package/src/parser/block/extension/figure.test.ts +31 -28
- package/src/parser/block/extension/figure.ts +5 -3
- package/src/parser/block/extension/table.ts +6 -6
- package/src/parser/block/paragraph.test.ts +1 -1
- package/src/parser/block.ts +1 -2
- package/src/parser/inline/annotation.ts +3 -3
- package/src/parser/inline/bracket.test.ts +10 -10
- package/src/parser/inline/bracket.ts +5 -8
- package/src/parser/inline/deletion.test.ts +4 -1
- package/src/parser/inline/deletion.ts +7 -4
- package/src/parser/inline/emphasis.ts +3 -6
- package/src/parser/inline/emstrong.ts +7 -8
- package/src/parser/inline/html.test.ts +25 -17
- package/src/parser/inline/html.ts +39 -15
- package/src/parser/inline/htmlentity.test.ts +1 -1
- package/src/parser/inline/htmlentity.ts +17 -10
- package/src/parser/inline/insertion.test.ts +4 -1
- package/src/parser/inline/insertion.ts +7 -4
- package/src/parser/inline/link.test.ts +3 -0
- package/src/parser/inline/link.ts +6 -7
- package/src/parser/inline/mark.ts +3 -6
- package/src/parser/inline/media.test.ts +3 -0
- package/src/parser/inline/media.ts +1 -1
- package/src/parser/inline/reference.ts +6 -6
- package/src/parser/inline/ruby.ts +1 -1
- package/src/parser/inline/strong.test.ts +1 -1
- package/src/parser/inline/strong.ts +3 -6
- package/src/parser/inline.test.ts +2 -3
- package/src/parser/processor/figure.test.ts +28 -28
- package/src/parser/processor/figure.ts +1 -1
- package/src/parser/util.ts +43 -39
|
@@ -85,7 +85,7 @@ export function* figure(
|
|
|
85
85
|
? `(${number})`
|
|
86
86
|
: `${capitalize(group)}${group === 'fig' ? '.' : ''} ${number}`;
|
|
87
87
|
define(
|
|
88
|
-
def.querySelector(':scope > .figindex')!,
|
|
88
|
+
def.querySelector(':scope > figcaption > .figindex')!,
|
|
89
89
|
group === '$' ? figindex : `${figindex}. `);
|
|
90
90
|
for (const ref of refs.take(label, Infinity)) {
|
|
91
91
|
if (ref.hash.slice(1) === def.id && ref.innerText === figindex) continue;
|
package/src/parser/util.ts
CHANGED
|
@@ -5,15 +5,23 @@ import { union, some, verify, convert } from '../combinator';
|
|
|
5
5
|
import { unsafehtmlentity } from './inline/htmlentity';
|
|
6
6
|
import { linebreak, unescsource } from './source';
|
|
7
7
|
import { invisibleHTMLEntityNames } from './api/normalize';
|
|
8
|
-
import {
|
|
8
|
+
import { reduce } from 'spica/memoize';
|
|
9
|
+
import { push } from 'spica/array';
|
|
9
10
|
|
|
10
|
-
export function
|
|
11
|
-
return new RegExp(String.raw
|
|
11
|
+
export function blank(prefix: '' | RegExp, suffix: string | RegExp): RegExp {
|
|
12
|
+
return new RegExp(String.raw
|
|
13
|
+
`^${
|
|
14
|
+
prefix && prefix.source
|
|
15
|
+
}(?:\\\s|[^\S\n]+|\n|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr>)?${
|
|
16
|
+
typeof suffix === 'string' ? suffix.replace(/[*+()\[\]]/g, '\\$&') : suffix.source
|
|
17
|
+
}`);
|
|
12
18
|
}
|
|
13
19
|
|
|
14
20
|
export function visualize<P extends Parser<HTMLElement | string>>(parser: P): P;
|
|
15
21
|
export function visualize<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
|
|
16
|
-
const blankline = new RegExp(String.raw
|
|
22
|
+
const blankline = new RegExp(String.raw
|
|
23
|
+
`^(?:\\$|\\?[^\S\n]|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr>)+$`,
|
|
24
|
+
'gm');
|
|
17
25
|
return union([
|
|
18
26
|
convert(
|
|
19
27
|
source => source.replace(blankline, line => line.replace(/[\\&<]/g, '\x1B$&')),
|
|
@@ -45,11 +53,9 @@ export function startLoose<T extends HTMLElement | string>(parser: Parser<T>, ex
|
|
|
45
53
|
? parser(source, context)
|
|
46
54
|
: undefined;
|
|
47
55
|
}
|
|
48
|
-
export
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return isStartTight(source, context, except);
|
|
52
|
-
}
|
|
56
|
+
export const isStartLoose = reduce((source: string, context: MarkdownParser.Context, except?: string): boolean => {
|
|
57
|
+
return isStartTight(source.replace(/^[^\S\n]+/, ''), context, except);
|
|
58
|
+
}, (source, _, except = '') => `${source}\0${except}`);
|
|
53
59
|
export function startTight<P extends Parser<unknown>>(parser: P, except?: string): P;
|
|
54
60
|
export function startTight<T>(parser: Parser<T>, except?: string): Parser<T> {
|
|
55
61
|
return (source, context) =>
|
|
@@ -57,7 +63,7 @@ export function startTight<T>(parser: Parser<T>, except?: string): Parser<T> {
|
|
|
57
63
|
? parser(source, context)
|
|
58
64
|
: undefined;
|
|
59
65
|
}
|
|
60
|
-
|
|
66
|
+
const isStartTight = reduce((source: string, context: MarkdownParser.Context, except?: string): boolean => {
|
|
61
67
|
if (source === '') return true;
|
|
62
68
|
if (except && source.slice(0, except.length) === except) return false;
|
|
63
69
|
switch (source[0]) {
|
|
@@ -87,15 +93,15 @@ function isStartTight(source: string, context: MarkdownParser.Context, except?:
|
|
|
87
93
|
default:
|
|
88
94
|
return source[0].trimStart() !== '';
|
|
89
95
|
}
|
|
90
|
-
}
|
|
96
|
+
}, (source, _, except = '') => `${source}\0${except}`);
|
|
91
97
|
export function isStartTightNodes(nodes: readonly (HTMLElement | string)[]): boolean {
|
|
92
98
|
if (nodes.length === 0) return true;
|
|
93
99
|
return isVisible(nodes[0], 0);
|
|
94
100
|
}
|
|
95
|
-
export function isEndTightNodes(nodes: readonly (HTMLElement | string)[]): boolean {
|
|
96
|
-
if (nodes.length === 0) return true;
|
|
97
|
-
return isVisible(nodes[nodes.length - 1], -1);
|
|
98
|
-
}
|
|
101
|
+
//export function isEndTightNodes(nodes: readonly (HTMLElement | string)[]): boolean {
|
|
102
|
+
// if (nodes.length === 0) return true;
|
|
103
|
+
// return isVisible(nodes[nodes.length - 1], -1);
|
|
104
|
+
//}
|
|
99
105
|
function isVisible(node: HTMLElement | string, strpos?: number): boolean {
|
|
100
106
|
switch (typeof node) {
|
|
101
107
|
case 'string':
|
|
@@ -124,23 +130,29 @@ function isVisible(node: HTMLElement | string, strpos?: number): boolean {
|
|
|
124
130
|
}
|
|
125
131
|
}
|
|
126
132
|
|
|
127
|
-
export function
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (nodes.length === 1 && typeof node === 'object' && node.className === 'indexer') break;
|
|
133
|
-
if (typeof node === 'string') {
|
|
134
|
-
const pos = node.length - node.trimStart().length;
|
|
135
|
-
if (pos > 0) {
|
|
136
|
-
nodes[0] = node.slice(pos);
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
nodes.shift();
|
|
141
|
-
}
|
|
142
|
-
return nodes;
|
|
133
|
+
export function trimSpaceStart<P extends Parser<unknown>>(parser: P): P;
|
|
134
|
+
export function trimSpaceStart<T>(parser: Parser<T>): Parser<T> {
|
|
135
|
+
return convert(
|
|
136
|
+
reduce(source => source.replace(/^[^\S\n]+/, '')),
|
|
137
|
+
parser);
|
|
143
138
|
}
|
|
139
|
+
//export function trimNode(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
|
|
140
|
+
// return trimNodeStart(trimNodeEnd(nodes));
|
|
141
|
+
//}
|
|
142
|
+
//function trimNodeStart(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
|
|
143
|
+
// for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[0], 0);) {
|
|
144
|
+
// if (nodes.length === 1 && typeof node === 'object' && node.className === 'indexer') break;
|
|
145
|
+
// if (typeof node === 'string') {
|
|
146
|
+
// const pos = node.length - node.trimStart().length;
|
|
147
|
+
// if (pos > 0) {
|
|
148
|
+
// nodes[0] = node.slice(pos);
|
|
149
|
+
// break;
|
|
150
|
+
// }
|
|
151
|
+
// }
|
|
152
|
+
// nodes.shift();
|
|
153
|
+
// }
|
|
154
|
+
// return nodes;
|
|
155
|
+
//}
|
|
144
156
|
export function trimNodeEnd(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
|
|
145
157
|
const skip = nodes.length > 0 &&
|
|
146
158
|
typeof nodes[nodes.length - 1] === 'object' &&
|
|
@@ -159,14 +171,6 @@ export function trimNodeEnd(nodes: (HTMLElement | string)[]): (HTMLElement | str
|
|
|
159
171
|
}
|
|
160
172
|
return push(nodes, skip);
|
|
161
173
|
}
|
|
162
|
-
export function trimNodeEndBR<T extends HTMLElement | string>(nodes: T[]): T[];
|
|
163
|
-
export function trimNodeEndBR(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
|
|
164
|
-
if (nodes.length === 0) return nodes;
|
|
165
|
-
const node = nodes[nodes.length - 1];
|
|
166
|
-
return typeof node === 'object' && node.tagName === 'BR'
|
|
167
|
-
? pop(nodes)[0]
|
|
168
|
-
: nodes;
|
|
169
|
-
}
|
|
170
174
|
|
|
171
175
|
export function stringify(nodes: readonly (HTMLElement | string)[]): string {
|
|
172
176
|
let acc = '';
|