securemark 0.276.1 → 0.276.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 +8 -0
- package/design.md +1 -0
- package/dist/index.js +207 -160
- package/package.json +10 -10
- package/src/combinator/control/manipulation/fence.ts +1 -1
- package/src/parser/api/bind.test.ts +3 -3
- package/src/parser/api/parse.test.ts +33 -33
- package/src/parser/block/blockquote.test.ts +1 -1
- package/src/parser/block/extension/example.test.ts +1 -1
- package/src/parser/inline/link.ts +13 -13
- package/src/parser/inline/mark.ts +2 -6
- package/src/parser/inline/ruby.ts +1 -1
- package/src/parser/processor/note.test.ts +25 -30
- package/src/parser/processor/note.ts +34 -21
- package/src/parser/visibility.ts +17 -17
- package/webpack.config.js +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { identity, signature, text } from '../inline/extension/indexee';
|
|
2
2
|
import { markInvalid, unmarkInvalid } from '../util';
|
|
3
|
+
import { memoize } from 'spica/memoize';
|
|
3
4
|
import { html, define } from 'typed-dom/dom';
|
|
4
5
|
|
|
5
6
|
export function* note(
|
|
@@ -26,12 +27,38 @@ export const reference = build('reference', (n, abbr) => `[${abbr || n}]`);
|
|
|
26
27
|
|
|
27
28
|
function build(
|
|
28
29
|
syntax: 'annotation' | 'reference',
|
|
29
|
-
marker: (index: number, abbr: string
|
|
30
|
+
marker: (index: number, abbr: string) => string,
|
|
30
31
|
splitter: string = '',
|
|
31
32
|
) {
|
|
32
33
|
assert(syntax.match(/^[a-z]+$/));
|
|
33
34
|
// Referenceを含むAnnotationの重複排除は両構文が互いに処理済みであることを必要とするため
|
|
34
35
|
// 構文ごとに各1回の処理では不可能
|
|
36
|
+
const memory = memoize((ref: HTMLElement): {
|
|
37
|
+
readonly content: Element;
|
|
38
|
+
readonly identifier: string;
|
|
39
|
+
readonly abbr: string;
|
|
40
|
+
readonly text: string;
|
|
41
|
+
} => {
|
|
42
|
+
const content = ref.firstElementChild!;
|
|
43
|
+
content.replaceWith(content.cloneNode());
|
|
44
|
+
const abbr = ref.getAttribute('data-abbr') ?? '';
|
|
45
|
+
const identifier = abbr
|
|
46
|
+
? identity(
|
|
47
|
+
undefined,
|
|
48
|
+
(
|
|
49
|
+
abbr.match(/^(?:\S+ )+?(?:(?:January|February|March|April|May|June|August|September|October|November|December) \d{1,2}(?:-\d{0,2})?, \d{1,4}(?:-\d{0,4})?[a-z]?|n\.d\.)(?=,|$)/)?.[0] ??
|
|
50
|
+
abbr.match(/^[^,\s]+(?:,? [^,\s]+)*?(?: \d{1,4}(?:-\d{0,4})?[a-z]?(?=,|$)|(?=,(?: [a-z]+\.?)? [0-9]))/)?.[0] ??
|
|
51
|
+
abbr
|
|
52
|
+
),
|
|
53
|
+
'')?.slice(2) || ''
|
|
54
|
+
: identity(undefined, signature(content), 'mark')?.slice(6) || '';
|
|
55
|
+
return {
|
|
56
|
+
content,
|
|
57
|
+
identifier,
|
|
58
|
+
abbr,
|
|
59
|
+
text: text(content).trim(),
|
|
60
|
+
};
|
|
61
|
+
}, new WeakMap());
|
|
35
62
|
return function* (
|
|
36
63
|
target: ParentNode & Node,
|
|
37
64
|
note?: HTMLOListElement,
|
|
@@ -51,7 +78,7 @@ function build(
|
|
|
51
78
|
let refIndex = 0;
|
|
52
79
|
for (let len = refs.length, i = 0; i < len; ++i) {
|
|
53
80
|
const ref = refs[i];
|
|
54
|
-
if (
|
|
81
|
+
if (!target.contains(ref)) {
|
|
55
82
|
yield;
|
|
56
83
|
continue;
|
|
57
84
|
}
|
|
@@ -69,17 +96,7 @@ function build(
|
|
|
69
96
|
yield;
|
|
70
97
|
}
|
|
71
98
|
}
|
|
72
|
-
const abbr = ref
|
|
73
|
-
const identifier = abbr
|
|
74
|
-
? identity(
|
|
75
|
-
undefined,
|
|
76
|
-
(
|
|
77
|
-
abbr.match(/^(?:\S+ )+?(?:(?:January|February|March|April|May|June|August|September|October|November|December) \d{1,2}(?:-\d{0,2})?, \d{1,4}(?:-\d{0,4})?[a-z]?|n\.d\.)(?=,|$)/)?.[0] ??
|
|
78
|
-
abbr.match(/^[^,\s]+(?:,? [^,\s]+)*?(?: \d{1,4}(?:-\d{0,4})?[a-z]?(?=,|$)|(?=,(?: [a-z]+\.?)? [0-9]))/)?.[0] ??
|
|
79
|
-
abbr
|
|
80
|
-
),
|
|
81
|
-
'')?.slice(2) || ''
|
|
82
|
-
: identity(undefined, signature(ref.firstElementChild!), 'mark')?.slice(6) || '';
|
|
99
|
+
const { content, identifier, abbr, text } = memory(ref);
|
|
83
100
|
const refSubindex = refSubindexes.get(identifier)! + 1 || 1;
|
|
84
101
|
refSubindexes.set(identifier, refSubindex);
|
|
85
102
|
const refId = opts.id !== ''
|
|
@@ -99,7 +116,7 @@ function build(
|
|
|
99
116
|
id: defId,
|
|
100
117
|
'data-marker': note ? undefined : marker(total + defs.size + 1, abbr),
|
|
101
118
|
},
|
|
102
|
-
[
|
|
119
|
+
[content.cloneNode(true), html('sup')])
|
|
103
120
|
: defs.get(identifier)!;
|
|
104
121
|
initial && defs.set(identifier, def);
|
|
105
122
|
assert(def.lastElementChild?.matches('sup'));
|
|
@@ -107,14 +124,10 @@ function build(
|
|
|
107
124
|
? total + defs.size
|
|
108
125
|
: defIndexes.get(def)!;
|
|
109
126
|
initial && defIndexes.set(def, defIndex);
|
|
110
|
-
const title = initial
|
|
111
|
-
? text(ref.firstElementChild!).trim()
|
|
112
|
-
: titles.get(identifier)!;
|
|
127
|
+
const title = initial ? text : titles.get(identifier)!;
|
|
113
128
|
initial && titles.set(identifier, title);
|
|
114
129
|
assert(syntax !== 'annotation' || title);
|
|
115
|
-
ref.
|
|
116
|
-
? ref.lastElementChild!.remove()
|
|
117
|
-
: ref.firstElementChild!.setAttribute('hidden', '');
|
|
130
|
+
ref.childElementCount > 1 && ref.lastElementChild!.remove();
|
|
118
131
|
define(ref, {
|
|
119
132
|
id: refId,
|
|
120
133
|
class: opts.id !== '' ? undefined : void ref.classList.add('disabled'),
|
|
@@ -140,7 +153,7 @@ function build(
|
|
|
140
153
|
html('a',
|
|
141
154
|
{
|
|
142
155
|
href: refId && `#${refId}`,
|
|
143
|
-
title: abbr &&
|
|
156
|
+
title: abbr && text || undefined,
|
|
144
157
|
},
|
|
145
158
|
`^${++refIndex}`));
|
|
146
159
|
}
|
package/src/parser/visibility.ts
CHANGED
|
@@ -167,23 +167,23 @@ function trimBlankEnd<T extends HTMLElement | string>(parser: Parser<T>): Parser
|
|
|
167
167
|
parser,
|
|
168
168
|
trimNodeEnd);
|
|
169
169
|
}
|
|
170
|
-
export function trimNode<T extends HTMLElement | string>(nodes: T[]): T[] {
|
|
171
|
-
return trimNodeStart(trimNodeEnd(nodes));
|
|
172
|
-
}
|
|
173
|
-
function trimNodeStart<T extends HTMLElement | string>(nodes: T[]): T[] {
|
|
174
|
-
for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[0], 0);) {
|
|
175
|
-
if (nodes.length === 1 && typeof node === 'object' && node.className === 'indexer') break;
|
|
176
|
-
if (typeof node === 'string') {
|
|
177
|
-
const pos = node.trimStart().length;
|
|
178
|
-
if (pos > 0) {
|
|
179
|
-
nodes[0] = node.slice(-pos) as T;
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
nodes.shift();
|
|
184
|
-
}
|
|
185
|
-
return nodes;
|
|
186
|
-
}
|
|
170
|
+
//export function trimNode<T extends HTMLElement | string>(nodes: T[]): T[] {
|
|
171
|
+
// return trimNodeStart(trimNodeEnd(nodes));
|
|
172
|
+
//}
|
|
173
|
+
//function trimNodeStart<T extends HTMLElement | string>(nodes: T[]): T[] {
|
|
174
|
+
// for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[0], 0);) {
|
|
175
|
+
// if (nodes.length === 1 && typeof node === 'object' && node.className === 'indexer') break;
|
|
176
|
+
// if (typeof node === 'string') {
|
|
177
|
+
// const pos = node.trimStart().length;
|
|
178
|
+
// if (pos > 0) {
|
|
179
|
+
// nodes[0] = node.slice(-pos) as T;
|
|
180
|
+
// break;
|
|
181
|
+
// }
|
|
182
|
+
// }
|
|
183
|
+
// nodes.shift();
|
|
184
|
+
// }
|
|
185
|
+
// return nodes;
|
|
186
|
+
//}
|
|
187
187
|
export function trimNodeEnd<T extends HTMLElement | string>(nodes: T[]): T[] {
|
|
188
188
|
const skip = nodes.length > 0 &&
|
|
189
189
|
typeof nodes[nodes.length - 1] === 'object' &&
|
package/webpack.config.js
CHANGED
|
@@ -81,7 +81,7 @@ module.exports = env => {
|
|
|
81
81
|
return merge(config);
|
|
82
82
|
case 'lint':
|
|
83
83
|
return merge(config, {
|
|
84
|
-
entry: glob.sync('./!(node_modules)/**/*.ts', { absolute: true }),
|
|
84
|
+
entry: glob.sync('./!(node_modules)/**/*.ts', { absolute: true }).sort(),
|
|
85
85
|
plugins: [
|
|
86
86
|
new ESLintPlugin({
|
|
87
87
|
extensions: ['ts'],
|
|
@@ -109,7 +109,7 @@ module.exports = env => {
|
|
|
109
109
|
});
|
|
110
110
|
case 'dist':
|
|
111
111
|
return merge(config, {
|
|
112
|
-
entry: glob.sync('./index.ts', { absolute: true }),
|
|
112
|
+
entry: glob.sync('./index.ts', { absolute: true }).sort(),
|
|
113
113
|
module: {
|
|
114
114
|
rules: [
|
|
115
115
|
{
|