@scalar/code-highlight 0.4.15 → 0.4.17

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.
@@ -1,5 +1,5 @@
1
- import { i as convert, t as visit } from "./lib.js";
2
- //#region \0rolldown/runtime.js
1
+ import { t as visit } from "./lib.js";
2
+ // \0rolldown/runtime.js
3
3
  var __create = Object.create;
4
4
  var __defProp = Object.defineProperty;
5
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -30,11 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  value: mod,
31
31
  enumerable: true
32
32
  }) : target, mod));
33
- //#endregion
34
- //#region ../../node_modules/.pnpm/devlop@1.1.0/node_modules/devlop/lib/default.js
33
+ // ../../node_modules/.pnpm/devlop@1.1.0/node_modules/devlop/lib/default.js
35
34
  function ok() {}
36
- //#endregion
37
- //#region src/constants.ts
35
+ // src/constants.ts
38
36
  /** Map common markdown language shortcuts to lowlight languages */
39
37
  var lowlightLanguageMappings = {
40
38
  "ts": "typescript",
@@ -45,337 +43,69 @@ var lowlightLanguageMappings = {
45
43
  "c++": "cpp",
46
44
  "node": "javascript"
47
45
  };
48
- //#endregion
49
- //#region ../../node_modules/.pnpm/unist-util-find-after@5.0.0/node_modules/unist-util-find-after/lib/index.js
46
+ // ../../node_modules/.pnpm/hast-util-to-text@4.0.5/node_modules/hast-util-to-text/lib/index.js
50
47
  /**
51
- * @typedef {import('unist').Node} UnistNode
52
- * @typedef {import('unist').Parent} UnistParent
48
+ * @import {Comment, Element, Nodes, Parents, Text} from 'hast'
53
49
  */
54
50
  /**
55
- * @typedef {Exclude<import('unist-util-is').Test, undefined> | undefined} Test
56
- * Test from `unist-util-is`.
57
- *
58
- * Note: we have remove and add `undefined`, because otherwise when generating
59
- * automatic `.d.ts` files, TS tries to flatten paths from a local perspective,
60
- * which doesn’t work when publishing on npm.
61
- */
62
- /**
63
- * @typedef {(
64
- * Fn extends (value: any) => value is infer Thing
65
- * ? Thing
66
- * : Fallback
67
- * )} Predicate
68
- * Get the value of a type guard `Fn`.
69
- * @template Fn
70
- * Value; typically function that is a type guard (such as `(x): x is Y`).
71
- * @template Fallback
72
- * Value to yield if `Fn` is not a type guard.
73
- */
74
- /**
75
- * @typedef {(
76
- * Check extends null | undefined // No test.
77
- * ? Value
78
- * : Value extends {type: Check} // String (type) test.
79
- * ? Value
80
- * : Value extends Check // Partial test.
81
- * ? Value
82
- * : Check extends Function // Function test.
83
- * ? Predicate<Check, Value> extends Value
84
- * ? Predicate<Check, Value>
85
- * : never
86
- * : never // Some other test?
87
- * )} MatchesOne
88
- * Check whether a node matches a primitive check in the type system.
89
- * @template Value
90
- * Value; typically unist `Node`.
91
- * @template Check
92
- * Value; typically `unist-util-is`-compatible test, but not arrays.
93
- */
94
- /**
95
- * @typedef {(
96
- * Check extends Array<any>
97
- * ? MatchesOne<Value, Check[keyof Check]>
98
- * : MatchesOne<Value, Check>
99
- * )} Matches
100
- * Check whether a node matches a check in the type system.
101
- * @template Value
102
- * Value; typically unist `Node`.
103
- * @template Check
104
- * Value; typically `unist-util-is`-compatible test.
105
- */
106
- /**
107
- * @typedef {(
108
- * Kind extends {children: Array<infer Child>}
109
- * ? Child
110
- * : never
111
- * )} Child
112
- * Collect nodes that can be parents of `Child`.
113
- * @template {UnistNode} Kind
114
- * All node types.
115
- */
116
- /**
117
- * Find the first node in `parent` after another `node` or after an index,
118
- * that passes `test`.
119
- *
120
- * @param parent
121
- * Parent node.
122
- * @param index
123
- * Child node or index.
124
- * @param [test=undefined]
125
- * Test for child to look for (optional).
126
- * @returns
127
- * A child (matching `test`, if given) or `undefined`.
128
- */
129
- var findAfter = (
130
- /**
131
- * @param {UnistParent} parent
132
- * @param {UnistNode | number} index
133
- * @param {Test} [test]
134
- * @returns {UnistNode | undefined}
135
- */
136
- function(parent, index, test) {
137
- const is = convert(test);
138
- if (!parent || !parent.type || !parent.children) throw new Error("Expected parent node");
139
- if (typeof index === "number") {
140
- if (index < 0 || index === Number.POSITIVE_INFINITY) throw new Error("Expected positive finite number as index");
141
- } else {
142
- index = parent.children.indexOf(index);
143
- if (index < 0) throw new Error("Expected child node or index");
144
- }
145
- while (++index < parent.children.length) if (is(parent.children[index], index, parent)) return parent.children[index];
146
- });
147
- //#endregion
148
- //#region ../../node_modules/.pnpm/hast-util-is-element@3.0.0/node_modules/hast-util-is-element/lib/index.js
149
- /**
150
- * @typedef {import('hast').Element} Element
151
- * @typedef {import('hast').Parents} Parents
152
- */
153
- /**
154
- * @template Fn
155
- * @template Fallback
156
- * @typedef {Fn extends (value: any) => value is infer Thing ? Thing : Fallback} Predicate
157
- */
158
- /**
159
- * @callback Check
160
- * Check that an arbitrary value is an element.
161
- * @param {unknown} this
162
- * Context object (`this`) to call `test` with
163
- * @param {unknown} [element]
164
- * Anything (typically a node).
165
- * @param {number | null | undefined} [index]
166
- * Position of `element` in its parent.
167
- * @param {Parents | null | undefined} [parent]
168
- * Parent of `element`.
169
- * @returns {boolean}
170
- * Whether this is an element and passes a test.
171
- *
172
- * @typedef {Array<TestFunction | string> | TestFunction | string | null | undefined} Test
173
- * Check for an arbitrary element.
174
- *
175
- * * when `string`, checks that the element has that tag name
176
- * * when `function`, see `TestFunction`
177
- * * when `Array`, checks if one of the subtests pass
178
- *
179
- * @callback TestFunction
180
- * Check if an element passes a test.
181
- * @param {unknown} this
182
- * The given context.
183
- * @param {Element} element
184
- * An element.
185
- * @param {number | undefined} [index]
186
- * Position of `element` in its parent.
187
- * @param {Parents | undefined} [parent]
188
- * Parent of `element`.
189
- * @returns {boolean | undefined | void}
190
- * Whether this element passes the test.
191
- *
192
- * Note: `void` is included until TS sees no return as `undefined`.
193
- */
194
- /**
195
- * Check if `element` is an `Element` and whether it passes the given test.
196
- *
197
- * @param element
198
- * Thing to check, typically `element`.
199
- * @param test
200
- * Check for a specific element.
201
- * @param index
202
- * Position of `element` in its parent.
203
- * @param parent
204
- * Parent of `element`.
205
- * @param context
206
- * Context object (`this`) to call `test` with.
207
- * @returns
208
- * Whether `element` is an `Element` and passes a test.
209
- * @throws
210
- * When an incorrect `test`, `index`, or `parent` is given; there is no error
211
- * thrown when `element` is not a node or not an element.
212
- */
213
- var isElement = (
214
- /**
215
- * @param {unknown} [element]
216
- * @param {Test | undefined} [test]
217
- * @param {number | null | undefined} [index]
218
- * @param {Parents | null | undefined} [parent]
219
- * @param {unknown} [context]
220
- * @returns {boolean}
221
- */
222
- function(element, test, index, parent, context) {
223
- const check = convertElement(test);
224
- if (index !== null && index !== void 0 && (typeof index !== "number" || index < 0 || index === Number.POSITIVE_INFINITY)) throw new Error("Expected positive finite `index`");
225
- if (parent !== null && parent !== void 0 && (!parent.type || !parent.children)) throw new Error("Expected valid `parent`");
226
- if ((index === null || index === void 0) !== (parent === null || parent === void 0)) throw new Error("Expected both `index` and `parent`");
227
- return looksLikeAnElement(element) ? check.call(context, element, index, parent) : false;
228
- });
229
- /**
230
- * Generate a check from a test.
231
- *
232
- * Useful if you’re going to test many nodes, for example when creating a
233
- * utility where something else passes a compatible test.
234
- *
235
- * The created function is a bit faster because it expects valid input only:
236
- * an `element`, `index`, and `parent`.
237
- *
238
- * @param test
239
- * A test for a specific element.
240
- * @returns
241
- * A check.
242
- */
243
- var convertElement = (
244
- /**
245
- * @param {Test | null | undefined} [test]
246
- * @returns {Check}
247
- */
248
- function(test) {
249
- if (test === null || test === void 0) return element;
250
- if (typeof test === "string") return tagNameFactory(test);
251
- if (typeof test === "object") return anyFactory(test);
252
- if (typeof test === "function") return castFactory(test);
253
- throw new Error("Expected function, string, or array as `test`");
254
- });
255
- /**
256
- * Handle multiple tests.
257
- *
258
- * @param {Array<TestFunction | string>} tests
259
- * @returns {Check}
260
- */
261
- function anyFactory(tests) {
262
- /** @type {Array<Check>} */
263
- const checks = [];
264
- let index = -1;
265
- while (++index < tests.length) checks[index] = convertElement(tests[index]);
266
- return castFactory(any);
267
- /**
268
- * @this {unknown}
269
- * @type {TestFunction}
270
- */
271
- function any(...parameters) {
272
- let index = -1;
273
- while (++index < checks.length) if (checks[index].apply(this, parameters)) return true;
274
- return false;
275
- }
276
- }
277
- /**
278
- * Turn a string into a test for an element with a certain type.
279
- *
280
- * @param {string} check
281
- * @returns {Check}
282
- */
283
- function tagNameFactory(check) {
284
- return castFactory(tagName);
285
- /**
286
- * @param {Element} element
287
- * @returns {boolean}
288
- */
289
- function tagName(element) {
290
- return element.tagName === check;
291
- }
292
- }
293
- /**
294
- * Turn a custom test into a test for an element that passes that test.
295
- *
296
- * @param {TestFunction} testFunction
297
- * @returns {Check}
298
- */
299
- function castFactory(testFunction) {
300
- return check;
301
- /**
302
- * @this {unknown}
303
- * @type {Check}
304
- */
305
- function check(value, index, parent) {
306
- return Boolean(looksLikeAnElement(value) && testFunction.call(this, value, typeof index === "number" ? index : void 0, parent || void 0));
307
- }
308
- }
309
- /**
310
- * Make sure something is an element.
311
- *
312
- * @param {unknown} element
313
- * @returns {element is Element}
314
- */
315
- function element(element) {
316
- return Boolean(element && typeof element === "object" && "type" in element && element.type === "element" && "tagName" in element && typeof element.tagName === "string");
317
- }
318
- /**
319
- * @param {unknown} value
320
- * @returns {value is Element}
321
- */
322
- function looksLikeAnElement(value) {
323
- return value !== null && typeof value === "object" && "type" in value && "tagName" in value;
324
- }
325
- //#endregion
326
- //#region ../../node_modules/.pnpm/hast-util-to-text@4.0.2/node_modules/hast-util-to-text/lib/index.js
327
- /**
328
- * @typedef {import('hast').Comment} Comment
329
- * @typedef {import('hast').Element} Element
330
- * @typedef {import('hast').Nodes} Nodes
331
- * @typedef {import('hast').Parents} Parents
332
- * @typedef {import('hast').Text} Text
333
- * @typedef {import('hast-util-is-element').TestFunction} TestFunction
51
+ * @typedef BreakForce
52
+ * Forced break.
53
+ * @property {'\t' | '\n'} value
54
+ * Value.
334
55
  */
335
56
  /**
336
- * @typedef {'normal' | 'nowrap' | 'pre' | 'pre-wrap'} Whitespace
337
- * Valid and useful whitespace values (from CSS).
338
- *
339
57
  * @typedef {0 | 1 | 2} BreakNumber
340
58
  * Specific break:
341
59
  *
342
- * * `0` — space
60
+ * * `0` — collapsible space
343
61
  * * `1` — line ending
344
62
  * * `2` — blank line
345
- *
346
- * @typedef {'\n'} BreakForce
347
- * Forced break.
348
- *
349
- * @typedef {boolean} BreakValue
350
- * Whether there was a break.
351
- *
352
- * @typedef {BreakNumber | BreakValue | undefined} BreakBefore
353
- * Any value for a break before.
354
- *
355
- * @typedef {BreakForce | BreakNumber | BreakValue | undefined} BreakAfter
356
- * Any value for a break after.
357
- *
63
+ */
64
+ /**
358
65
  * @typedef CollectionInfo
359
66
  * Info on current collection.
360
- * @property {BreakAfter} breakAfter
361
- * Whether there was a break after.
362
- * @property {BreakBefore} breakBefore
363
- * Whether there was a break before.
67
+ * @property {boolean | undefined} [rowAfter]
68
+ * Whether a row comes later in the nearest table, after the current node or
69
+ * after the row group it is in.
364
70
  * @property {Whitespace} whitespace
365
71
  * Current whitespace setting.
366
- *
72
+ */
73
+ /**
74
+ * @typedef {BreakForce | BreakNumber | string} Item
75
+ * Item in a collection.
76
+ */
77
+ /**
367
78
  * @typedef Options
368
79
  * Configuration.
369
80
  * @property {Whitespace | null | undefined} [whitespace='normal']
370
81
  * Initial CSS whitespace setting to use (default: `'normal'`).
371
82
  */
83
+ /**
84
+ * @typedef {'normal' | 'nowrap' | 'pre' | 'pre-wrap'} Whitespace
85
+ * Valid and useful whitespace values (from CSS).
86
+ */
87
+ /** @type {BreakForce} */
88
+ var forcedLineFeed = { value: "\n" };
89
+ /** @type {BreakForce} */
90
+ var forcedTab = { value: " " };
372
91
  var searchLineFeeds = /\n/g;
373
92
  var searchTabOrSpaces = /[\t ]+/g;
374
- var br = convertElement("br");
375
- var cell = convertElement(isCell);
376
- var p = convertElement("p");
377
- var row = convertElement("tr");
378
- var notRendered = convertElement([
93
+ var startsWithTabOrSpace = /^[\t ]/;
94
+ var endsWithTabOrSpace = /[\t ]$/;
95
+ var trimTabOrSpaces = /^[\t ]+|[\t ]+$/g;
96
+ var whitespaceOnly = /^[\t\n\f\r ]+$/;
97
+ var tablePartNames = /* @__PURE__ */ new Set([
98
+ "caption",
99
+ "col",
100
+ "colgroup",
101
+ "tbody",
102
+ "td",
103
+ "tfoot",
104
+ "th",
105
+ "thead",
106
+ "tr"
107
+ ]);
108
+ var notRenderedNames = /* @__PURE__ */ new Set([
379
109
  "datalist",
380
110
  "head",
381
111
  "noembed",
@@ -385,11 +115,9 @@ var notRendered = convertElement([
385
115
  "script",
386
116
  "style",
387
117
  "template",
388
- "title",
389
- hidden,
390
- closedDialog
118
+ "title"
391
119
  ]);
392
- var blockOrCaption = convertElement([
120
+ var blockOrCaptionNames = /* @__PURE__ */ new Set([
393
121
  "address",
394
122
  "article",
395
123
  "aside",
@@ -406,7 +134,7 @@ var blockOrCaption = convertElement([
406
134
  "figure",
407
135
  "figcaption",
408
136
  "footer",
409
- "form,",
137
+ "form",
410
138
  "h1",
411
139
  "h2",
412
140
  "h3",
@@ -467,53 +195,63 @@ var blockOrCaption = convertElement([
467
195
  function toText(tree, options) {
468
196
  const options_ = options || {};
469
197
  const children = "children" in tree ? tree.children : [];
470
- const block = blockOrCaption(tree);
471
- const whitespace = inferWhitespace(tree, {
472
- whitespace: options_.whitespace || "normal",
473
- breakBefore: false,
474
- breakAfter: false
475
- });
476
- /** @type {Array<BreakNumber | string>} */
198
+ const inline = tree.type === "element" && tree.tagName !== "p" && tree.tagName !== "table" && !blockOrCaptionNames.has(tree.tagName) && !tablePartNames.has(tree.tagName);
199
+ let inTable = false;
200
+ if (tree.type === "element") inTable = tree.tagName === "table" || rowGroup(tree);
201
+ const whitespace = inferWhitespace(tree, { whitespace: options_.whitespace || "normal" });
202
+ /** @type {Array<Item>} */
477
203
  const results = [];
478
- if (tree.type === "text" || tree.type === "comment") results.push(...collectText(tree, {
479
- whitespace,
480
- breakBefore: true,
481
- breakAfter: true
482
- }));
204
+ if (tree.type === "text" || tree.type === "comment") append(results, collectText(tree));
483
205
  let index = -1;
484
- while (++index < children.length) results.push(...renderedTextCollection(children[index], tree, {
485
- whitespace,
486
- breakBefore: index ? void 0 : block,
487
- breakAfter: index < children.length - 1 ? br(children[index + 1]) : block
206
+ while (++index < children.length) append(results, renderedTextCollection(children[index], index, tree, {
207
+ rowAfter: inTable ? inferRowAfter(tree, index, void 0) : void 0,
208
+ whitespace
488
209
  }));
210
+ let force = false;
489
211
  /** @type {Array<string>} */
490
212
  const result = [];
491
213
  /** @type {number | undefined} */
492
- let count;
214
+ let count = inline ? -1 : void 0;
493
215
  index = -1;
494
216
  while (++index < results.length) {
495
217
  const value = results[index];
496
218
  if (typeof value === "number") {
497
219
  if (count !== void 0 && value > count) count = value;
498
220
  } else if (value) {
499
- if (count !== void 0 && count > -1) result.push("\n".repeat(count) || " ");
221
+ const forceBefore = force;
222
+ force = typeof value === "object";
223
+ if (count !== void 0 && count > (force || forceBefore ? 0 : -1) && (result.length > 0 || count === 0)) result.push("\n".repeat(count) || " ");
500
224
  count = -1;
501
- result.push(value);
225
+ result.push(typeof value === "object" ? value.value : value);
502
226
  }
503
227
  }
228
+ if (inline && count === 0 && !force) result.push(" ");
504
229
  return result.join("");
505
230
  }
506
231
  /**
507
232
  * <https://html.spec.whatwg.org/multipage/dom.html#rendered-text-collection-steps>
508
233
  *
509
234
  * @param {Nodes} node
235
+ * Node.
236
+ * @param {number} index
237
+ * Index of `node` in `parent`.
510
238
  * @param {Parents} parent
239
+ * Parent of `node`.
511
240
  * @param {CollectionInfo} info
512
- * @returns {Array<BreakNumber | string>}
241
+ * Info on current collection.
242
+ * @returns {Array<Item>}
243
+ * Items.
513
244
  */
514
- function renderedTextCollection(node, parent, info) {
515
- if (node.type === "element") return collectElement(node, parent, info);
516
- if (node.type === "text") return info.whitespace === "normal" ? collectText(node, info) : collectPreText(node);
245
+ function renderedTextCollection(node, index, parent, info) {
246
+ if (node.type === "element") return collectElement(node, index, parent, info);
247
+ if (node.type === "text") {
248
+ if (whitespaceOnly.test(node.value) && parent.type === "element" && (parent.tagName === "table" || parent.tagName === "tr" || rowGroup(parent))) {
249
+ const before = parent.children[index - 1];
250
+ const after = parent.children[index + 1];
251
+ if ((!before || before.type === "element" && tablePartNames.has(before.tagName)) && (!after || after.type === "element" && tablePartNames.has(after.tagName))) return [];
252
+ }
253
+ return info.whitespace === "normal" ? collectText(node) : collectPreText(node);
254
+ }
517
255
  return [];
518
256
  }
519
257
  /**
@@ -521,37 +259,41 @@ function renderedTextCollection(node, parent, info) {
521
259
  *
522
260
  * @param {Element} node
523
261
  * Element node.
262
+ * @param {number} position
263
+ * Index of `node` in `parent`.
524
264
  * @param {Parents} parent
265
+ * Parent of `node`.
525
266
  * @param {CollectionInfo} info
526
267
  * Info on current collection.
527
- * @returns {Array<BreakNumber | string>}
268
+ * @returns {Array<Item>}
269
+ * Items.
528
270
  */
529
- function collectElement(node, parent, info) {
271
+ function collectElement(node, position, parent, info) {
530
272
  const whitespace = inferWhitespace(node, info);
531
273
  const children = node.children || [];
274
+ const inTable = node.tagName === "table" || rowGroup(node);
532
275
  let index = -1;
533
- /** @type {Array<BreakNumber | string>} */
534
- let items = [];
535
- if (notRendered(node)) return items;
276
+ /** @type {Array<Item>} */
277
+ const items = [];
278
+ if (notRenderedNames.has(node.tagName) || node.properties?.hidden || node.tagName === "dialog" && !node.properties?.open) return items;
536
279
  /** @type {BreakNumber | undefined} */
537
280
  let prefix;
538
281
  /** @type {BreakForce | BreakNumber | undefined} */
539
282
  let suffix;
540
- if (br(node)) suffix = "\n";
541
- else if (row(node) && findAfter(parent, node, row)) suffix = "\n";
542
- else if (p(node)) {
283
+ if (node.tagName === "br") suffix = forcedLineFeed;
284
+ else if (row(node) && (info.rowAfter || after(parent, position, row))) suffix = forcedLineFeed;
285
+ else if (node.tagName === "p") {
543
286
  prefix = 2;
544
287
  suffix = 2;
545
- } else if (blockOrCaption(node)) {
288
+ } else if (blockOrCaptionNames.has(node.tagName)) {
546
289
  prefix = 1;
547
290
  suffix = 1;
548
291
  }
549
- while (++index < children.length) items = items.concat(renderedTextCollection(children[index], node, {
550
- whitespace,
551
- breakBefore: index ? void 0 : prefix,
552
- breakAfter: index < children.length - 1 ? br(children[index + 1]) : suffix
292
+ while (++index < children.length) append(items, renderedTextCollection(children[index], index, node, {
293
+ rowAfter: inTable ? inferRowAfter(node, index, info.rowAfter) : void 0,
294
+ whitespace
553
295
  }));
554
- if (cell(node) && findAfter(parent, node, cell)) items.push(" ");
296
+ if (cell(node) && after(parent, position, cell)) items.push(forcedTab);
555
297
  if (prefix) items.unshift(prefix);
556
298
  if (suffix) items.push(suffix);
557
299
  return items;
@@ -575,23 +317,22 @@ function collectElement(node, parent, info) {
575
317
  *
576
318
  * @param {Comment | Text} node
577
319
  * Text node.
578
- * @param {CollectionInfo} info
579
- * Info on current collection.
580
- * @returns {Array<BreakNumber | string>}
320
+ * @returns {Array<Item>}
581
321
  * Result.
582
322
  */
583
- function collectText(node, info) {
584
- const value = String(node.value);
323
+ function collectText(node) {
324
+ const value = String(node.value).replace(/[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g, "");
585
325
  /** @type {Array<string>} */
586
326
  const lines = [];
587
- /** @type {Array<BreakNumber | string>} */
327
+ /** @type {Array<Item>} */
588
328
  const result = [];
589
329
  let start = 0;
330
+ if (startsWithTabOrSpace.test(value)) result.push(0);
590
331
  while (start <= value.length) {
591
332
  searchLineFeeds.lastIndex = start;
592
333
  const match = searchLineFeeds.exec(value);
593
334
  const end = match && "index" in match ? match.index : value.length;
594
- lines.push(trimAndCollapseSpacesAndTabs(value.slice(start, end).replace(/[\u061C\u200E\u200F\u202A-\u202E\u2066-\u2069]/g, ""), start === 0 ? info.breakBefore : true, end === value.length ? info.breakAfter : true));
335
+ lines.push(trimAndCollapseSpacesAndTabs(value.slice(start, end)));
595
336
  start = end + 1;
596
337
  }
597
338
  let index = -1;
@@ -605,6 +346,7 @@ function collectText(node, info) {
605
346
  result.push(lines[index]);
606
347
  join = 0;
607
348
  } else if (index === 0 || index === lines.length - 1) result.push(0);
349
+ if (endsWithTabOrSpace.test(value)) result.push(0);
608
350
  return result;
609
351
  }
610
352
  /**
@@ -612,7 +354,7 @@ function collectText(node, info) {
612
354
  *
613
355
  * @param {Text} node
614
356
  * Text node.
615
- * @returns {Array<BreakNumber | string>}
357
+ * @returns {Array<Item>}
616
358
  * Result.
617
359
  */
618
360
  function collectPreText(node) {
@@ -626,31 +368,16 @@ function collectPreText(node) {
626
368
  * context—is collapsed to have zero advance width. (It is invisible,
627
369
  * but retains its soft wrap opportunity, if any.)
628
370
  *
371
+ * Note: spaces at the start and end of the node are handled in
372
+ * `collectText`.
373
+ *
629
374
  * @param {string} value
630
375
  * Value to collapse.
631
- * @param {BreakBefore} breakBefore
632
- * Whether there was a break before.
633
- * @param {BreakAfter} breakAfter
634
- * Whether there was a break after.
635
376
  * @returns {string}
636
377
  * Result.
637
378
  */
638
- function trimAndCollapseSpacesAndTabs(value, breakBefore, breakAfter) {
639
- /** @type {Array<string>} */
640
- const result = [];
641
- let start = 0;
642
- /** @type {number | undefined} */
643
- let end;
644
- while (start < value.length) {
645
- searchTabOrSpaces.lastIndex = start;
646
- const match = searchTabOrSpaces.exec(value);
647
- end = match ? match.index : value.length;
648
- if (!start && !end && match && !breakBefore) result.push("");
649
- if (start !== end) result.push(value.slice(start, end));
650
- start = match ? end + match[0].length : end;
651
- }
652
- if (start !== end && !breakAfter) result.push("");
653
- return result.join(" ");
379
+ function trimAndCollapseSpacesAndTabs(value) {
380
+ return value.replace(trimTabOrSpaces, "").replace(searchTabOrSpaces, " ");
654
381
  }
655
382
  /**
656
383
  * Figure out the whitespace of a node.
@@ -665,42 +392,119 @@ function trimAndCollapseSpacesAndTabs(value, breakBefore, breakAfter) {
665
392
  * Applied whitespace.
666
393
  */
667
394
  function inferWhitespace(node, info) {
668
- if (node.type === "element") {
669
- const properties = node.properties || {};
670
- switch (node.tagName) {
671
- case "listing":
672
- case "plaintext":
673
- case "xmp": return "pre";
674
- case "nobr": return "nowrap";
675
- case "pre": return properties.wrap ? "pre-wrap" : "pre";
676
- case "td":
677
- case "th": return properties.noWrap ? "nowrap" : info.whitespace;
678
- case "textarea": return "pre-wrap";
679
- }
395
+ if (node.type === "element") switch (node.tagName) {
396
+ case "listing":
397
+ case "plaintext":
398
+ case "xmp": return "pre";
399
+ case "nobr": return "nowrap";
400
+ case "pre": return node.properties?.wrap ? "pre-wrap" : "pre";
401
+ case "td":
402
+ case "th": return node.properties?.noWrap ? "nowrap" : info.whitespace;
403
+ case "textarea": return "pre-wrap";
680
404
  }
681
405
  return info.whitespace;
682
406
  }
683
407
  /**
684
- * @type {TestFunction}
685
- * @param {Element} node
686
- * @returns {node is {properties: {hidden: true}}}
408
+ * Check if a row comes later in a table.
409
+ *
410
+ * @param {Nodes} parent
411
+ * Table or row group.
412
+ * @param {number} index
413
+ * Index of child in `parent`.
414
+ * @param {boolean | undefined} rowAfter
415
+ * Whether a row comes after `parent`, if it is a row group.
416
+ * @returns {boolean | undefined}
417
+ * Whether a row comes after the child in the nearest table.
418
+ */
419
+ function inferRowAfter(parent, index, rowAfter) {
420
+ return parent.type === "element" && parent.tagName === "table" ? after(parent, index, rowOrRowGroupWithRow) : rowAfter;
421
+ }
422
+ /**
423
+ * Check if an element after `index` in `parent` passes `test`.
424
+ *
425
+ * @param {Parents} parent
426
+ * Parent.
427
+ * @param {number} index
428
+ * Index of a child in `parent`; elements after it are checked.
429
+ * @param {(node: Element) => boolean} test
430
+ * Check.
431
+ * @returns {boolean}
432
+ * Whether an element after `index` passes `test`.
687
433
  */
688
- function hidden(node) {
689
- return Boolean((node.properties || {}).hidden);
434
+ function after(parent, index, test) {
435
+ while (++index < parent.children.length) {
436
+ const child = parent.children[index];
437
+ if (child.type === "element" && test(child)) return true;
438
+ }
439
+ return false;
690
440
  }
691
441
  /**
692
- * @type {TestFunction}
442
+ * Append items to a list; without `...spread` which overflows.
443
+ *
444
+ * @template Kind
445
+ * Item.
446
+ * @param {Array<Kind>} list
447
+ * List to append to.
448
+ * @param {Array<Kind>} items
449
+ * Items to append.
450
+ * @returns {undefined}
451
+ * Nothing.
452
+ */
453
+ function append(list, items) {
454
+ let index = -1;
455
+ while (++index < items.length) list.push(items[index]);
456
+ }
457
+ /**
458
+ * Check if an element is a cell.
459
+ *
693
460
  * @param {Element} node
694
- * @returns {node is {tagName: 'td' | 'th'}}
461
+ * Element.
462
+ * @returns {boolean}
463
+ * Whether `node` is a cell.
695
464
  */
696
- function isCell(node) {
465
+ function cell(node) {
697
466
  return node.tagName === "td" || node.tagName === "th";
698
467
  }
699
468
  /**
700
- * @type {TestFunction}
469
+ * Check if an element is a row group; hot path so a basic regular function.
470
+ *
471
+ * @param {Element} node
472
+ * Element.
473
+ * @returns {boolean}
474
+ * Whether `node` is a row group.
475
+ */
476
+ function rowGroup(node) {
477
+ return node.tagName === "tbody" || node.tagName === "tfoot" || node.tagName === "thead";
478
+ }
479
+ /**
480
+ * Check if an element is a row, or a row group with a row.
481
+ *
482
+ * @param {Element} node
483
+ * Element.
484
+ * @returns {boolean}
485
+ * Whether `node` is a row or a row group with a row.
486
+ */
487
+ function rowOrRowGroupWithRow(node) {
488
+ if (row(node)) return true;
489
+ if (rowGroup(node)) {
490
+ let index = -1;
491
+ while (++index < node.children.length) {
492
+ const child = node.children[index];
493
+ if (child.type === "element" && row(child)) return true;
494
+ }
495
+ }
496
+ return false;
497
+ }
498
+ /**
499
+ * Check if an element is a row.
500
+ *
501
+ * @param {Element} node
502
+ * Element.
503
+ * @returns {boolean}
504
+ * Whether `node` is a row.
701
505
  */
702
- function closedDialog(node) {
703
- return node.tagName === "dialog" && !(node.properties || {}).open;
506
+ function row(node) {
507
+ return node.tagName === "tr";
704
508
  }
705
509
  var core_default = (/* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
706
510
  function deepFreeze(obj) {
@@ -2534,8 +2338,7 @@ var core_default = (/* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exp
2534
2338
  highlight.HighlightJS = highlight;
2535
2339
  highlight.default = highlight;
2536
2340
  })))())).default;
2537
- //#endregion
2538
- //#region ../../node_modules/.pnpm/lowlight@3.3.0/node_modules/lowlight/lib/index.js
2341
+ // ../../node_modules/.pnpm/lowlight@3.3.0/node_modules/lowlight/lib/index.js
2539
2342
  /**
2540
2343
  * @import {ElementContent, Element, RootData, Root} from 'hast'
2541
2344
  * @import {Emitter, HLJSOptions as HljsOptions, HighlightResult, LanguageFn} from 'highlight.js'
@@ -2936,8 +2739,7 @@ var HastEmitter = class {
2936
2739
  return "";
2937
2740
  }
2938
2741
  };
2939
- //#endregion
2940
- //#region src/rehype-highlight/rehype-highlight.ts
2742
+ // src/rehype-highlight/rehype-highlight.ts
2941
2743
  var emptyOptions = {};
2942
2744
  /**
2943
2745
  * Lowlight syntax highlighting plugin for rehype pipelines
@@ -3015,7 +2817,6 @@ function language(node) {
3015
2817
  }, "");
3016
2818
  return lowlightLanguageMappings[name || ""] || name;
3017
2819
  }
3018
- //#endregion
3019
- export { lowlightLanguageMappings as a, __exportAll as c, isElement as i, __toESM as l, createLowlight as n, ok as o, convertElement as r, __commonJSMin as s, rehypeHighlight as t };
2820
+ export { __commonJSMin as a, ok as i, createLowlight as n, __exportAll as o, lowlightLanguageMappings as r, __toESM as s, rehypeHighlight as t };
3020
2821
 
3021
2822
  //# sourceMappingURL=rehype-highlight.js.map