@ox-content/vite-plugin 2.69.0 → 2.71.0

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/dist/github2.mjs CHANGED
@@ -1,632 +1,2 @@
1
- import { unified } from "unified";
2
- import rehypeParse from "rehype-parse";
3
- import rehypeStringify from "rehype-stringify";
4
- import { Buffer } from "node:buffer";
5
- //#region src/plugins/github.ts
6
- /**
7
- * GitHub Plugin - Repository and source code embedding
8
- *
9
- * Transforms <GitHub> components into static repository and source code cards
10
- * by fetching data from GitHub API at build time.
11
- */
12
- const defaultOptions = {
13
- token: "",
14
- cache: true,
15
- cacheTTL: 36e5,
16
- maxSourceBytes: 2e5,
17
- maxSourceLines: 120
18
- };
19
- const repoCache = /* @__PURE__ */ new Map();
20
- const sourceCache = /* @__PURE__ */ new Map();
21
- const GITHUB_REPO_RE = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
22
- const GITHUB_COMPONENT_RE = /<github\b([^>]*)>/gi;
23
- const ATTRIBUTE_RE = /([:\w-]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>/]+)))?/g;
24
- const EXTENSION_LANGUAGE_MAP = new Map([
25
- ["cjs", "javascript"],
26
- ["css", "css"],
27
- ["go", "go"],
28
- ["html", "html"],
29
- ["js", "javascript"],
30
- ["json", "json"],
31
- ["jsx", "jsx"],
32
- ["md", "markdown"],
33
- ["mdx", "mdx"],
34
- ["mjs", "javascript"],
35
- ["py", "python"],
36
- ["rb", "ruby"],
37
- ["rs", "rust"],
38
- ["sh", "shell"],
39
- ["svelte", "svelte"],
40
- ["toml", "toml"],
41
- ["ts", "typescript"],
42
- ["tsx", "tsx"],
43
- ["vue", "vue"],
44
- ["yaml", "yaml"],
45
- ["yml", "yaml"]
46
- ]);
47
- function hasControlChar(value) {
48
- for (let index = 0; index < value.length; index++) {
49
- const code = value.charCodeAt(index);
50
- if (code <= 31 || code === 127) return true;
51
- }
52
- return false;
53
- }
54
- function isSafeGitHubRepo(repo) {
55
- return GITHUB_REPO_RE.test(repo) && !repo.split("/").some((part) => part === "." || part === "..");
56
- }
57
- function isSafeGitHubRef(ref) {
58
- return Boolean(ref) && !hasControlChar(ref) && !hasUnsafePathSegment(ref);
59
- }
60
- function isSafeGitHubPath(path) {
61
- return Boolean(path) && !hasControlChar(path) && !hasUnsafePathSegment(path);
62
- }
63
- function hasUnsafePathSegment(value) {
64
- return value.split("/").some((part) => !part || part === "." || part === ".." || part.includes("\\"));
65
- }
66
- function encodePath(path) {
67
- return path.split("/").map(encodeURIComponent).join("/");
68
- }
69
- function sourceKey(source) {
70
- return `${source.repo}@${source.ref}:${source.path}`;
71
- }
72
- function formatLineRange(lines) {
73
- return lines.start === lines.end ? `L${lines.start}` : `L${lines.start}-L${lines.end}`;
74
- }
75
- function parseGitHubLineRange(value) {
76
- if (!value) return void 0;
77
- const match = value.trim().match(/^#?L?(\d+)(?:-L?(\d+))?$/i);
78
- if (!match) return void 0;
79
- const start = Number.parseInt(match[1], 10);
80
- const end = match[2] ? Number.parseInt(match[2], 10) : start;
81
- if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 1 || end < start) return;
82
- return {
83
- start,
84
- end
85
- };
86
- }
87
- function createGitHubPermalink(source) {
88
- const fragment = source.lines ? `#${formatLineRange(source.lines)}` : "";
89
- return `https://github.com/${source.repo}/blob/${encodeURIComponent(source.ref)}/${encodePath(source.path)}${fragment}`;
90
- }
91
- function parseGitHubPermalink(value) {
92
- let url;
93
- try {
94
- url = new URL(value);
95
- } catch {
96
- return null;
97
- }
98
- if (url.protocol !== "https:" || url.hostname !== "github.com") return null;
99
- let parts;
100
- try {
101
- parts = url.pathname.split("/").filter(Boolean).map((part) => decodeURIComponent(part));
102
- } catch {
103
- return null;
104
- }
105
- if (parts.length < 5 || parts[2] !== "blob") return null;
106
- const repo = `${parts[0]}/${parts[1]}`;
107
- const ref = parts[3];
108
- const path = parts.slice(4).join("/");
109
- if (!isSafeGitHubRepo(repo) || !isSafeGitHubRef(ref) || !isSafeGitHubPath(path)) return null;
110
- const source = {
111
- repo,
112
- ref,
113
- path,
114
- lines: parseGitHubLineRange(url.hash)
115
- };
116
- return {
117
- ...source,
118
- permalink: createGitHubPermalink(source)
119
- };
120
- }
121
- /**
122
- * Get element attribute value.
123
- */
124
- function getAttribute(el, name) {
125
- const value = el.properties?.[name];
126
- if (typeof value === "string") return value;
127
- if (Array.isArray(value)) return value.join(" ");
128
- }
129
- /**
130
- * Format number with K/M suffix.
131
- */
132
- function formatNumber(num) {
133
- if (num >= 1e6) return `${(num / 1e6).toFixed(1)}M`;
134
- if (num >= 1e3) return `${(num / 1e3).toFixed(1)}k`;
135
- return String(num);
136
- }
137
- /**
138
- * Fetch repository data from GitHub API.
139
- */
140
- async function fetchRepoData(repo, options) {
141
- if (!isSafeGitHubRepo(repo)) return null;
142
- if (options.cache) {
143
- const cached = repoCache.get(repo);
144
- if (cached && Date.now() - cached.timestamp < options.cacheTTL) return cached.data;
145
- }
146
- try {
147
- const headers = {
148
- Accept: "application/vnd.github.v3+json",
149
- "User-Agent": "ox-content-github-plugin"
150
- };
151
- if (options.token) headers.Authorization = `Bearer ${options.token}`;
152
- const response = await fetch(`https://api.github.com/repos/${repo}`, { headers });
153
- if (!response.ok) {
154
- console.warn(`Failed to fetch GitHub repo ${repo}: ${response.status}`);
155
- return null;
156
- }
157
- const data = await response.json();
158
- if (options.cache) repoCache.set(repo, {
159
- data,
160
- timestamp: Date.now()
161
- });
162
- return data;
163
- } catch (error) {
164
- console.warn(`Error fetching GitHub repo ${repo}:`, error);
165
- return null;
166
- }
167
- }
168
- /**
169
- * Fetch source file data from GitHub API.
170
- */
171
- async function fetchGitHubSource(source, options) {
172
- if (!isSafeGitHubRepo(source.repo) || !isSafeGitHubRef(source.ref) || !isSafeGitHubPath(source.path)) return null;
173
- const key = sourceKey(source);
174
- if (options.cache) {
175
- const cached = sourceCache.get(key);
176
- if (cached && Date.now() - cached.timestamp < options.cacheTTL) return cached.data;
177
- }
178
- try {
179
- const headers = {
180
- Accept: "application/vnd.github.v3+json",
181
- "User-Agent": "ox-content-github-plugin"
182
- };
183
- if (options.token) headers.Authorization = `Bearer ${options.token}`;
184
- const apiUrl = `https://api.github.com/repos/${source.repo}/contents/${encodePath(source.path)}?ref=${encodeURIComponent(source.ref)}`;
185
- const response = await fetch(apiUrl, { headers });
186
- if (!response.ok) {
187
- console.warn(`Failed to fetch GitHub source ${source.permalink}: ${response.status}`);
188
- return null;
189
- }
190
- const data = await response.json();
191
- if (data.type !== "file" || data.encoding !== "base64" || !data.content || (data.size ?? 0) > options.maxSourceBytes) return null;
192
- const content = Buffer.from(data.content.replace(/\s/g, ""), "base64").toString("utf8");
193
- if (Buffer.byteLength(content) > options.maxSourceBytes) return null;
194
- const sourceData = {
195
- repo: source.repo,
196
- ref: source.ref,
197
- path: source.path,
198
- permalink: source.permalink,
199
- content,
200
- size: data.size ?? Buffer.byteLength(content),
201
- html_url: data.html_url ?? source.permalink,
202
- language: inferLanguage(source.path)
203
- };
204
- if (options.cache) sourceCache.set(key, {
205
- data: sourceData,
206
- timestamp: Date.now()
207
- });
208
- return sourceData;
209
- } catch (error) {
210
- console.warn(`Error fetching GitHub source ${source.permalink}:`, error);
211
- return null;
212
- }
213
- }
214
- /**
215
- * Create GitHub card element from repo data.
216
- */
217
- function createGitHubCard(repoData) {
218
- const statsChildren = [];
219
- if (repoData.language) statsChildren.push({
220
- type: "element",
221
- tagName: "span",
222
- properties: { className: ["ox-github-language"] },
223
- children: [{
224
- type: "element",
225
- tagName: "span",
226
- properties: {
227
- className: ["ox-github-language-color"],
228
- "data-lang": repoData.language.toLowerCase()
229
- },
230
- children: []
231
- }, {
232
- type: "text",
233
- value: repoData.language
234
- }]
235
- });
236
- statsChildren.push({
237
- type: "element",
238
- tagName: "span",
239
- properties: { className: ["ox-github-stat"] },
240
- children: [{
241
- type: "element",
242
- tagName: "svg",
243
- properties: {
244
- viewBox: "0 0 16 16",
245
- fill: "currentColor"
246
- },
247
- children: [{
248
- type: "element",
249
- tagName: "path",
250
- properties: { d: "M8 .25a.75.75 0 0 1 .673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611L7.327.668A.75.75 0 0 1 8 .25Z" },
251
- children: []
252
- }]
253
- }, {
254
- type: "text",
255
- value: formatNumber(repoData.stargazers_count)
256
- }]
257
- });
258
- statsChildren.push({
259
- type: "element",
260
- tagName: "span",
261
- properties: { className: ["ox-github-stat"] },
262
- children: [{
263
- type: "element",
264
- tagName: "svg",
265
- properties: {
266
- viewBox: "0 0 16 16",
267
- fill: "currentColor"
268
- },
269
- children: [{
270
- type: "element",
271
- tagName: "path",
272
- properties: { d: "M5 5.372v.878c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75v-.878a2.25 2.25 0 1 1 1.5 0v.878a2.25 2.25 0 0 1-2.25 2.25h-1.5v2.128a2.251 2.251 0 1 1-1.5 0V8.5h-1.5A2.25 2.25 0 0 1 3.5 6.25v-.878a2.25 2.25 0 1 1 1.5 0ZM5 3.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Zm6.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3 8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z" },
273
- children: []
274
- }]
275
- }, {
276
- type: "text",
277
- value: formatNumber(repoData.forks_count)
278
- }]
279
- });
280
- return {
281
- type: "element",
282
- tagName: "a",
283
- properties: {
284
- className: ["ox-github-card"],
285
- href: repoData.html_url,
286
- target: "_blank",
287
- rel: "noopener noreferrer"
288
- },
289
- children: [
290
- {
291
- type: "element",
292
- tagName: "div",
293
- properties: { className: ["ox-github-header"] },
294
- children: [{
295
- type: "element",
296
- tagName: "svg",
297
- properties: {
298
- className: ["ox-github-icon"],
299
- viewBox: "0 0 16 16",
300
- fill: "currentColor"
301
- },
302
- children: [{
303
- type: "element",
304
- tagName: "path",
305
- properties: { d: "M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z" },
306
- children: []
307
- }]
308
- }, {
309
- type: "element",
310
- tagName: "span",
311
- properties: { className: ["ox-github-repo"] },
312
- children: [{
313
- type: "text",
314
- value: repoData.full_name
315
- }]
316
- }]
317
- },
318
- ...repoData.description ? [{
319
- type: "element",
320
- tagName: "p",
321
- properties: { className: ["ox-github-description"] },
322
- children: [{
323
- type: "text",
324
- value: repoData.description
325
- }]
326
- }] : [],
327
- {
328
- type: "element",
329
- tagName: "div",
330
- properties: { className: ["ox-github-stats"] },
331
- children: statsChildren
332
- }
333
- ]
334
- };
335
- }
336
- /**
337
- * Create fallback element when repo data is unavailable.
338
- */
339
- function createFallbackCard(repo) {
340
- return {
341
- type: "element",
342
- tagName: "a",
343
- properties: {
344
- className: ["ox-github-card", "error"],
345
- href: isSafeGitHubRepo(repo) ? `https://github.com/${repo}` : "#",
346
- target: "_blank",
347
- rel: "noopener noreferrer"
348
- },
349
- children: [{
350
- type: "element",
351
- tagName: "div",
352
- properties: { className: ["ox-github-header"] },
353
- children: [{
354
- type: "element",
355
- tagName: "svg",
356
- properties: {
357
- className: ["ox-github-icon"],
358
- viewBox: "0 0 16 16",
359
- fill: "currentColor"
360
- },
361
- children: [{
362
- type: "element",
363
- tagName: "path",
364
- properties: { d: "M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z" },
365
- children: []
366
- }]
367
- }, {
368
- type: "element",
369
- tagName: "span",
370
- properties: { className: ["ox-github-repo"] },
371
- children: [{
372
- type: "text",
373
- value: repo
374
- }]
375
- }]
376
- }]
377
- };
378
- }
379
- function inferLanguage(path) {
380
- const fileName = path.split("/").at(-1)?.toLowerCase() ?? "";
381
- if (fileName === "dockerfile") return "dockerfile";
382
- if (fileName === "makefile") return "makefile";
383
- const extension = fileName.includes(".") ? fileName.split(".").at(-1) : void 0;
384
- return extension ? EXTENSION_LANGUAGE_MAP.get(extension) ?? extension : null;
385
- }
386
- function normalizeSourceLines(content) {
387
- const lines = content.replace(/\r\n?/g, "\n").split("\n");
388
- if (lines.length > 1 && lines.at(-1) === "") lines.pop();
389
- return lines.length > 0 ? lines : [""];
390
- }
391
- function createGitHubSourceCard(source, lines, options) {
392
- const allLines = normalizeSourceLines(source.content);
393
- const start = Math.min(lines?.start ?? 1, allLines.length);
394
- const end = lines ? Math.min(lines.end, allLines.length) : Math.min(allLines.length, options.maxSourceLines);
395
- const selectedLines = allLines.slice(start - 1, end);
396
- const lineRange = {
397
- start,
398
- end
399
- };
400
- const loc = selectedLines.length;
401
- const rangeLabel = formatLineRange(lineRange);
402
- const locLabel = !lines && end < allLines.length ? `${rangeLabel} of ${allLines.length} LOC` : `${rangeLabel} - ${loc} LOC`;
403
- const languageClass = source.language ? [`language-${source.language}`] : [];
404
- return {
405
- type: "element",
406
- tagName: "figure",
407
- properties: {
408
- className: ["ox-github-code"],
409
- "data-loc": String(loc),
410
- "data-source": source.permalink
411
- },
412
- children: [{
413
- type: "element",
414
- tagName: "figcaption",
415
- properties: { className: ["ox-github-code-header"] },
416
- children: [{
417
- type: "element",
418
- tagName: "a",
419
- properties: {
420
- className: ["ox-github-code-title"],
421
- href: source.permalink,
422
- target: "_blank",
423
- rel: "noopener noreferrer"
424
- },
425
- children: [{
426
- type: "text",
427
- value: `${source.repo}/${source.path}`
428
- }]
429
- }, {
430
- type: "element",
431
- tagName: "span",
432
- properties: { className: ["ox-github-code-loc"] },
433
- children: [{
434
- type: "text",
435
- value: locLabel
436
- }]
437
- }]
438
- }, {
439
- type: "element",
440
- tagName: "pre",
441
- properties: {
442
- className: ["ox-github-code-block", ...languageClass],
443
- ...source.language ? { "data-language": source.language } : {}
444
- },
445
- children: [{
446
- type: "element",
447
- tagName: "code",
448
- properties: { className: languageClass },
449
- children: selectedLines.map((line, index) => {
450
- const lineNumber = start + index;
451
- return {
452
- type: "element",
453
- tagName: "span",
454
- properties: {
455
- className: ["line", "ox-github-code-line"],
456
- "data-line": String(lineNumber)
457
- },
458
- children: [{
459
- type: "element",
460
- tagName: "span",
461
- properties: { className: ["ox-github-code-line-number"] },
462
- children: [{
463
- type: "text",
464
- value: String(lineNumber)
465
- }]
466
- }, {
467
- type: "element",
468
- tagName: "span",
469
- properties: { className: ["ox-github-code-line-content"] },
470
- children: [{
471
- type: "text",
472
- value: line || " "
473
- }]
474
- }]
475
- };
476
- })
477
- }]
478
- }]
479
- };
480
- }
481
- /**
482
- * Collect all GitHub repos from HTML for pre-fetching.
483
- */
484
- async function collectGitHubRepos(html) {
485
- const repos = [];
486
- GITHUB_COMPONENT_RE.lastIndex = 0;
487
- let match;
488
- while ((match = GITHUB_COMPONENT_RE.exec(html)) !== null) {
489
- const attrs = parseAttributes(match[1]);
490
- if (attrs.path || attrs.file || attrs.permalink || attrs.url || attrs.href) continue;
491
- const repo = attrs.repo;
492
- if (repo && isSafeGitHubRepo(repo)) repos.push(repo);
493
- }
494
- return repos;
495
- }
496
- /**
497
- * Collect all GitHub source references from HTML for pre-fetching.
498
- */
499
- async function collectGitHubSources(html) {
500
- const sources = [];
501
- GITHUB_COMPONENT_RE.lastIndex = 0;
502
- let match;
503
- while ((match = GITHUB_COMPONENT_RE.exec(html)) !== null) {
504
- const source = sourceRefFromAttributes(parseAttributes(match[1]));
505
- if (source) sources.push(source);
506
- }
507
- return sources;
508
- }
509
- function parseAttributes(raw) {
510
- const attrs = {};
511
- ATTRIBUTE_RE.lastIndex = 0;
512
- let match;
513
- while ((match = ATTRIBUTE_RE.exec(raw)) !== null) attrs[match[1].toLowerCase()] = match[2] ?? match[3] ?? match[4] ?? "";
514
- return attrs;
515
- }
516
- function attributesFromElement(el) {
517
- const attrs = {};
518
- for (const name of [
519
- "permalink",
520
- "url",
521
- "href",
522
- "repo",
523
- "path",
524
- "file",
525
- "ref",
526
- "sha",
527
- "branch",
528
- "loc",
529
- "lines",
530
- "line"
531
- ]) {
532
- const value = getAttribute(el, name);
533
- if (value !== void 0) attrs[name] = value;
534
- }
535
- return attrs;
536
- }
537
- function sourceRefFromAttributes(attrs) {
538
- const permalink = attrs.permalink ?? attrs.url ?? attrs.href;
539
- if (permalink) return parseGitHubPermalink(permalink);
540
- const repo = attrs.repo;
541
- const path = attrs.path ?? attrs.file;
542
- if (!repo || !path || !isSafeGitHubRepo(repo) || !isSafeGitHubPath(path)) return null;
543
- const ref = attrs.ref ?? attrs.sha ?? attrs.branch ?? "main";
544
- if (!isSafeGitHubRef(ref)) return null;
545
- const source = {
546
- repo,
547
- ref,
548
- path,
549
- lines: parseGitHubLineRange(attrs.loc ?? attrs.lines ?? attrs.line)
550
- };
551
- return {
552
- ...source,
553
- permalink: createGitHubPermalink(source)
554
- };
555
- }
556
- /**
557
- * Pre-fetch all GitHub repos data.
558
- */
559
- async function prefetchGitHubRepos(repos, options) {
560
- const mergedOptions = {
561
- ...defaultOptions,
562
- ...options
563
- };
564
- const results = /* @__PURE__ */ new Map();
565
- await Promise.all(Array.from(new Set(repos)).map(async (repo) => {
566
- const data = await fetchRepoData(repo, mergedOptions);
567
- results.set(repo, data);
568
- }));
569
- return results;
570
- }
571
- /**
572
- * Pre-fetch all GitHub source files.
573
- */
574
- async function prefetchGitHubSources(sources, options) {
575
- const mergedOptions = {
576
- ...defaultOptions,
577
- ...options
578
- };
579
- const results = /* @__PURE__ */ new Map();
580
- const uniqueSources = Array.from(new Map(sources.map((source) => [sourceKey(source), source])).values());
581
- await Promise.all(uniqueSources.map(async (source) => {
582
- const data = await fetchGitHubSource(source, mergedOptions);
583
- results.set(sourceKey(source), data);
584
- }));
585
- return results;
586
- }
587
- /**
588
- * Rehype plugin to transform GitHub components.
589
- */
590
- function rehypeGitHub(repoDataMap, sourceDataMap, options) {
591
- return (tree) => {
592
- const visit = (node) => {
593
- if ("children" in node) for (let i = 0; i < node.children.length; i++) {
594
- const child = node.children[i];
595
- if (child.type === "element") if (child.tagName.toLowerCase() === "github") {
596
- const attrs = attributesFromElement(child);
597
- const source = sourceRefFromAttributes(attrs);
598
- if (source) {
599
- const sourceData = sourceDataMap.get(sourceKey(source));
600
- node.children[i] = sourceData ? createGitHubSourceCard(sourceData, source.lines, options) : createFallbackCard(source.permalink);
601
- continue;
602
- }
603
- const repo = attrs.repo;
604
- if (repo) {
605
- const repoData = repoDataMap.get(repo);
606
- const cardElement = repoData ? createGitHubCard(repoData) : createFallbackCard(repo);
607
- node.children[i] = cardElement;
608
- }
609
- } else visit(child);
610
- }
611
- };
612
- visit(tree);
613
- };
614
- }
615
- /**
616
- * Transform GitHub components in HTML.
617
- */
618
- async function transformGitHub(html, repoDataMap, options) {
619
- const mergedOptions = {
620
- ...defaultOptions,
621
- ...options
622
- };
623
- let dataMap = repoDataMap;
624
- if (!dataMap) dataMap = await prefetchGitHubRepos(await collectGitHubRepos(html), mergedOptions);
625
- const sourceDataMap = await prefetchGitHubSources(await collectGitHubSources(html), mergedOptions);
626
- const result = await unified().use(rehypeParse, { fragment: true }).use(rehypeGitHub, dataMap, sourceDataMap, mergedOptions).use(rehypeStringify).process(html);
627
- return String(result);
628
- }
629
- //#endregion
630
- export { fetchRepoData as a, parseGitHubPermalink as c, transformGitHub as d, fetchGitHubSource as i, prefetchGitHubRepos as l, collectGitHubSources as n, isSafeGitHubRepo as o, createGitHubPermalink as r, parseGitHubLineRange as s, collectGitHubRepos as t, prefetchGitHubSources as u };
631
-
632
- //# sourceMappingURL=github2.mjs.map
1
+ import { t as transformGitHub } from "./github.mjs";
2
+ export { transformGitHub };