securemark 0.223.0 → 0.225.1

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.
@@ -70,16 +70,18 @@ function hasVisible(
70
70
  return false;
71
71
  }
72
72
 
73
- export function startLoose<P extends Parser<HTMLElement | string>>(parser: P): P;
74
- export function startLoose<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
73
+ export function startLoose<P extends Parser<HTMLElement | string>>(parser: P, except?: string): P;
74
+ export function startLoose<T extends HTMLElement | string>(parser: Parser<T>, except?: string): Parser<T> {
75
75
  return (source, context) =>
76
- isStartLoose(source, context)
76
+ isStartLoose(source, context, except)
77
77
  ? parser(source, context)
78
78
  : undefined;
79
79
  }
80
- function isStartLoose(source: string, context: MarkdownParser.Context): boolean {
80
+ export function isStartLoose(source: string, context: MarkdownParser.Context, except?: string): boolean {
81
+ source &&= source.replace(/^[^\S\n]+/, '');
81
82
  if (source === '') return true;
82
- return isStartTight(source.replace(/^[^\S\n]+/, ''), context);
83
+ return source.slice(0, except?.length ?? 0) !== except
84
+ && isStartTight(source, context);
83
85
  }
84
86
  export function startTight<P extends Parser<unknown>>(parser: P): P;
85
87
  export function startTight<T>(parser: Parser<T>): Parser<T> {
@@ -88,7 +90,7 @@ export function startTight<T>(parser: Parser<T>): Parser<T> {
88
90
  ? parser(source, context)
89
91
  : undefined;
90
92
  }
91
- export function isStartTight(source: string, context: MarkdownParser.Context): boolean {
93
+ function isStartTight(source: string, context: MarkdownParser.Context): boolean {
92
94
  if (source === '') return true;
93
95
  switch (source[0]) {
94
96
  case ' ':
@@ -133,22 +135,7 @@ export function isStartTightNodes(nodes: readonly (HTMLElement | string)[]): boo
133
135
  }
134
136
  export function isEndTightNodes(nodes: readonly (HTMLElement | string)[]): boolean {
135
137
  if (nodes.length === 0) return true;
136
- const last = nodes.length - 1;
137
- return typeof nodes[last] === 'string' && (nodes[last] as string).length > 1
138
- ? isVisible(nodes[last], -1) ||
139
- isVisible(nodes[last], -2)
140
- : isVisible(nodes[last], -1) || last === 0 ||
141
- isVisible(nodes[last - 1], -1);
142
- }
143
- export function visible<P extends Parser<HTMLElement | string>>(parser: P): P;
144
- export function visible<T extends HTMLElement | string>(parser: Parser<T>): Parser<T> {
145
- return verify(parser, nodes => {
146
- if (nodes.length === 0) return true;
147
- for (let i = 0; i < nodes.length; ++i) {
148
- if (isVisible(nodes[i])) return true;
149
- }
150
- return false;
151
- });
138
+ return isVisible(nodes[nodes.length - 1], -1);
152
139
  }
153
140
  function isVisible(node: HTMLElement | string, position?: number): boolean {
154
141
  if (!node) return false;
@@ -185,28 +172,19 @@ export function trimNode(nodes: (HTMLElement | string)[]): (HTMLElement | string
185
172
  return trimNodeStart(trimNodeEnd(nodes));
186
173
  }
187
174
  function trimNodeStart(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
188
- const skip = nodes.length > 0 &&
189
- typeof nodes[nodes.length - 1] === 'object' &&
190
- nodes[nodes.length - 1]['className'] === 'indexer'
191
- ? [nodes.pop()!]
192
- : [];
193
- for (
194
- let first = nodes[0];
195
- nodes.length > 0 &&
196
- !isVisible(first, 0) &&
197
- !(typeof first === 'object' && first.className === 'comment');
198
- ) {
199
- assert(nodes.length > 0);
200
- if (typeof first === 'string') {
201
- const pos = first.length - first.trimStart().length;
175
+ for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[0], 0);) {
176
+ if (nodes.length === 1 && typeof node === 'object' && node.className === 'indexer') break;
177
+ if (typeof node === 'object' && node.className === 'comment') break;
178
+ if (typeof node === 'string') {
179
+ const pos = node.length - node.trimStart().length;
202
180
  if (pos > 0) {
203
- nodes[0] = first.slice(pos);
181
+ nodes[0] = node.slice(pos);
204
182
  break;
205
183
  }
206
184
  }
207
- nodes.pop();
185
+ nodes.shift();
208
186
  }
209
- return push(nodes, skip);
187
+ return nodes;
210
188
  }
211
189
  export function trimNodeEnd(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
212
190
  const skip = nodes.length > 0 &&
@@ -214,17 +192,12 @@ export function trimNodeEnd(nodes: (HTMLElement | string)[]): (HTMLElement | str
214
192
  nodes[nodes.length - 1]['className'] === 'indexer'
215
193
  ? [nodes.pop()!]
216
194
  : [];
217
- for (
218
- let last = nodes[0];
219
- nodes.length > 0 &&
220
- !isVisible(last = nodes[nodes.length - 1], -1) &&
221
- !(typeof last === 'object' && last.className === 'comment');
222
- ) {
223
- assert(nodes.length > 0);
224
- if (typeof last === 'string') {
225
- const pos = last.trimEnd().length;
195
+ for (let node = nodes[0]; nodes.length > 0 && !isVisible(node = nodes[nodes.length - 1], -1);) {
196
+ if (typeof node === 'object' && node.className === 'comment') break;
197
+ if (typeof node === 'string') {
198
+ const pos = node.trimEnd().length;
226
199
  if (pos > 0) {
227
- nodes[nodes.length - 1] = last.slice(0, pos);
200
+ nodes[nodes.length - 1] = node.slice(0, pos);
228
201
  break;
229
202
  }
230
203
  }
@@ -232,8 +205,8 @@ export function trimNodeEnd(nodes: (HTMLElement | string)[]): (HTMLElement | str
232
205
  }
233
206
  return push(nodes, skip);
234
207
  }
235
- export function trimEndBR<T extends HTMLElement | string>(nodes: T[]): T[];
236
- export function trimEndBR(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
208
+ export function trimNodeEndBR<T extends HTMLElement | string>(nodes: T[]): T[];
209
+ export function trimNodeEndBR(nodes: (HTMLElement | string)[]): (HTMLElement | string)[] {
237
210
  if (nodes.length === 0) return nodes;
238
211
  const node = nodes[nodes.length - 1];
239
212
  return typeof node === 'object' && node.tagName === 'BR'
@@ -12,7 +12,6 @@ const extend = reduce((opts: RenderingOptions): RenderingOptions =>
12
12
 
13
13
  export function render(source: HTMLElement, opts: RenderingOptions = {}): void {
14
14
  opts = extend(opts);
15
- if (source.classList.contains('invalid')) return;
16
15
  const base = location.href;
17
16
  if (source.matches(selector)) return void render_(base, source, opts);
18
17
  for (
@@ -23,7 +22,7 @@ export function render(source: HTMLElement, opts: RenderingOptions = {}): void {
23
22
  }
24
23
 
25
24
  function render_(base: string, source: HTMLElement, opts: RenderingOptions): void {
26
- assert(!source.matches('.invalid'));
25
+ if (source.classList.contains('invalid')) return;
27
26
  try {
28
27
  switch (true) {
29
28
  case !!opts.code