securemark 0.256.0 → 0.257.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 +14 -0
- package/README.md +21 -8
- package/dist/index.js +237 -197
- package/markdown.d.ts +23 -17
- package/package.json +1 -1
- package/src/combinator/control/manipulation/context.ts +13 -2
- package/src/combinator/control/manipulation/resource.ts +36 -2
- package/src/combinator/control/manipulation/surround.ts +6 -6
- 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 +16 -38
- package/src/combinator/data/parser.ts +34 -18
- package/src/debug.test.ts +2 -2
- package/src/parser/api/bind.ts +9 -11
- package/src/parser/api/parse.test.ts +48 -11
- package/src/parser/block.ts +1 -1
- package/src/parser/inline/annotation.test.ts +7 -5
- package/src/parser/inline/annotation.ts +10 -6
- package/src/parser/inline/autolink/account.ts +3 -7
- package/src/parser/inline/autolink/anchor.ts +3 -7
- package/src/parser/inline/autolink/hashnum.ts +3 -7
- package/src/parser/inline/autolink/hashtag.ts +3 -7
- package/src/parser/inline/autolink/url.test.ts +1 -0
- package/src/parser/inline/autolink/url.ts +7 -8
- package/src/parser/inline/bracket.test.ts +13 -7
- package/src/parser/inline/bracket.ts +10 -10
- package/src/parser/inline/comment.test.ts +5 -3
- package/src/parser/inline/comment.ts +4 -4
- package/src/parser/inline/deletion.ts +3 -3
- package/src/parser/inline/emphasis.ts +3 -3
- package/src/parser/inline/emstrong.ts +4 -5
- package/src/parser/inline/extension/index.test.ts +1 -0
- package/src/parser/inline/extension/index.ts +8 -7
- package/src/parser/inline/extension/indexer.ts +3 -5
- package/src/parser/inline/extension/label.ts +1 -1
- package/src/parser/inline/extension/placeholder.test.ts +1 -0
- package/src/parser/inline/extension/placeholder.ts +4 -4
- package/src/parser/inline/html.test.ts +2 -0
- package/src/parser/inline/html.ts +5 -5
- package/src/parser/inline/insertion.ts +3 -3
- package/src/parser/inline/link.test.ts +1 -0
- package/src/parser/inline/link.ts +58 -17
- package/src/parser/inline/mark.ts +3 -3
- package/src/parser/inline/math.test.ts +21 -14
- package/src/parser/inline/math.ts +7 -19
- package/src/parser/inline/media.test.ts +0 -2
- package/src/parser/inline/media.ts +10 -10
- package/src/parser/inline/reference.test.ts +6 -5
- package/src/parser/inline/reference.ts +12 -8
- package/src/parser/inline/ruby.ts +29 -27
- package/src/parser/inline/strong.ts +3 -3
- package/src/parser/inline/template.ts +4 -4
- package/src/parser/inline.test.ts +13 -8
- package/src/parser/inline.ts +1 -0
- package/src/parser/util.ts +35 -19
package/src/parser/util.ts
CHANGED
|
@@ -5,9 +5,25 @@ import { union, some, verify, convert, fmap } 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 { reduce } from 'spica/memoize';
|
|
8
|
+
import { memoize, reduce } from 'spica/memoize';
|
|
9
9
|
import { push } from 'spica/array';
|
|
10
10
|
|
|
11
|
+
export function clean<P extends Parser<unknown>>(parser: P): P;
|
|
12
|
+
export function clean<T>(parser: Parser<T, MarkdownParser.Context>): Parser<T, MarkdownParser.Context> {
|
|
13
|
+
const clean = memoize<MarkdownParser.Context, MarkdownParser.Context>(context => ({
|
|
14
|
+
resources: context.resources,
|
|
15
|
+
precedence: context.precedence,
|
|
16
|
+
delimiters: context.delimiters,
|
|
17
|
+
host: context.host,
|
|
18
|
+
url: context.url,
|
|
19
|
+
id: context.id,
|
|
20
|
+
header: context.header,
|
|
21
|
+
cache: context.caches,
|
|
22
|
+
}), new WeakMap());
|
|
23
|
+
return (source, context) =>
|
|
24
|
+
parser(source, context.syntax ? clean(context) : context);
|
|
25
|
+
}
|
|
26
|
+
|
|
11
27
|
export const regBlankStart = new RegExp(
|
|
12
28
|
/^(?:\\?[^\S\n]|&IHN;|<wbr>)+/.source.replace('IHN', `(?:${invisibleHTMLEntityNames.join('|')})`));
|
|
13
29
|
|
|
@@ -166,24 +182,24 @@ export function trimBlankEnd<T extends HTMLElement | string>(parser: Parser<T>):
|
|
|
166
182
|
parser,
|
|
167
183
|
trimNodeEnd);
|
|
168
184
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
185
|
+
export function trimNode<T extends HTMLElement | string>(nodes: T[]): T[] {
|
|
186
|
+
return trimNodeStart(trimNodeEnd(nodes));
|
|
187
|
+
}
|
|
188
|
+
function trimNodeStart<T extends HTMLElement | string>(nodes: T[]): T[] {
|
|
189
|
+
for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[0], 0);) {
|
|
190
|
+
if (nodes.length === 1 && typeof node === 'object' && node.className === 'indexer') break;
|
|
191
|
+
if (typeof node === 'string') {
|
|
192
|
+
const pos = node.trimStart().length;
|
|
193
|
+
if (pos > 0) {
|
|
194
|
+
nodes[0] = node.slice(pos) as T;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
nodes.shift();
|
|
199
|
+
}
|
|
200
|
+
return nodes;
|
|
201
|
+
}
|
|
202
|
+
function trimNodeEnd<T extends HTMLElement | string>(nodes: T[]): T[] {
|
|
187
203
|
const skip = nodes.length > 0 &&
|
|
188
204
|
typeof nodes[nodes.length - 1] === 'object' &&
|
|
189
205
|
nodes[nodes.length - 1]['className'] === 'indexer'
|