| 1 | import { findReferences } from "@ghost/references"; |
| 2 | import type { Nodes, |
| 3 | |
| 4 | /** Links `#1`, `owner/repo#1`, `@user` and `@org/team` in prose. `#1` is resolved against `repository`; code and existing links are left alone. */ |
| 5 | export function remarkReferences(repository |
| 6 | username: string |
| 7 | repo: string |
| 8 | }) { |
| 9 | const linkify = |
| 10 | const pieces: |
| 11 | let cursor = |
| 12 | for (const reference |
| 13 | const text = |
| 14 | reference.index, |
| 15 | reference.index + |
| 16 | ); |
| 17 | const url = |
| 18 | reference.kind === |
| 19 | ? `/${reference. |
| 20 | : reference.kind |
| 21 | ? `/${reference. |
| 22 | : `/${reference. |
| 23 | if (reference.index |
| 24 | pieces.push({ |
| 25 | type: "text", |
| 26 | value: value.slice |
| 27 | }); |
| 28 | pieces.push({ |
| 29 | type: "link", |
| 30 | url, |
| 31 | children: [{ type: |
| 32 | }); |
| 33 | cursor = reference. |
| 34 | } |
| 35 | if (cursor < |
| 36 | pieces.push({ |
| 37 | return pieces; |
| 38 | }; |
| 39 | |
| 40 | const walk = |
| 41 | if ( |
| 42 | !("children" in node |
| 43 | node.type === |
| 44 | node.type === |
| 45 | ) |
| 46 | return; |
| 47 | // Text only ever sits where phrasing content is allowed, so its replacements are valid children of the same parent. |
| 48 | const children: |
| 49 | (node as { |
| 50 | (child) => |
| 51 | if (child.type |
| 52 | walk(child); |
| 53 | return [child]; |
| 54 | }, |
| 55 | ); |
| 56 | }; |
| 57 | |
| 58 | return (tree: |
| 59 | } |