Open History to see the last commit
1import type { MarkdownNode } from "react-native-nitro-markdown/headless";
2
3import type { SelectableMarkdownSkill } from "./SelectableMarkdownText.types";
4import {
5 resolveMarkdownInlineCodePresentation,
6 resolveMarkdownLinkPresentation,
7 type MarkdownFileIcon,
8} from "./markdownLinks";
9
10export interface NativeMarkdownTextRun {
11 readonly text: string;
12 readonly bold?: boolean;
13 readonly italic?: boolean;
14 readonly strikethrough?: boolean;
15 readonly code?: boolean;
16 readonly href?: string;
17 readonly externalHost?: string;
18 readonly fileIcon?: MarkdownFileIcon;
19 readonly skillName?: string;
20 readonly skillLabel?: string;
21 readonly role?:
22 | "body"
23 | "heading"
24 | "list-marker"
25 | "list-break"
26 | "quote-marker"
27 | "code-block"
28 | "code-language"
29 | "divider"
30 | "spacer";
31 readonly headingLevel?: number;
32 readonly depth?: number;
33 readonly spacing?: number;
34 readonly firstLineHeadIndent?: number;
35 readonly headIndent?: number;
36 readonly paragraphSpacing?: number;
37}
38
39export type NativeMarkdownDocumentChunk =
40 | {
41 readonly kind: "selectable";
42 readonly key: string;
43 readonly node: MarkdownNode;
44 }
45 | {
46 readonly kind: "rich";
47 readonly key: string;
48 readonly node: MarkdownNode;
49 };
50
51interface RunContext {
52 readonly bold: boolean;
53 readonly italic: boolean;
54 readonly strikethrough: boolean;
55 readonly code: boolean;
56 readonly href?: string;
57 readonly externalHost?: string;
58 readonly fileIcon?: MarkdownFileIcon;
59 readonly role?: NativeMarkdownTextRun["role"];
60 readonly headingLevel?: number;
61 readonly depth?: number;
62 readonly spacing?: number;
63 readonly firstLineHeadIndent?: number;
64 readonly headIndent?: number;
65 readonly paragraphSpacing?: number;
66}
67
68const EMPTY_CONTEXT: RunContext = {
69 bold: false,
70 italic: false,
71 strikethrough: false,
72 code: false,
73};
74
75const INLINE_HTML_TAG_PATTERN = /<\/?(?:kbd|mark|sub|sup|u)(?:\s[^>]*)?>/gi;
76
77function decodeCodePoint(codePoint: number, entity: string): string {
78 if (!Number.isInteger(codePoint) || codePoint < 0 || codePoint > 0x10ffff) {
79 return entity;
80 }
81 return String.fromCodePoint(codePoint);
82}
83
84function decodeHtmlEntitiesOnce(value: string): string {
85 return value.replace(
86 /&(?:#(\d+)|#x([0-9a-f]+)|amp|apos|gt|lt|nbsp|quot);/gi,
87 (entity, decimal: string | undefined, hexadecimal: string | undefined) => {
88 if (decimal) {
89 return decodeCodePoint(Number.parseInt(decimal, 10), entity);
90 }
91 if (hexadecimal) {
92 return decodeCodePoint(Number.parseInt(hexadecimal, 16), entity);
93 }
94 switch (entity.toLowerCase()) {
95 case "&":
96 return "&";
97 case "'":
98 return "'";
99 case ">":
100 return ">";
101 case "<":
102 return "<";
103 case " ":
104 return "\u00a0";
105 case """:
106 return '"';
107 default:
108 return entity;
109 }
110 },
111 );
112}
113
114function decodeHtmlEntities(value: string): string {
115 let decoded = value;
116 for (let pass = 0; pass < 2; pass += 1) {
117 const next = decodeHtmlEntitiesOnce(decoded);
118 if (next === decoded) {
119 break;
120 }
121 decoded = next;
122 }
123 return decoded;
124}
125
126function textNodeContent(value: string): string {
127 return decodeHtmlEntities(value).replace(INLINE_HTML_TAG_PATTERN, "");
128}
129
130function inlineHtmlText(value: string): string {
131 if (/^<br\s*\/?>$/i.test(value.trim())) {
132 return "\n";
133 }
134 return decodeHtmlEntities(value.replace(/<[^>]+>/g, ""));
135}
136
137function sameRunStyle(left: NativeMarkdownTextRun, right: NativeMarkdownTextRun): boolean {
138 return (
139 left.bold === right.bold &&
140 left.italic === right.italic &&
141 left.strikethrough === right.strikethrough &&
142 left.code === right.code &&
143 left.href === right.href &&
144 left.externalHost === right.externalHost &&
145 left.fileIcon === right.fileIcon &&
146 left.skillName === right.skillName &&
147 left.skillLabel === right.skillLabel &&
148 left.role === right.role &&
149 left.headingLevel === right.headingLevel &&
150 left.depth === right.depth &&
151 left.spacing === right.spacing &&
152 left.firstLineHeadIndent === right.firstLineHeadIndent &&
153 left.headIndent === right.headIndent &&
154 left.paragraphSpacing === right.paragraphSpacing
155 );
156}
157
158function appendRun(
159 runs: NativeMarkdownTextRun[],
160 text: string,
161 context: RunContext,
162): NativeMarkdownTextRun[] {
163 if (text.length === 0) {
164 return runs;
165 }
166
167 const run: NativeMarkdownTextRun = {
168 text,
169 ...(context.bold ? { bold: true } : {}),
170 ...(context.italic ? { italic: true } : {}),
171 ...(context.strikethrough ? { strikethrough: true } : {}),
172 ...(context.code ? { code: true } : {}),
173 ...(context.href ? { href: context.href } : {}),
174 ...(context.externalHost ? { externalHost: context.externalHost } : {}),
175 ...(context.fileIcon ? { fileIcon: context.fileIcon } : {}),
176 ...(context.role ? { role: context.role } : {}),
177 ...(context.headingLevel ? { headingLevel: context.headingLevel } : {}),
178 ...(context.depth ? { depth: context.depth } : {}),
179 ...(context.spacing ? { spacing: context.spacing } : {}),
180 ...(context.firstLineHeadIndent !== undefined
181 ? { firstLineHeadIndent: context.firstLineHeadIndent }
182 : {}),
183 ...(context.headIndent !== undefined ? { headIndent: context.headIndent } : {}),
184 ...(context.paragraphSpacing !== undefined
185 ? { paragraphSpacing: context.paragraphSpacing }
186 : {}),
187 };
188 const previous = runs.at(-1);
189 if (previous && sameRunStyle(previous, run)) {
190 runs[runs.length - 1] = { ...previous, text: previous.text + run.text };
191 return runs;
192 }
193
194 runs.push(run);
195 return runs;
196}
197
198const SKILL_TOKEN_REGEX =
199 /(^|\s)\$(?![0-9][0-9_]*(?:[kKmMbBtT]|[eE][0-9]+)?(?:\s|$))(?=[a-zA-Z0-9:_-]*[a-zA-Z])([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s|$)/g;
200
201function formatSkillLabel(skill: SelectableMarkdownSkill): string {
202 const displayName = skill.displayName?.trim();
203 if (displayName) {
204 return displayName;
205 }
206 return skill.name
207 .split(/[\s:_-]+/)
208 .filter(Boolean)
209 .map((segment) => segment.charAt(0).toUpperCase() + segment.slice(1))
210 .join(" ");
211}
212
213function decorateSkillRuns(
214 runs: ReadonlyArray<NativeMarkdownTextRun>,
215 skills: ReadonlyArray<SelectableMarkdownSkill>,
216): ReadonlyArray<NativeMarkdownTextRun> {
217 if (skills.length === 0) {
218 return runs;
219 }
220 const skillByName = new Map(skills.map((skill) => [skill.name, skill]));
221 const decorated: NativeMarkdownTextRun[] = [];
222
223 for (const run of runs) {
224 if (run.code || run.href || run.fileIcon || run.role === "code-block") {
225 decorated.push(run);
226 continue;
227 }
228
229 let cursor = 0;
230 let matched = false;
231 for (const match of run.text.matchAll(SKILL_TOKEN_REGEX)) {
232 const prefix = match[1] ?? "";
233 const name = match[2] ?? "";
234 const skill = skillByName.get(name);
235 if (!skill) {
236 continue;
237 }
238 const start = (match.index ?? 0) + prefix.length;
239 const end = start + name.length + 1;
240 if (start > cursor) {
241 decorated.push({ ...run, text: run.text.slice(cursor, start) });
242 }
243 decorated.push({
244 ...run,
245 text: run.text.slice(start, end),
246 skillName: name,
247 skillLabel: formatSkillLabel(skill),
248 });
249 cursor = end;
250 matched = true;
251 }
252 if (!matched) {
253 decorated.push(run);
254 } else if (cursor < run.text.length) {
255 decorated.push({ ...run, text: run.text.slice(cursor) });
256 }
257 }
258
259 return decorated;
260}
261
262function appendChildren(
263 runs: NativeMarkdownTextRun[],
264 node: MarkdownNode,
265 context: RunContext,
266): NativeMarkdownTextRun[] {
267 for (const child of node.children ?? []) {
268 appendNode(runs, child, context);
269 }
270 return runs;
271}
272
273function nodeTextContent(node: MarkdownNode): string {
274 if (node.content !== undefined) {
275 return node.content;
276 }
277 return (node.children ?? []).map(nodeTextContent).join("");
278}
279
280function appendNode(
281 runs: NativeMarkdownTextRun[],
282 node: MarkdownNode,
283 context: RunContext,
284): NativeMarkdownTextRun[] {
285 switch (node.type) {
286 case "text":
287 case "math_inline":
288 return appendRun(runs, textNodeContent(nodeTextContent(node)), context);
289 case "html_inline":
290 return appendRun(runs, inlineHtmlText(nodeTextContent(node)), context);
291 case "code_inline": {
292 const content = nodeTextContent(node);
293 const presentation = context.href ? null : resolveMarkdownInlineCodePresentation(content);
294 return presentation
295 ? appendRun(runs, presentation.label, {
296 ...context,
297 href: presentation.href,
298 fileIcon: presentation.icon,
299 })
300 : appendRun(runs, content, { ...context, code: true });
301 }
302 case "soft_break":
303 return appendRun(runs, " ", context);
304 case "line_break":
305 return appendRun(runs, "\n", context);
306 case "bold":
307 return appendChildren(runs, node, { ...context, bold: true });
308 case "italic":
309 return appendChildren(runs, node, { ...context, italic: true });
310 case "strikethrough":
311 return appendChildren(runs, node, { ...context, strikethrough: true });
312 case "link": {
313 const presentation = resolveMarkdownLinkPresentation(node.href ?? "");
314 if (presentation.kind === "file") {
315 return appendRun(runs, presentation.label, {
316 ...context,
317 href: presentation.href,
318 fileIcon: presentation.icon,
319 });
320 }
321 if (presentation.kind === "external") {
322 return appendChildren(runs, node, {
323 ...context,
324 href: presentation.href,
325 externalHost: presentation.host,
326 });
327 }
328 return appendChildren(runs, node, {
329 ...context,
330 ...(presentation.href ? { href: presentation.href } : {}),
331 });
332 }
333 case "image":
334 return appendRun(runs, node.alt ?? node.title ?? "", context);
335 default:
336 return appendChildren(runs, node, context);
337 }
338}
339
340export function nativeMarkdownTextRuns(node: MarkdownNode): ReadonlyArray<NativeMarkdownTextRun> {
341 return appendChildren([], node, EMPTY_CONTEXT);
342}
343
344export function nativeMarkdownWithPreservedSoftBreaks(node: MarkdownNode): MarkdownNode {
345 const children = node.children?.map(nativeMarkdownWithPreservedSoftBreaks);
346 return {
347 ...node,
348 ...(node.type === "soft_break" ? { type: "line_break" as const } : {}),
349 ...(children ? { children } : {}),
350 };
351}
352
353function appendBlockTerminator(
354 runs: NativeMarkdownTextRun[],
355 context: RunContext,
356): NativeMarkdownTextRun[] {
357 return appendRun(runs, "\n", context);
358}
359
360function appendSpacer(runs: NativeMarkdownTextRun[], spacing: number): NativeMarkdownTextRun[] {
361 return appendRun(runs, "\n", { ...EMPTY_CONTEXT, role: "spacer", spacing });
362}
363
364function appendInlineChildren(
365 runs: NativeMarkdownTextRun[],
366 node: MarkdownNode,
367 context: RunContext,
368): NativeMarkdownTextRun[] {
369 for (const child of node.children ?? []) {
370 appendNode(runs, child, context);
371 }
372 return runs;
373}
374
375function isInlineNode(node: MarkdownNode): boolean {
376 return (
377 node.type === "text" ||
378 node.type === "bold" ||
379 node.type === "italic" ||
380 node.type === "strikethrough" ||
381 node.type === "link" ||
382 node.type === "image" ||
383 node.type === "code_inline" ||
384 node.type === "math_inline" ||
385 node.type === "html_inline" ||
386 node.type === "soft_break" ||
387 node.type === "line_break"
388 );
389}
390
391export function nativeMarkdownListItemBlocks(node: MarkdownNode): ReadonlyArray<MarkdownNode> {
392 const blocks: MarkdownNode[] = [];
393 let inlineNodes: MarkdownNode[] = [];
394 const flushInlineNodes = () => {
395 if (inlineNodes.length === 0) {
396 return;
397 }
398 blocks.push({ type: "paragraph", children: inlineNodes });
399 inlineNodes = [];
400 };
401
402 for (const child of node.children ?? []) {
403 if (isInlineNode(child)) {
404 inlineNodes.push(child);
405 continue;
406 }
407
408 flushInlineNodes();
409 blocks.push(child);
410 }
411 flushInlineNodes();
412 return blocks;
413}
414
415function appendListItem(
416 runs: NativeMarkdownTextRun[],
417 node: MarkdownNode,
418 marker: string,
419 depth: number,
420 markerColumnWidth: number,
421): NativeMarkdownTextRun[] {
422 const firstLineHeadIndent = Math.max(0, depth - 1) * 20;
423 appendRun(runs, `${marker}\t`, {
424 ...EMPTY_CONTEXT,
425 role: "list-marker",
426 depth,
427 firstLineHeadIndent,
428 headIndent: firstLineHeadIndent + markerColumnWidth,
429 paragraphSpacing: 2,
430 });
431
432 const children = node.children ?? [];
433 let wroteInlineContent = false;
434 for (const child of children) {
435 if (child.type === "paragraph") {
436 appendInlineChildren(runs, child, {
437 ...EMPTY_CONTEXT,
438 role: "body",
439 depth,
440 });
441 wroteInlineContent = true;
442 continue;
443 }
444 if (child.type === "list") {
445 if (wroteInlineContent) {
446 appendBlockTerminator(runs, {
447 ...EMPTY_CONTEXT,
448 role: "list-break",
449 depth,
450 spacing: 1,
451 });
452 }
453 appendList(runs, child, depth + 1);
454 wroteInlineContent = false;
455 continue;
456 }
457 if (isInlineNode(child)) {
458 appendNode(runs, child, {
459 ...EMPTY_CONTEXT,
460 role: "body",
461 depth,
462 });
463 wroteInlineContent = true;
464 continue;
465 }
466 appendDocumentBlock(runs, child, depth);
467 wroteInlineContent = true;
468 }
469
470 if (wroteInlineContent) {
471 appendBlockTerminator(runs, {
472 ...EMPTY_CONTEXT,
473 role: "list-break",
474 depth,
475 spacing: depth === 1 ? 4 : 2,
476 });
477 }
478 return runs;
479}
480
481function appendList(
482 runs: NativeMarkdownTextRun[],
483 node: MarkdownNode,
484 depth: number,
485): NativeMarkdownTextRun[] {
486 const ordered = node.ordered ?? false;
487 const start = node.start ?? 1;
488 const children = node.children ?? [];
489 const markers = children.map((child, index) =>
490 child.type === "task_list_item"
491 ? child.checked
492 ? "☑︎"
493 : "☐︎"
494 : ordered
495 ? `${start + index}.`
496 : depth % 3 === 2
497 ? "◦"
498 : depth % 3 === 0
499 ? "▪︎"
500 : "•",
501 );
502 const markerWidth = ordered
503 ? Math.max(0, ...markers.map((marker) => Array.from(marker).length))
504 : 0;
505
506 for (const [index, child] of children.entries()) {
507 const marker = markers[index] ?? "•";
508 const alignedMarker =
509 child.type === "task_list_item"
510 ? marker
511 : ordered
512 ? `${"\u2007".repeat(Math.max(0, markerWidth - Array.from(marker).length))}${marker}`
513 : marker;
514 const markerColumnWidth =
515 child.type === "task_list_item" ? 28 : ordered ? 10 + markerWidth * 8 : 24;
516 appendListItem(runs, child, alignedMarker, depth, markerColumnWidth);
517 }
518 return runs;
519}
520
521function appendQuoteBlock(
522 runs: NativeMarkdownTextRun[],
523 node: MarkdownNode,
524 depth: number,
525): NativeMarkdownTextRun[] {
526 for (const [index, child] of (node.children ?? []).entries()) {
527 if (index > 0) {
528 appendBlockTerminator(runs, { ...EMPTY_CONTEXT, role: "body", depth });
529 }
530 appendRun(runs, "│\u00a0", {
531 ...EMPTY_CONTEXT,
532 role: "quote-marker",
533 depth,
534 });
535 if (child.type === "paragraph") {
536 appendInlineChildren(runs, child, {
537 ...EMPTY_CONTEXT,
538 role: "body",
539 depth,
540 });
541 } else {
542 appendDocumentBlock(runs, child, depth);
543 }
544 }
545 appendBlockTerminator(runs, { ...EMPTY_CONTEXT, role: "body", depth });
546 return runs;
547}
548
549function appendTableRow(
550 runs: NativeMarkdownTextRun[],
551 node: MarkdownNode,
552 depth: number,
553): NativeMarkdownTextRun[] {
554 const cells = node.children ?? [];
555 for (const [index, cell] of cells.entries()) {
556 if (index > 0) {
557 appendRun(runs, "\u00a0│\u00a0", {
558 ...EMPTY_CONTEXT,
559 role: "divider",
560 depth,
561 });
562 }
563 appendInlineChildren(runs, cell, {
564 ...EMPTY_CONTEXT,
565 role: "body",
566 bold: cell.isHeader ?? false,
567 depth,
568 });
569 }
570 appendBlockTerminator(runs, { ...EMPTY_CONTEXT, role: "body", depth });
571 return runs;
572}
573
574function appendTable(
575 runs: NativeMarkdownTextRun[],
576 node: MarkdownNode,
577 depth: number,
578): NativeMarkdownTextRun[] {
579 const visit = (child: MarkdownNode) => {
580 if (child.type === "table_row") {
581 appendTableRow(runs, child, depth);
582 return;
583 }
584 for (const nested of child.children ?? []) {
585 visit(nested);
586 }
587 };
588 visit(node);
589 return runs;
590}
591
592function appendDocumentBlock(
593 runs: NativeMarkdownTextRun[],
594 node: MarkdownNode,
595 depth = 0,
596): NativeMarkdownTextRun[] {
597 switch (node.type) {
598 case "document": {
599 const children = node.children ?? [];
600 for (const [index, child] of children.entries()) {
601 if (index > 0) {
602 const previous = children[index - 1];
603 appendSpacer(
604 runs,
605 child.type === "heading" ? 20 : previous?.type === "heading" ? 10 : 12,
606 );
607 }
608 appendDocumentBlock(runs, child, depth);
609 }
610 return runs;
611 }
612 case "heading": {
613 const context: RunContext = {
614 ...EMPTY_CONTEXT,
615 role: "heading",
616 headingLevel: node.level ?? 1,
617 depth,
618 };
619 appendInlineChildren(runs, node, context);
620 return appendBlockTerminator(runs, context);
621 }
622 case "paragraph": {
623 const context: RunContext = { ...EMPTY_CONTEXT, role: "body", depth };
624 appendInlineChildren(runs, node, context);
625 return appendBlockTerminator(runs, context);
626 }
627 case "list":
628 return appendList(runs, node, depth + 1);
629 case "blockquote":
630 return appendQuoteBlock(runs, node, depth);
631 case "code_block": {
632 if (node.language) {
633 appendRun(runs, `${node.language.toUpperCase()}\n`, {
634 ...EMPTY_CONTEXT,
635 role: "code-language",
636 code: true,
637 depth,
638 });
639 }
640 const content = nodeTextContent(node);
641 appendRun(runs, content, {
642 ...EMPTY_CONTEXT,
643 role: "code-block",
644 code: true,
645 depth,
646 });
647 if (!content.endsWith("\n")) {
648 appendBlockTerminator(runs, {
649 ...EMPTY_CONTEXT,
650 role: "code-block",
651 code: true,
652 depth,
653 });
654 }
655 return runs;
656 }
657 case "horizontal_rule":
658 appendRun(runs, "────────────────────────\n", {
659 ...EMPTY_CONTEXT,
660 role: "divider",
661 depth,
662 });
663 return runs;
664 case "table":
665 return appendTable(runs, node, depth);
666 case "html_block":
667 appendRun(runs, inlineHtmlText(nodeTextContent(node)), {
668 ...EMPTY_CONTEXT,
669 role: "body",
670 depth,
671 });
672 return appendBlockTerminator(runs, { ...EMPTY_CONTEXT, role: "body", depth });
673 case "math_block":
674 appendRun(runs, nodeTextContent(node), { ...EMPTY_CONTEXT, role: "body", depth });
675 return appendBlockTerminator(runs, { ...EMPTY_CONTEXT, role: "body", depth });
676 default:
677 appendInlineChildren(runs, node, { ...EMPTY_CONTEXT, role: "body", depth });
678 return appendBlockTerminator(runs, { ...EMPTY_CONTEXT, role: "body", depth });
679 }
680}
681
682function containsRichBlock(node: MarkdownNode): boolean {
683 if (
684 node.type === "code_block" ||
685 node.type === "blockquote" ||
686 node.type === "table" ||
687 node.type === "image" ||
688 node.type === "horizontal_rule" ||
689 node.type === "html_block" ||
690 node.type === "math_block"
691 ) {
692 return true;
693 }
694 return (node.children ?? []).some(containsRichBlock);
695}
696
697export function nativeMarkdownDocumentChunks(
698 document: MarkdownNode,
699): ReadonlyArray<NativeMarkdownDocumentChunk> {
700 const chunks: NativeMarkdownDocumentChunk[] = [];
701 let selectableNodes: MarkdownNode[] = [];
702
703 const flushSelectable = () => {
704 if (selectableNodes.length === 0) {
705 return;
706 }
707 const first = selectableNodes[0];
708 const last = selectableNodes.at(-1);
709 chunks.push({
710 kind: "selectable",
711 key: `selectable:${first?.beg ?? "start"}:${last?.end ?? "end"}`,
712 node: {
713 type: "document",
714 children: selectableNodes,
715 },
716 });
717 selectableNodes = [];
718 };
719
720 for (const [index, child] of (document.children ?? []).entries()) {
721 if (!containsRichBlock(child)) {
722 selectableNodes.push(child);
723 continue;
724 }
725
726 flushSelectable();
727 chunks.push({
728 kind: "rich",
729 key: `rich:${child.type}:${child.beg ?? index}:${child.end ?? index}`,
730 node: child,
731 });
732 }
733 flushSelectable();
734 return chunks;
735}
736
737function topLevelNodes(node: MarkdownNode): ReadonlyArray<MarkdownNode> {
738 return node.type === "document" ? (node.children ?? []) : [node];
739}
740
741export function nativeMarkdownChunkSpacing(
742 previous: NativeMarkdownDocumentChunk | undefined,
743 current: NativeMarkdownDocumentChunk,
744): number {
745 if (!previous) {
746 return 0;
747 }
748
749 const previousLast = topLevelNodes(previous.node).at(-1);
750 const currentFirst = topLevelNodes(current.node)[0];
751
752 if (currentFirst?.type === "heading") {
753 return 20;
754 }
755 if (previousLast?.type === "heading") {
756 return 10;
757 }
758 if (previousLast?.type === "list" && currentFirst?.type === "list") {
759 return 12;
760 }
761 return 14;
762}
763
764export function nativeMarkdownDocumentRuns(
765 node: MarkdownNode,
766 skills: ReadonlyArray<SelectableMarkdownSkill> = [],
767): ReadonlyArray<NativeMarkdownTextRun> {
768 const runs = appendDocumentBlock([], node);
769 while (runs.length > 0) {
770 const lastIndex = runs.length - 1;
771 const last = runs[lastIndex];
772 if (!last?.text.endsWith("\n")) {
773 break;
774 }
775 const text = last.text.slice(0, -1);
776 if (text.length === 0) {
777 runs.pop();
778 } else {
779 runs[lastIndex] = { ...last, text };
780 }
781 }
782 return decorateSkillRuns(runs, skills);
783}