@ox-content/vite-plugin 2.10.0 → 2.12.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/chunk.cjs +0 -7
- package/dist/github.cjs +389 -12
- package/dist/github.cjs.map +1 -1
- package/dist/github.mjs +2 -299
- package/dist/github2.mjs +632 -0
- package/dist/github2.mjs.map +1 -0
- package/dist/index.cjs +761 -9370
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +259 -169
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +259 -169
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +684 -9272
- package/dist/index.mjs.map +1 -1
- package/dist/mermaid.cjs +16 -11
- package/dist/mermaid.cjs.map +1 -1
- package/dist/mermaid.mjs +16 -51
- package/dist/mermaid.mjs.map +1 -1
- package/dist/mermaid2.mjs +2 -0
- package/dist/ogp.cjs +2 -2
- package/dist/ogp.cjs.map +1 -1
- package/dist/ogp.mjs +2 -307
- package/dist/ogp2.mjs +299 -0
- package/dist/ogp2.mjs.map +1 -0
- package/dist/tabs.cjs +2 -2
- package/dist/tabs.cjs.map +1 -1
- package/dist/tabs.mjs +2 -188
- package/dist/tabs2.mjs +182 -0
- package/dist/tabs2.mjs.map +1 -0
- package/dist/vitepress-cli.cjs +1 -1
- package/dist/vitepress-cli.cjs.map +1 -1
- package/dist/vitepress-cli.mjs.map +1 -1
- package/dist/vitepress.cjs.map +1 -1
- package/dist/vitepress.mjs.map +1 -1
- package/dist/youtube.cjs +2 -2
- package/dist/youtube.cjs.map +1 -1
- package/dist/youtube.mjs +2 -117
- package/dist/youtube2.mjs +112 -0
- package/dist/youtube2.mjs.map +1 -0
- package/package.json +15 -15
- package/dist/github.mjs.map +0 -1
- package/dist/ogp.mjs.map +0 -1
- package/dist/tabs.mjs.map +0 -1
- package/dist/youtube.mjs.map +0 -1
package/dist/chunk.cjs
CHANGED
|
@@ -6,7 +6,6 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __esmMin = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
9
|
-
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
10
9
|
var __exportAll = (all, no_symbols) => {
|
|
11
10
|
let target = {};
|
|
12
11
|
for (var name in all) __defProp(target, name, {
|
|
@@ -32,12 +31,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
32
31
|
}) : target, mod));
|
|
33
32
|
var __toCommonJS = (mod) => __hasOwnProp.call(mod, "module.exports") ? mod["module.exports"] : __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
34
33
|
//#endregion
|
|
35
|
-
Object.defineProperty(exports, "__commonJSMin", {
|
|
36
|
-
enumerable: true,
|
|
37
|
-
get: function() {
|
|
38
|
-
return __commonJSMin;
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
34
|
Object.defineProperty(exports, "__esmMin", {
|
|
42
35
|
enumerable: true,
|
|
43
36
|
get: function() {
|
package/dist/github.cjs
CHANGED
|
@@ -1,33 +1,139 @@
|
|
|
1
1
|
const require_chunk = require("./chunk.cjs");
|
|
2
2
|
let unified = require("unified");
|
|
3
3
|
let rehype_parse = require("rehype-parse");
|
|
4
|
-
rehype_parse = require_chunk.__toESM(rehype_parse);
|
|
4
|
+
rehype_parse = require_chunk.__toESM(rehype_parse, 1);
|
|
5
5
|
let rehype_stringify = require("rehype-stringify");
|
|
6
|
-
rehype_stringify = require_chunk.__toESM(rehype_stringify);
|
|
6
|
+
rehype_stringify = require_chunk.__toESM(rehype_stringify, 1);
|
|
7
|
+
let node_buffer = require("node:buffer");
|
|
7
8
|
//#region src/plugins/github.ts
|
|
8
9
|
/**
|
|
9
|
-
* GitHub Plugin - Repository
|
|
10
|
+
* GitHub Plugin - Repository and source code embedding
|
|
10
11
|
*
|
|
11
|
-
* Transforms <GitHub> components into static repository cards
|
|
12
|
+
* Transforms <GitHub> components into static repository and source code cards
|
|
12
13
|
* by fetching data from GitHub API at build time.
|
|
13
14
|
*/
|
|
14
15
|
var github_exports = /* @__PURE__ */ require_chunk.__exportAll({
|
|
15
16
|
collectGitHubRepos: () => collectGitHubRepos,
|
|
17
|
+
collectGitHubSources: () => collectGitHubSources,
|
|
18
|
+
createGitHubPermalink: () => createGitHubPermalink,
|
|
19
|
+
fetchGitHubSource: () => fetchGitHubSource,
|
|
16
20
|
fetchRepoData: () => fetchRepoData,
|
|
17
21
|
isSafeGitHubRepo: () => isSafeGitHubRepo,
|
|
22
|
+
parseGitHubLineRange: () => parseGitHubLineRange,
|
|
23
|
+
parseGitHubPermalink: () => parseGitHubPermalink,
|
|
18
24
|
prefetchGitHubRepos: () => prefetchGitHubRepos,
|
|
25
|
+
prefetchGitHubSources: () => prefetchGitHubSources,
|
|
19
26
|
transformGitHub: () => transformGitHub
|
|
20
27
|
});
|
|
21
28
|
const defaultOptions = {
|
|
22
29
|
token: "",
|
|
23
30
|
cache: true,
|
|
24
|
-
cacheTTL: 36e5
|
|
31
|
+
cacheTTL: 36e5,
|
|
32
|
+
maxSourceBytes: 2e5,
|
|
33
|
+
maxSourceLines: 120
|
|
25
34
|
};
|
|
26
35
|
const repoCache = /* @__PURE__ */ new Map();
|
|
36
|
+
const sourceCache = /* @__PURE__ */ new Map();
|
|
27
37
|
const GITHUB_REPO_RE = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
38
|
+
const GITHUB_COMPONENT_RE = /<github\b([^>]*)>/gi;
|
|
39
|
+
const ATTRIBUTE_RE = /([:\w-]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>/]+)))?/g;
|
|
40
|
+
const EXTENSION_LANGUAGE_MAP = new Map([
|
|
41
|
+
["cjs", "javascript"],
|
|
42
|
+
["css", "css"],
|
|
43
|
+
["go", "go"],
|
|
44
|
+
["html", "html"],
|
|
45
|
+
["js", "javascript"],
|
|
46
|
+
["json", "json"],
|
|
47
|
+
["jsx", "jsx"],
|
|
48
|
+
["md", "markdown"],
|
|
49
|
+
["mdx", "mdx"],
|
|
50
|
+
["mjs", "javascript"],
|
|
51
|
+
["py", "python"],
|
|
52
|
+
["rb", "ruby"],
|
|
53
|
+
["rs", "rust"],
|
|
54
|
+
["sh", "shell"],
|
|
55
|
+
["svelte", "svelte"],
|
|
56
|
+
["toml", "toml"],
|
|
57
|
+
["ts", "typescript"],
|
|
58
|
+
["tsx", "tsx"],
|
|
59
|
+
["vue", "vue"],
|
|
60
|
+
["yaml", "yaml"],
|
|
61
|
+
["yml", "yaml"]
|
|
62
|
+
]);
|
|
63
|
+
function hasControlChar(value) {
|
|
64
|
+
for (let index = 0; index < value.length; index++) {
|
|
65
|
+
const code = value.charCodeAt(index);
|
|
66
|
+
if (code <= 31 || code === 127) return true;
|
|
67
|
+
}
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
28
70
|
function isSafeGitHubRepo(repo) {
|
|
29
71
|
return GITHUB_REPO_RE.test(repo) && !repo.split("/").some((part) => part === "." || part === "..");
|
|
30
72
|
}
|
|
73
|
+
function isSafeGitHubRef(ref) {
|
|
74
|
+
return Boolean(ref) && !hasControlChar(ref) && !hasUnsafePathSegment(ref);
|
|
75
|
+
}
|
|
76
|
+
function isSafeGitHubPath(path) {
|
|
77
|
+
return Boolean(path) && !hasControlChar(path) && !hasUnsafePathSegment(path);
|
|
78
|
+
}
|
|
79
|
+
function hasUnsafePathSegment(value) {
|
|
80
|
+
return value.split("/").some((part) => !part || part === "." || part === ".." || part.includes("\\"));
|
|
81
|
+
}
|
|
82
|
+
function encodePath(path) {
|
|
83
|
+
return path.split("/").map(encodeURIComponent).join("/");
|
|
84
|
+
}
|
|
85
|
+
function sourceKey(source) {
|
|
86
|
+
return `${source.repo}@${source.ref}:${source.path}`;
|
|
87
|
+
}
|
|
88
|
+
function formatLineRange(lines) {
|
|
89
|
+
return lines.start === lines.end ? `L${lines.start}` : `L${lines.start}-L${lines.end}`;
|
|
90
|
+
}
|
|
91
|
+
function parseGitHubLineRange(value) {
|
|
92
|
+
if (!value) return void 0;
|
|
93
|
+
const match = value.trim().match(/^#?L?(\d+)(?:-L?(\d+))?$/i);
|
|
94
|
+
if (!match) return void 0;
|
|
95
|
+
const start = Number.parseInt(match[1], 10);
|
|
96
|
+
const end = match[2] ? Number.parseInt(match[2], 10) : start;
|
|
97
|
+
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 1 || end < start) return;
|
|
98
|
+
return {
|
|
99
|
+
start,
|
|
100
|
+
end
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function createGitHubPermalink(source) {
|
|
104
|
+
const fragment = source.lines ? `#${formatLineRange(source.lines)}` : "";
|
|
105
|
+
return `https://github.com/${source.repo}/blob/${encodeURIComponent(source.ref)}/${encodePath(source.path)}${fragment}`;
|
|
106
|
+
}
|
|
107
|
+
function parseGitHubPermalink(value) {
|
|
108
|
+
let url;
|
|
109
|
+
try {
|
|
110
|
+
url = new URL(value);
|
|
111
|
+
} catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
if (url.protocol !== "https:" || url.hostname !== "github.com") return null;
|
|
115
|
+
let parts;
|
|
116
|
+
try {
|
|
117
|
+
parts = url.pathname.split("/").filter(Boolean).map((part) => decodeURIComponent(part));
|
|
118
|
+
} catch {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
if (parts.length < 5 || parts[2] !== "blob") return null;
|
|
122
|
+
const repo = `${parts[0]}/${parts[1]}`;
|
|
123
|
+
const ref = parts[3];
|
|
124
|
+
const path = parts.slice(4).join("/");
|
|
125
|
+
if (!isSafeGitHubRepo(repo) || !isSafeGitHubRef(ref) || !isSafeGitHubPath(path)) return null;
|
|
126
|
+
const source = {
|
|
127
|
+
repo,
|
|
128
|
+
ref,
|
|
129
|
+
path,
|
|
130
|
+
lines: parseGitHubLineRange(url.hash)
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
...source,
|
|
134
|
+
permalink: createGitHubPermalink(source)
|
|
135
|
+
};
|
|
136
|
+
}
|
|
31
137
|
/**
|
|
32
138
|
* Get element attribute value.
|
|
33
139
|
*/
|
|
@@ -76,6 +182,52 @@ async function fetchRepoData(repo, options) {
|
|
|
76
182
|
}
|
|
77
183
|
}
|
|
78
184
|
/**
|
|
185
|
+
* Fetch source file data from GitHub API.
|
|
186
|
+
*/
|
|
187
|
+
async function fetchGitHubSource(source, options) {
|
|
188
|
+
if (!isSafeGitHubRepo(source.repo) || !isSafeGitHubRef(source.ref) || !isSafeGitHubPath(source.path)) return null;
|
|
189
|
+
const key = sourceKey(source);
|
|
190
|
+
if (options.cache) {
|
|
191
|
+
const cached = sourceCache.get(key);
|
|
192
|
+
if (cached && Date.now() - cached.timestamp < options.cacheTTL) return cached.data;
|
|
193
|
+
}
|
|
194
|
+
try {
|
|
195
|
+
const headers = {
|
|
196
|
+
Accept: "application/vnd.github.v3+json",
|
|
197
|
+
"User-Agent": "ox-content-github-plugin"
|
|
198
|
+
};
|
|
199
|
+
if (options.token) headers.Authorization = `Bearer ${options.token}`;
|
|
200
|
+
const apiUrl = `https://api.github.com/repos/${source.repo}/contents/${encodePath(source.path)}?ref=${encodeURIComponent(source.ref)}`;
|
|
201
|
+
const response = await fetch(apiUrl, { headers });
|
|
202
|
+
if (!response.ok) {
|
|
203
|
+
console.warn(`Failed to fetch GitHub source ${source.permalink}: ${response.status}`);
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
const data = await response.json();
|
|
207
|
+
if (data.type !== "file" || data.encoding !== "base64" || !data.content || (data.size ?? 0) > options.maxSourceBytes) return null;
|
|
208
|
+
const content = node_buffer.Buffer.from(data.content.replace(/\s/g, ""), "base64").toString("utf8");
|
|
209
|
+
if (node_buffer.Buffer.byteLength(content) > options.maxSourceBytes) return null;
|
|
210
|
+
const sourceData = {
|
|
211
|
+
repo: source.repo,
|
|
212
|
+
ref: source.ref,
|
|
213
|
+
path: source.path,
|
|
214
|
+
permalink: source.permalink,
|
|
215
|
+
content,
|
|
216
|
+
size: data.size ?? node_buffer.Buffer.byteLength(content),
|
|
217
|
+
html_url: data.html_url ?? source.permalink,
|
|
218
|
+
language: inferLanguage(source.path)
|
|
219
|
+
};
|
|
220
|
+
if (options.cache) sourceCache.set(key, {
|
|
221
|
+
data: sourceData,
|
|
222
|
+
timestamp: Date.now()
|
|
223
|
+
});
|
|
224
|
+
return sourceData;
|
|
225
|
+
} catch (error) {
|
|
226
|
+
console.warn(`Error fetching GitHub source ${source.permalink}:`, error);
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
79
231
|
* Create GitHub card element from repo data.
|
|
80
232
|
*/
|
|
81
233
|
function createGitHubCard(repoData) {
|
|
@@ -240,17 +392,184 @@ function createFallbackCard(repo) {
|
|
|
240
392
|
}]
|
|
241
393
|
};
|
|
242
394
|
}
|
|
395
|
+
function inferLanguage(path) {
|
|
396
|
+
const fileName = path.split("/").at(-1)?.toLowerCase() ?? "";
|
|
397
|
+
if (fileName === "dockerfile") return "dockerfile";
|
|
398
|
+
if (fileName === "makefile") return "makefile";
|
|
399
|
+
const extension = fileName.includes(".") ? fileName.split(".").at(-1) : void 0;
|
|
400
|
+
return extension ? EXTENSION_LANGUAGE_MAP.get(extension) ?? extension : null;
|
|
401
|
+
}
|
|
402
|
+
function normalizeSourceLines(content) {
|
|
403
|
+
const lines = content.replace(/\r\n?/g, "\n").split("\n");
|
|
404
|
+
if (lines.length > 1 && lines.at(-1) === "") lines.pop();
|
|
405
|
+
return lines.length > 0 ? lines : [""];
|
|
406
|
+
}
|
|
407
|
+
function createGitHubSourceCard(source, lines, options) {
|
|
408
|
+
const allLines = normalizeSourceLines(source.content);
|
|
409
|
+
const start = Math.min(lines?.start ?? 1, allLines.length);
|
|
410
|
+
const end = lines ? Math.min(lines.end, allLines.length) : Math.min(allLines.length, options.maxSourceLines);
|
|
411
|
+
const selectedLines = allLines.slice(start - 1, end);
|
|
412
|
+
const lineRange = {
|
|
413
|
+
start,
|
|
414
|
+
end
|
|
415
|
+
};
|
|
416
|
+
const loc = selectedLines.length;
|
|
417
|
+
const rangeLabel = formatLineRange(lineRange);
|
|
418
|
+
const locLabel = !lines && end < allLines.length ? `${rangeLabel} of ${allLines.length} LOC` : `${rangeLabel} - ${loc} LOC`;
|
|
419
|
+
const languageClass = source.language ? [`language-${source.language}`] : [];
|
|
420
|
+
return {
|
|
421
|
+
type: "element",
|
|
422
|
+
tagName: "figure",
|
|
423
|
+
properties: {
|
|
424
|
+
className: ["ox-github-code"],
|
|
425
|
+
"data-loc": String(loc),
|
|
426
|
+
"data-source": source.permalink
|
|
427
|
+
},
|
|
428
|
+
children: [{
|
|
429
|
+
type: "element",
|
|
430
|
+
tagName: "figcaption",
|
|
431
|
+
properties: { className: ["ox-github-code-header"] },
|
|
432
|
+
children: [{
|
|
433
|
+
type: "element",
|
|
434
|
+
tagName: "a",
|
|
435
|
+
properties: {
|
|
436
|
+
className: ["ox-github-code-title"],
|
|
437
|
+
href: source.permalink,
|
|
438
|
+
target: "_blank",
|
|
439
|
+
rel: "noopener noreferrer"
|
|
440
|
+
},
|
|
441
|
+
children: [{
|
|
442
|
+
type: "text",
|
|
443
|
+
value: `${source.repo}/${source.path}`
|
|
444
|
+
}]
|
|
445
|
+
}, {
|
|
446
|
+
type: "element",
|
|
447
|
+
tagName: "span",
|
|
448
|
+
properties: { className: ["ox-github-code-loc"] },
|
|
449
|
+
children: [{
|
|
450
|
+
type: "text",
|
|
451
|
+
value: locLabel
|
|
452
|
+
}]
|
|
453
|
+
}]
|
|
454
|
+
}, {
|
|
455
|
+
type: "element",
|
|
456
|
+
tagName: "pre",
|
|
457
|
+
properties: {
|
|
458
|
+
className: ["ox-github-code-block", ...languageClass],
|
|
459
|
+
...source.language ? { "data-language": source.language } : {}
|
|
460
|
+
},
|
|
461
|
+
children: [{
|
|
462
|
+
type: "element",
|
|
463
|
+
tagName: "code",
|
|
464
|
+
properties: { className: languageClass },
|
|
465
|
+
children: selectedLines.map((line, index) => {
|
|
466
|
+
const lineNumber = start + index;
|
|
467
|
+
return {
|
|
468
|
+
type: "element",
|
|
469
|
+
tagName: "span",
|
|
470
|
+
properties: {
|
|
471
|
+
className: ["line", "ox-github-code-line"],
|
|
472
|
+
"data-line": String(lineNumber)
|
|
473
|
+
},
|
|
474
|
+
children: [{
|
|
475
|
+
type: "element",
|
|
476
|
+
tagName: "span",
|
|
477
|
+
properties: { className: ["ox-github-code-line-number"] },
|
|
478
|
+
children: [{
|
|
479
|
+
type: "text",
|
|
480
|
+
value: String(lineNumber)
|
|
481
|
+
}]
|
|
482
|
+
}, {
|
|
483
|
+
type: "element",
|
|
484
|
+
tagName: "span",
|
|
485
|
+
properties: { className: ["ox-github-code-line-content"] },
|
|
486
|
+
children: [{
|
|
487
|
+
type: "text",
|
|
488
|
+
value: line || " "
|
|
489
|
+
}]
|
|
490
|
+
}]
|
|
491
|
+
};
|
|
492
|
+
})
|
|
493
|
+
}]
|
|
494
|
+
}]
|
|
495
|
+
};
|
|
496
|
+
}
|
|
243
497
|
/**
|
|
244
498
|
* Collect all GitHub repos from HTML for pre-fetching.
|
|
245
499
|
*/
|
|
246
500
|
async function collectGitHubRepos(html) {
|
|
247
501
|
const repos = [];
|
|
248
|
-
|
|
502
|
+
GITHUB_COMPONENT_RE.lastIndex = 0;
|
|
249
503
|
let match;
|
|
250
|
-
while ((match =
|
|
504
|
+
while ((match = GITHUB_COMPONENT_RE.exec(html)) !== null) {
|
|
505
|
+
const attrs = parseAttributes(match[1]);
|
|
506
|
+
if (attrs.path || attrs.file || attrs.permalink || attrs.url || attrs.href) continue;
|
|
507
|
+
const repo = attrs.repo;
|
|
508
|
+
if (repo && isSafeGitHubRepo(repo)) repos.push(repo);
|
|
509
|
+
}
|
|
251
510
|
return repos;
|
|
252
511
|
}
|
|
253
512
|
/**
|
|
513
|
+
* Collect all GitHub source references from HTML for pre-fetching.
|
|
514
|
+
*/
|
|
515
|
+
async function collectGitHubSources(html) {
|
|
516
|
+
const sources = [];
|
|
517
|
+
GITHUB_COMPONENT_RE.lastIndex = 0;
|
|
518
|
+
let match;
|
|
519
|
+
while ((match = GITHUB_COMPONENT_RE.exec(html)) !== null) {
|
|
520
|
+
const source = sourceRefFromAttributes(parseAttributes(match[1]));
|
|
521
|
+
if (source) sources.push(source);
|
|
522
|
+
}
|
|
523
|
+
return sources;
|
|
524
|
+
}
|
|
525
|
+
function parseAttributes(raw) {
|
|
526
|
+
const attrs = {};
|
|
527
|
+
ATTRIBUTE_RE.lastIndex = 0;
|
|
528
|
+
let match;
|
|
529
|
+
while ((match = ATTRIBUTE_RE.exec(raw)) !== null) attrs[match[1].toLowerCase()] = match[2] ?? match[3] ?? match[4] ?? "";
|
|
530
|
+
return attrs;
|
|
531
|
+
}
|
|
532
|
+
function attributesFromElement(el) {
|
|
533
|
+
const attrs = {};
|
|
534
|
+
for (const name of [
|
|
535
|
+
"permalink",
|
|
536
|
+
"url",
|
|
537
|
+
"href",
|
|
538
|
+
"repo",
|
|
539
|
+
"path",
|
|
540
|
+
"file",
|
|
541
|
+
"ref",
|
|
542
|
+
"sha",
|
|
543
|
+
"branch",
|
|
544
|
+
"loc",
|
|
545
|
+
"lines",
|
|
546
|
+
"line"
|
|
547
|
+
]) {
|
|
548
|
+
const value = getAttribute(el, name);
|
|
549
|
+
if (value !== void 0) attrs[name] = value;
|
|
550
|
+
}
|
|
551
|
+
return attrs;
|
|
552
|
+
}
|
|
553
|
+
function sourceRefFromAttributes(attrs) {
|
|
554
|
+
const permalink = attrs.permalink ?? attrs.url ?? attrs.href;
|
|
555
|
+
if (permalink) return parseGitHubPermalink(permalink);
|
|
556
|
+
const repo = attrs.repo;
|
|
557
|
+
const path = attrs.path ?? attrs.file;
|
|
558
|
+
if (!repo || !path || !isSafeGitHubRepo(repo) || !isSafeGitHubPath(path)) return null;
|
|
559
|
+
const ref = attrs.ref ?? attrs.sha ?? attrs.branch ?? "main";
|
|
560
|
+
if (!isSafeGitHubRef(ref)) return null;
|
|
561
|
+
const source = {
|
|
562
|
+
repo,
|
|
563
|
+
ref,
|
|
564
|
+
path,
|
|
565
|
+
lines: parseGitHubLineRange(attrs.loc ?? attrs.lines ?? attrs.line)
|
|
566
|
+
};
|
|
567
|
+
return {
|
|
568
|
+
...source,
|
|
569
|
+
permalink: createGitHubPermalink(source)
|
|
570
|
+
};
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
254
573
|
* Pre-fetch all GitHub repos data.
|
|
255
574
|
*/
|
|
256
575
|
async function prefetchGitHubRepos(repos, options) {
|
|
@@ -259,22 +578,45 @@ async function prefetchGitHubRepos(repos, options) {
|
|
|
259
578
|
...options
|
|
260
579
|
};
|
|
261
580
|
const results = /* @__PURE__ */ new Map();
|
|
262
|
-
await Promise.all(repos.map(async (repo) => {
|
|
581
|
+
await Promise.all(Array.from(new Set(repos)).map(async (repo) => {
|
|
263
582
|
const data = await fetchRepoData(repo, mergedOptions);
|
|
264
583
|
results.set(repo, data);
|
|
265
584
|
}));
|
|
266
585
|
return results;
|
|
267
586
|
}
|
|
268
587
|
/**
|
|
588
|
+
* Pre-fetch all GitHub source files.
|
|
589
|
+
*/
|
|
590
|
+
async function prefetchGitHubSources(sources, options) {
|
|
591
|
+
const mergedOptions = {
|
|
592
|
+
...defaultOptions,
|
|
593
|
+
...options
|
|
594
|
+
};
|
|
595
|
+
const results = /* @__PURE__ */ new Map();
|
|
596
|
+
const uniqueSources = Array.from(new Map(sources.map((source) => [sourceKey(source), source])).values());
|
|
597
|
+
await Promise.all(uniqueSources.map(async (source) => {
|
|
598
|
+
const data = await fetchGitHubSource(source, mergedOptions);
|
|
599
|
+
results.set(sourceKey(source), data);
|
|
600
|
+
}));
|
|
601
|
+
return results;
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
269
604
|
* Rehype plugin to transform GitHub components.
|
|
270
605
|
*/
|
|
271
|
-
function rehypeGitHub(repoDataMap) {
|
|
606
|
+
function rehypeGitHub(repoDataMap, sourceDataMap, options) {
|
|
272
607
|
return (tree) => {
|
|
273
608
|
const visit = (node) => {
|
|
274
609
|
if ("children" in node) for (let i = 0; i < node.children.length; i++) {
|
|
275
610
|
const child = node.children[i];
|
|
276
611
|
if (child.type === "element") if (child.tagName.toLowerCase() === "github") {
|
|
277
|
-
const
|
|
612
|
+
const attrs = attributesFromElement(child);
|
|
613
|
+
const source = sourceRefFromAttributes(attrs);
|
|
614
|
+
if (source) {
|
|
615
|
+
const sourceData = sourceDataMap.get(sourceKey(source));
|
|
616
|
+
node.children[i] = sourceData ? createGitHubSourceCard(sourceData, source.lines, options) : createFallbackCard(source.permalink);
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
const repo = attrs.repo;
|
|
278
620
|
if (repo) {
|
|
279
621
|
const repoData = repoDataMap.get(repo);
|
|
280
622
|
const cardElement = repoData ? createGitHubCard(repoData) : createFallbackCard(repo);
|
|
@@ -290,9 +632,14 @@ function rehypeGitHub(repoDataMap) {
|
|
|
290
632
|
* Transform GitHub components in HTML.
|
|
291
633
|
*/
|
|
292
634
|
async function transformGitHub(html, repoDataMap, options) {
|
|
635
|
+
const mergedOptions = {
|
|
636
|
+
...defaultOptions,
|
|
637
|
+
...options
|
|
638
|
+
};
|
|
293
639
|
let dataMap = repoDataMap;
|
|
294
|
-
if (!dataMap) dataMap = await prefetchGitHubRepos(await collectGitHubRepos(html),
|
|
295
|
-
const
|
|
640
|
+
if (!dataMap) dataMap = await prefetchGitHubRepos(await collectGitHubRepos(html), mergedOptions);
|
|
641
|
+
const sourceDataMap = await prefetchGitHubSources(await collectGitHubSources(html), mergedOptions);
|
|
642
|
+
const result = await (0, unified.unified)().use(rehype_parse.default, { fragment: true }).use(rehypeGitHub, dataMap, sourceDataMap, mergedOptions).use(rehype_stringify.default).process(html);
|
|
296
643
|
return String(result);
|
|
297
644
|
}
|
|
298
645
|
//#endregion
|
|
@@ -302,6 +649,18 @@ Object.defineProperty(exports, "collectGitHubRepos", {
|
|
|
302
649
|
return collectGitHubRepos;
|
|
303
650
|
}
|
|
304
651
|
});
|
|
652
|
+
Object.defineProperty(exports, "collectGitHubSources", {
|
|
653
|
+
enumerable: true,
|
|
654
|
+
get: function() {
|
|
655
|
+
return collectGitHubSources;
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
Object.defineProperty(exports, "fetchGitHubSource", {
|
|
659
|
+
enumerable: true,
|
|
660
|
+
get: function() {
|
|
661
|
+
return fetchGitHubSource;
|
|
662
|
+
}
|
|
663
|
+
});
|
|
305
664
|
Object.defineProperty(exports, "fetchRepoData", {
|
|
306
665
|
enumerable: true,
|
|
307
666
|
get: function() {
|
|
@@ -314,12 +673,30 @@ Object.defineProperty(exports, "github_exports", {
|
|
|
314
673
|
return github_exports;
|
|
315
674
|
}
|
|
316
675
|
});
|
|
676
|
+
Object.defineProperty(exports, "parseGitHubLineRange", {
|
|
677
|
+
enumerable: true,
|
|
678
|
+
get: function() {
|
|
679
|
+
return parseGitHubLineRange;
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
Object.defineProperty(exports, "parseGitHubPermalink", {
|
|
683
|
+
enumerable: true,
|
|
684
|
+
get: function() {
|
|
685
|
+
return parseGitHubPermalink;
|
|
686
|
+
}
|
|
687
|
+
});
|
|
317
688
|
Object.defineProperty(exports, "prefetchGitHubRepos", {
|
|
318
689
|
enumerable: true,
|
|
319
690
|
get: function() {
|
|
320
691
|
return prefetchGitHubRepos;
|
|
321
692
|
}
|
|
322
693
|
});
|
|
694
|
+
Object.defineProperty(exports, "prefetchGitHubSources", {
|
|
695
|
+
enumerable: true,
|
|
696
|
+
get: function() {
|
|
697
|
+
return prefetchGitHubSources;
|
|
698
|
+
}
|
|
699
|
+
});
|
|
323
700
|
Object.defineProperty(exports, "transformGitHub", {
|
|
324
701
|
enumerable: true,
|
|
325
702
|
get: function() {
|
package/dist/github.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github.cjs","names":["rehypeParse","rehypeStringify"],"sources":["../src/plugins/github.ts"],"sourcesContent":["/**\n * GitHub Plugin - Repository card embedding\n *\n * Transforms <GitHub> components into static repository cards\n * by fetching data from GitHub API at build time.\n */\n\nimport { unified } from \"unified\";\nimport rehypeParse from \"rehype-parse\";\nimport rehypeStringify from \"rehype-stringify\";\nimport type { Root, Element } from \"hast\";\n\nexport interface GitHubRepoData {\n name: string;\n full_name: string;\n description: string | null;\n html_url: string;\n stargazers_count: number;\n forks_count: number;\n language: string | null;\n owner: {\n login: string;\n avatar_url: string;\n };\n}\n\nexport interface GitHubOptions {\n /** GitHub API token for higher rate limits. */\n token?: string;\n /** Cache fetched data. Default: true */\n cache?: boolean;\n /** Cache TTL in milliseconds. Default: 3600000 (1 hour) */\n cacheTTL?: number;\n}\n\nconst defaultOptions: Required<GitHubOptions> = {\n token: \"\",\n cache: true,\n cacheTTL: 3600000,\n};\n\n// Simple in-memory cache\nconst repoCache = new Map<string, { data: GitHubRepoData; timestamp: number }>();\nconst GITHUB_REPO_RE = /^[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+$/;\n\nexport function isSafeGitHubRepo(repo: string): boolean {\n return (\n GITHUB_REPO_RE.test(repo) && !repo.split(\"/\").some((part) => part === \".\" || part === \"..\")\n );\n}\n\n/**\n * Get element attribute value.\n */\nfunction getAttribute(el: Element, name: string): string | undefined {\n const value = el.properties?.[name];\n if (typeof value === \"string\") return value;\n if (Array.isArray(value)) return value.join(\" \");\n return undefined;\n}\n\n/**\n * Format number with K/M suffix.\n */\nfunction formatNumber(num: number): string {\n if (num >= 1000000) {\n return `${(num / 1000000).toFixed(1)}M`;\n }\n if (num >= 1000) {\n return `${(num / 1000).toFixed(1)}k`;\n }\n return String(num);\n}\n\n/**\n * Fetch repository data from GitHub API.\n */\nexport async function fetchRepoData(\n repo: string,\n options: Required<GitHubOptions>,\n): Promise<GitHubRepoData | null> {\n if (!isSafeGitHubRepo(repo)) {\n return null;\n }\n\n // Check cache\n if (options.cache) {\n const cached = repoCache.get(repo);\n if (cached && Date.now() - cached.timestamp < options.cacheTTL) {\n return cached.data;\n }\n }\n\n try {\n const headers: Record<string, string> = {\n Accept: \"application/vnd.github.v3+json\",\n \"User-Agent\": \"ox-content-github-plugin\",\n };\n\n if (options.token) {\n headers.Authorization = `Bearer ${options.token}`;\n }\n\n const response = await fetch(`https://api.github.com/repos/${repo}`, { headers });\n\n if (!response.ok) {\n console.warn(`Failed to fetch GitHub repo ${repo}: ${response.status}`);\n return null;\n }\n\n const data = (await response.json()) as GitHubRepoData;\n\n // Cache the result\n if (options.cache) {\n repoCache.set(repo, { data, timestamp: Date.now() });\n }\n\n return data;\n } catch (error) {\n console.warn(`Error fetching GitHub repo ${repo}:`, error);\n return null;\n }\n}\n\n/**\n * Create GitHub card element from repo data.\n */\nfunction createGitHubCard(repoData: GitHubRepoData): Element {\n const statsChildren: Element[\"children\"] = [];\n\n // Language\n if (repoData.language) {\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-language\"] },\n children: [\n {\n type: \"element\",\n tagName: \"span\",\n properties: {\n className: [\"ox-github-language-color\"],\n \"data-lang\": repoData.language.toLowerCase(),\n },\n children: [],\n },\n { type: \"text\", value: repoData.language },\n ],\n });\n }\n\n // Stars\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n 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\",\n },\n children: [],\n },\n ],\n },\n { type: \"text\", value: formatNumber(repoData.stargazers_count) },\n ],\n });\n\n // Forks\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n 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\",\n },\n children: [],\n },\n ],\n },\n { type: \"text\", value: formatNumber(repoData.forks_count) },\n ],\n });\n\n return {\n type: \"element\",\n tagName: \"a\",\n properties: {\n className: [\"ox-github-card\"],\n href: repoData.html_url,\n target: \"_blank\",\n rel: \"noopener noreferrer\",\n },\n children: [\n // Header\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n 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\",\n },\n children: [],\n },\n ],\n },\n {\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-repo\"] },\n children: [{ type: \"text\", value: repoData.full_name }],\n },\n ],\n },\n // Description\n ...(repoData.description\n ? [\n {\n type: \"element\" as const,\n tagName: \"p\",\n properties: { className: [\"ox-github-description\"] },\n children: [{ type: \"text\" as const, value: repoData.description }],\n },\n ]\n : []),\n // Stats\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-stats\"] },\n children: statsChildren,\n },\n ],\n };\n}\n\n/**\n * Create fallback element when repo data is unavailable.\n */\nfunction createFallbackCard(repo: string): Element {\n const href = isSafeGitHubRepo(repo) ? `https://github.com/${repo}` : \"#\";\n return {\n type: \"element\",\n tagName: \"a\",\n properties: {\n className: [\"ox-github-card\", \"error\"],\n href,\n target: \"_blank\",\n rel: \"noopener noreferrer\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n 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\",\n },\n children: [],\n },\n ],\n },\n {\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-repo\"] },\n children: [{ type: \"text\", value: repo }],\n },\n ],\n },\n ],\n };\n}\n\n/**\n * Collect all GitHub repos from HTML for pre-fetching.\n */\nexport async function collectGitHubRepos(html: string): Promise<string[]> {\n const repos: string[] = [];\n const repoPattern = /<github[^>]*\\s+repo=[\"']([^\"']+)[\"']/gi;\n\n let match;\n while ((match = repoPattern.exec(html)) !== null) {\n if (isSafeGitHubRepo(match[1])) {\n repos.push(match[1]);\n }\n }\n\n return repos;\n}\n\n/**\n * Pre-fetch all GitHub repos data.\n */\nexport async function prefetchGitHubRepos(\n repos: string[],\n options?: GitHubOptions,\n): Promise<Map<string, GitHubRepoData | null>> {\n const mergedOptions = { ...defaultOptions, ...options };\n const results = new Map<string, GitHubRepoData | null>();\n\n await Promise.all(\n repos.map(async (repo) => {\n const data = await fetchRepoData(repo, mergedOptions);\n results.set(repo, data);\n }),\n );\n\n return results;\n}\n\n/**\n * Rehype plugin to transform GitHub components.\n */\nfunction rehypeGitHub(repoDataMap: Map<string, GitHubRepoData | null>) {\n return (tree: Root) => {\n const visit = (node: Root | Element) => {\n if (\"children\" in node) {\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n\n if (child.type === \"element\") {\n // Check for <GitHub> component\n if (child.tagName.toLowerCase() === \"github\") {\n const repo = getAttribute(child, \"repo\");\n\n if (repo) {\n const repoData = repoDataMap.get(repo);\n const cardElement = repoData\n ? createGitHubCard(repoData)\n : createFallbackCard(repo);\n node.children[i] = cardElement;\n }\n } else {\n visit(child);\n }\n }\n }\n }\n };\n\n visit(tree);\n };\n}\n\n/**\n * Transform GitHub components in HTML.\n */\nexport async function transformGitHub(\n html: string,\n repoDataMap?: Map<string, GitHubRepoData | null>,\n options?: GitHubOptions,\n): Promise<string> {\n // If no pre-fetched data, collect and fetch\n let dataMap = repoDataMap;\n if (!dataMap) {\n const repos = await collectGitHubRepos(html);\n dataMap = await prefetchGitHubRepos(repos, options);\n }\n\n const result = await unified()\n .use(rehypeParse, { fragment: true })\n .use(rehypeGitHub, dataMap)\n .use(rehypeStringify)\n .process(html);\n\n return String(result);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,iBAA0C;CAC9C,OAAO;CACP,OAAO;CACP,UAAU;CACX;AAGD,MAAM,4BAAY,IAAI,KAA0D;AAChF,MAAM,iBAAiB;AAEvB,SAAgB,iBAAiB,MAAuB;AACtD,QACE,eAAe,KAAK,KAAK,IAAI,CAAC,KAAK,MAAM,IAAI,CAAC,MAAM,SAAS,SAAS,OAAO,SAAS,KAAK;;;;;AAO/F,SAAS,aAAa,IAAa,MAAkC;CACnE,MAAM,QAAQ,GAAG,aAAa;AAC9B,KAAI,OAAO,UAAU,SAAU,QAAO;AACtC,KAAI,MAAM,QAAQ,MAAM,CAAE,QAAO,MAAM,KAAK,IAAI;;;;;AAOlD,SAAS,aAAa,KAAqB;AACzC,KAAI,OAAO,IACT,QAAO,IAAI,MAAM,KAAS,QAAQ,EAAE,CAAC;AAEvC,KAAI,OAAO,IACT,QAAO,IAAI,MAAM,KAAM,QAAQ,EAAE,CAAC;AAEpC,QAAO,OAAO,IAAI;;;;;AAMpB,eAAsB,cACpB,MACA,SACgC;AAChC,KAAI,CAAC,iBAAiB,KAAK,CACzB,QAAO;AAIT,KAAI,QAAQ,OAAO;EACjB,MAAM,SAAS,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,SAAS;AAE5B,QAAI,MAAM,SAAS,UAEjB,KAAI,MAAM,QAAQ,aAAa,KAAK,UAAU;KAC5C,MAAM,OAAO,aAAa,OAAO,OAAO;AAExC,SAAI,MAAM;MACR,MAAM,WAAW,YAAY,IAAI,KAAK;MACtC,MAAM,cAAc,WAChB,iBAAiB,SAAS,GAC1B,mBAAmB,KAAK;AAC5B,WAAK,SAAS,KAAK;;UAGrB,OAAM,MAAM;;;AAOtB,QAAM,KAAK;;;;;;AAOf,eAAsB,gBACpB,MACA,aACA,SACiB;CAEjB,IAAI,UAAU;AACd,KAAI,CAAC,QAEH,WAAU,MAAM,oBADF,MAAM,mBAAmB,KAAK,EACD,QAAQ;CAGrD,MAAM,SAAS,OAAA,GAAA,QAAA,UAAe,CAC3B,IAAIA,aAAAA,SAAa,EAAE,UAAU,MAAM,CAAC,CACpC,IAAI,cAAc,QAAQ,CAC1B,IAAIC,iBAAAA,QAAgB,CACpB,QAAQ,KAAK;AAEhB,QAAO,OAAO,OAAO"}
|
|
1
|
+
{"version":3,"file":"github.cjs","names":["Buffer","rehypeParse","rehypeStringify"],"sources":["../src/plugins/github.ts"],"sourcesContent":["/**\n * GitHub Plugin - Repository and source code embedding\n *\n * Transforms <GitHub> components into static repository and source code cards\n * by fetching data from GitHub API at build time.\n */\n\nimport { Buffer } from \"node:buffer\";\nimport { unified } from \"unified\";\nimport rehypeParse from \"rehype-parse\";\nimport rehypeStringify from \"rehype-stringify\";\nimport type { Root, Element } from \"hast\";\n\nexport interface GitHubRepoData {\n name: string;\n full_name: string;\n description: string | null;\n html_url: string;\n stargazers_count: number;\n forks_count: number;\n language: string | null;\n owner: {\n login: string;\n avatar_url: string;\n };\n}\n\nexport interface GitHubLineRange {\n start: number;\n end: number;\n}\n\nexport interface GitHubSourceRef {\n repo: string;\n ref: string;\n path: string;\n permalink: string;\n lines?: GitHubLineRange;\n}\n\nexport interface GitHubSourceData {\n repo: string;\n ref: string;\n path: string;\n permalink: string;\n content: string;\n size: number;\n html_url: string;\n language: string | null;\n}\n\nexport interface GitHubOptions {\n /** GitHub API token for higher rate limits. */\n token?: string;\n /** Cache fetched data. Default: true */\n cache?: boolean;\n /** Cache TTL in milliseconds. Default: 3600000 (1 hour) */\n cacheTTL?: number;\n /** Maximum source file size to inline in bytes. Default: 200000 */\n maxSourceBytes?: number;\n /** Maximum source lines to inline when no line range is specified. Default: 120 */\n maxSourceLines?: number;\n}\n\nconst defaultOptions: Required<GitHubOptions> = {\n token: \"\",\n cache: true,\n cacheTTL: 3600000,\n maxSourceBytes: 200000,\n maxSourceLines: 120,\n};\n\n// Simple in-memory cache\nconst repoCache = new Map<string, { data: GitHubRepoData; timestamp: number }>();\nconst sourceCache = new Map<string, { data: GitHubSourceData; timestamp: number }>();\nconst GITHUB_REPO_RE = /^[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+$/;\nconst GITHUB_COMPONENT_RE = /<github\\b([^>]*)>/gi;\nconst ATTRIBUTE_RE = /([:\\w-]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'>/]+)))?/g;\nconst EXTENSION_LANGUAGE_MAP = new Map<string, string>([\n [\"cjs\", \"javascript\"],\n [\"css\", \"css\"],\n [\"go\", \"go\"],\n [\"html\", \"html\"],\n [\"js\", \"javascript\"],\n [\"json\", \"json\"],\n [\"jsx\", \"jsx\"],\n [\"md\", \"markdown\"],\n [\"mdx\", \"mdx\"],\n [\"mjs\", \"javascript\"],\n [\"py\", \"python\"],\n [\"rb\", \"ruby\"],\n [\"rs\", \"rust\"],\n [\"sh\", \"shell\"],\n [\"svelte\", \"svelte\"],\n [\"toml\", \"toml\"],\n [\"ts\", \"typescript\"],\n [\"tsx\", \"tsx\"],\n [\"vue\", \"vue\"],\n [\"yaml\", \"yaml\"],\n [\"yml\", \"yaml\"],\n]);\n\nfunction hasControlChar(value: string): boolean {\n for (let index = 0; index < value.length; index++) {\n const code = value.charCodeAt(index);\n if (code <= 0x1f || code === 0x7f) {\n return true;\n }\n }\n return false;\n}\n\nexport function isSafeGitHubRepo(repo: string): boolean {\n return (\n GITHUB_REPO_RE.test(repo) && !repo.split(\"/\").some((part) => part === \".\" || part === \"..\")\n );\n}\n\nfunction isSafeGitHubRef(ref: string): boolean {\n return Boolean(ref) && !hasControlChar(ref) && !hasUnsafePathSegment(ref);\n}\n\nfunction isSafeGitHubPath(path: string): boolean {\n return Boolean(path) && !hasControlChar(path) && !hasUnsafePathSegment(path);\n}\n\nfunction hasUnsafePathSegment(value: string): boolean {\n return value\n .split(\"/\")\n .some((part) => !part || part === \".\" || part === \"..\" || part.includes(\"\\\\\"));\n}\n\nfunction encodePath(path: string): string {\n return path.split(\"/\").map(encodeURIComponent).join(\"/\");\n}\n\nfunction sourceKey(source: GitHubSourceRef): string {\n return `${source.repo}@${source.ref}:${source.path}`;\n}\n\nfunction formatLineRange(lines: GitHubLineRange): string {\n return lines.start === lines.end ? `L${lines.start}` : `L${lines.start}-L${lines.end}`;\n}\n\nexport function parseGitHubLineRange(value: string | undefined): GitHubLineRange | undefined {\n if (!value) return undefined;\n const match = value.trim().match(/^#?L?(\\d+)(?:-L?(\\d+))?$/i);\n if (!match) return undefined;\n\n const start = Number.parseInt(match[1], 10);\n const end = match[2] ? Number.parseInt(match[2], 10) : start;\n if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 1 || end < start) {\n return undefined;\n }\n\n return { start, end };\n}\n\nexport function createGitHubPermalink(source: Omit<GitHubSourceRef, \"permalink\">): string {\n const fragment = source.lines ? `#${formatLineRange(source.lines)}` : \"\";\n return `https://github.com/${source.repo}/blob/${encodeURIComponent(source.ref)}/${encodePath(\n source.path,\n )}${fragment}`;\n}\n\nexport function parseGitHubPermalink(value: string): GitHubSourceRef | null {\n let url: URL;\n try {\n url = new URL(value);\n } catch {\n return null;\n }\n\n if (url.protocol !== \"https:\" || url.hostname !== \"github.com\") {\n return null;\n }\n\n let parts: string[];\n try {\n parts = url.pathname\n .split(\"/\")\n .filter(Boolean)\n .map((part) => decodeURIComponent(part));\n } catch {\n return null;\n }\n\n if (parts.length < 5 || parts[2] !== \"blob\") {\n return null;\n }\n\n const repo = `${parts[0]}/${parts[1]}`;\n const ref = parts[3];\n const path = parts.slice(4).join(\"/\");\n if (!isSafeGitHubRepo(repo) || !isSafeGitHubRef(ref) || !isSafeGitHubPath(path)) {\n return null;\n }\n\n const lines = parseGitHubLineRange(url.hash);\n const source = { repo, ref, path, lines };\n return {\n ...source,\n permalink: createGitHubPermalink(source),\n };\n}\n\n/**\n * Get element attribute value.\n */\nfunction getAttribute(el: Element, name: string): string | undefined {\n const value = el.properties?.[name];\n if (typeof value === \"string\") return value;\n if (Array.isArray(value)) return value.join(\" \");\n return undefined;\n}\n\n/**\n * Format number with K/M suffix.\n */\nfunction formatNumber(num: number): string {\n if (num >= 1000000) {\n return `${(num / 1000000).toFixed(1)}M`;\n }\n if (num >= 1000) {\n return `${(num / 1000).toFixed(1)}k`;\n }\n return String(num);\n}\n\n/**\n * Fetch repository data from GitHub API.\n */\nexport async function fetchRepoData(\n repo: string,\n options: Required<GitHubOptions>,\n): Promise<GitHubRepoData | null> {\n if (!isSafeGitHubRepo(repo)) {\n return null;\n }\n\n // Check cache\n if (options.cache) {\n const cached = repoCache.get(repo);\n if (cached && Date.now() - cached.timestamp < options.cacheTTL) {\n return cached.data;\n }\n }\n\n try {\n const headers: Record<string, string> = {\n Accept: \"application/vnd.github.v3+json\",\n \"User-Agent\": \"ox-content-github-plugin\",\n };\n\n if (options.token) {\n headers.Authorization = `Bearer ${options.token}`;\n }\n\n const response = await fetch(`https://api.github.com/repos/${repo}`, { headers });\n\n if (!response.ok) {\n console.warn(`Failed to fetch GitHub repo ${repo}: ${response.status}`);\n return null;\n }\n\n const data = (await response.json()) as GitHubRepoData;\n\n // Cache the result\n if (options.cache) {\n repoCache.set(repo, { data, timestamp: Date.now() });\n }\n\n return data;\n } catch (error) {\n console.warn(`Error fetching GitHub repo ${repo}:`, error);\n return null;\n }\n}\n\ninterface GitHubContentApiFile {\n type: string;\n encoding?: string;\n content?: string;\n size?: number;\n html_url?: string;\n}\n\n/**\n * Fetch source file data from GitHub API.\n */\nexport async function fetchGitHubSource(\n source: GitHubSourceRef,\n options: Required<GitHubOptions>,\n): Promise<GitHubSourceData | null> {\n if (\n !isSafeGitHubRepo(source.repo) ||\n !isSafeGitHubRef(source.ref) ||\n !isSafeGitHubPath(source.path)\n ) {\n return null;\n }\n\n const key = sourceKey(source);\n if (options.cache) {\n const cached = sourceCache.get(key);\n if (cached && Date.now() - cached.timestamp < options.cacheTTL) {\n return cached.data;\n }\n }\n\n try {\n const headers: Record<string, string> = {\n Accept: \"application/vnd.github.v3+json\",\n \"User-Agent\": \"ox-content-github-plugin\",\n };\n\n if (options.token) {\n headers.Authorization = `Bearer ${options.token}`;\n }\n\n const apiUrl = `https://api.github.com/repos/${source.repo}/contents/${encodePath(\n source.path,\n )}?ref=${encodeURIComponent(source.ref)}`;\n const response = await fetch(apiUrl, { headers });\n\n if (!response.ok) {\n console.warn(`Failed to fetch GitHub source ${source.permalink}: ${response.status}`);\n return null;\n }\n\n const data = (await response.json()) as GitHubContentApiFile;\n if (\n data.type !== \"file\" ||\n data.encoding !== \"base64\" ||\n !data.content ||\n (data.size ?? 0) > options.maxSourceBytes\n ) {\n return null;\n }\n\n const content = Buffer.from(data.content.replace(/\\s/g, \"\"), \"base64\").toString(\"utf8\");\n if (Buffer.byteLength(content) > options.maxSourceBytes) {\n return null;\n }\n\n const sourceData: GitHubSourceData = {\n repo: source.repo,\n ref: source.ref,\n path: source.path,\n permalink: source.permalink,\n content,\n size: data.size ?? Buffer.byteLength(content),\n html_url: data.html_url ?? source.permalink,\n language: inferLanguage(source.path),\n };\n\n if (options.cache) {\n sourceCache.set(key, { data: sourceData, timestamp: Date.now() });\n }\n\n return sourceData;\n } catch (error) {\n console.warn(`Error fetching GitHub source ${source.permalink}:`, error);\n return null;\n }\n}\n\n/**\n * Create GitHub card element from repo data.\n */\nfunction createGitHubCard(repoData: GitHubRepoData): Element {\n const statsChildren: Element[\"children\"] = [];\n\n // Language\n if (repoData.language) {\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-language\"] },\n children: [\n {\n type: \"element\",\n tagName: \"span\",\n properties: {\n className: [\"ox-github-language-color\"],\n \"data-lang\": repoData.language.toLowerCase(),\n },\n children: [],\n },\n { type: \"text\", value: repoData.language },\n ],\n });\n }\n\n // Stars\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n 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\",\n },\n children: [],\n },\n ],\n },\n { type: \"text\", value: formatNumber(repoData.stargazers_count) },\n ],\n });\n\n // Forks\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n 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\",\n },\n children: [],\n },\n ],\n },\n { type: \"text\", value: formatNumber(repoData.forks_count) },\n ],\n });\n\n return {\n type: \"element\",\n tagName: \"a\",\n properties: {\n className: [\"ox-github-card\"],\n href: repoData.html_url,\n target: \"_blank\",\n rel: \"noopener noreferrer\",\n },\n children: [\n // Header\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n 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\",\n },\n children: [],\n },\n ],\n },\n {\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-repo\"] },\n children: [{ type: \"text\", value: repoData.full_name }],\n },\n ],\n },\n // Description\n ...(repoData.description\n ? [\n {\n type: \"element\" as const,\n tagName: \"p\",\n properties: { className: [\"ox-github-description\"] },\n children: [{ type: \"text\" as const, value: repoData.description }],\n },\n ]\n : []),\n // Stats\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-stats\"] },\n children: statsChildren,\n },\n ],\n };\n}\n\n/**\n * Create fallback element when repo data is unavailable.\n */\nfunction createFallbackCard(repo: string): Element {\n const href = isSafeGitHubRepo(repo) ? `https://github.com/${repo}` : \"#\";\n return {\n type: \"element\",\n tagName: \"a\",\n properties: {\n className: [\"ox-github-card\", \"error\"],\n href,\n target: \"_blank\",\n rel: \"noopener noreferrer\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n 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\",\n },\n children: [],\n },\n ],\n },\n {\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-repo\"] },\n children: [{ type: \"text\", value: repo }],\n },\n ],\n },\n ],\n };\n}\n\nfunction inferLanguage(path: string): string | null {\n const fileName = path.split(\"/\").at(-1)?.toLowerCase() ?? \"\";\n if (fileName === \"dockerfile\") return \"dockerfile\";\n if (fileName === \"makefile\") return \"makefile\";\n\n const extension = fileName.includes(\".\") ? fileName.split(\".\").at(-1) : undefined;\n return extension ? (EXTENSION_LANGUAGE_MAP.get(extension) ?? extension) : null;\n}\n\nfunction normalizeSourceLines(content: string): string[] {\n const lines = content.replace(/\\r\\n?/g, \"\\n\").split(\"\\n\");\n if (lines.length > 1 && lines.at(-1) === \"\") {\n lines.pop();\n }\n return lines.length > 0 ? lines : [\"\"];\n}\n\nfunction createGitHubSourceCard(\n source: GitHubSourceData,\n lines: GitHubLineRange | undefined,\n options: Required<GitHubOptions>,\n): Element {\n const allLines = normalizeSourceLines(source.content);\n const start = Math.min(lines?.start ?? 1, allLines.length);\n const end = lines\n ? Math.min(lines.end, allLines.length)\n : Math.min(allLines.length, options.maxSourceLines);\n const selectedLines = allLines.slice(start - 1, end);\n const lineRange = { start, end };\n const loc = selectedLines.length;\n const rangeLabel = formatLineRange(lineRange);\n const locLabel =\n !lines && end < allLines.length\n ? `${rangeLabel} of ${allLines.length} LOC`\n : `${rangeLabel} - ${loc} LOC`;\n const languageClass = source.language ? [`language-${source.language}`] : [];\n\n return {\n type: \"element\",\n tagName: \"figure\",\n properties: {\n className: [\"ox-github-code\"],\n \"data-loc\": String(loc),\n \"data-source\": source.permalink,\n },\n children: [\n {\n type: \"element\",\n tagName: \"figcaption\",\n properties: { className: [\"ox-github-code-header\"] },\n children: [\n {\n type: \"element\",\n tagName: \"a\",\n properties: {\n className: [\"ox-github-code-title\"],\n href: source.permalink,\n target: \"_blank\",\n rel: \"noopener noreferrer\",\n },\n children: [{ type: \"text\", value: `${source.repo}/${source.path}` }],\n },\n {\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-code-loc\"] },\n children: [{ type: \"text\", value: locLabel }],\n },\n ],\n },\n {\n type: \"element\",\n tagName: \"pre\",\n properties: {\n className: [\"ox-github-code-block\", ...languageClass],\n ...(source.language ? { \"data-language\": source.language } : {}),\n },\n children: [\n {\n type: \"element\",\n tagName: \"code\",\n properties: {\n className: languageClass,\n },\n children: selectedLines.map((line, index) => {\n const lineNumber = start + index;\n return {\n type: \"element\" as const,\n tagName: \"span\",\n properties: {\n className: [\"line\", \"ox-github-code-line\"],\n \"data-line\": String(lineNumber),\n },\n children: [\n {\n type: \"element\" as const,\n tagName: \"span\",\n properties: { className: [\"ox-github-code-line-number\"] },\n children: [{ type: \"text\" as const, value: String(lineNumber) }],\n },\n {\n type: \"element\" as const,\n tagName: \"span\",\n properties: { className: [\"ox-github-code-line-content\"] },\n children: [{ type: \"text\" as const, value: line || \" \" }],\n },\n ],\n };\n }),\n },\n ],\n },\n ],\n };\n}\n\n/**\n * Collect all GitHub repos from HTML for pre-fetching.\n */\nexport async function collectGitHubRepos(html: string): Promise<string[]> {\n const repos: string[] = [];\n\n GITHUB_COMPONENT_RE.lastIndex = 0;\n let match;\n while ((match = GITHUB_COMPONENT_RE.exec(html)) !== null) {\n const attrs = parseAttributes(match[1]);\n if (attrs.path || attrs.file || attrs.permalink || attrs.url || attrs.href) {\n continue;\n }\n\n const repo = attrs.repo;\n if (repo && isSafeGitHubRepo(repo)) {\n repos.push(repo);\n }\n }\n\n return repos;\n}\n\n/**\n * Collect all GitHub source references from HTML for pre-fetching.\n */\nexport async function collectGitHubSources(html: string): Promise<GitHubSourceRef[]> {\n const sources: GitHubSourceRef[] = [];\n\n GITHUB_COMPONENT_RE.lastIndex = 0;\n let match;\n while ((match = GITHUB_COMPONENT_RE.exec(html)) !== null) {\n const source = sourceRefFromAttributes(parseAttributes(match[1]));\n if (source) {\n sources.push(source);\n }\n }\n\n return sources;\n}\n\nfunction parseAttributes(raw: string): Record<string, string> {\n const attrs: Record<string, string> = {};\n ATTRIBUTE_RE.lastIndex = 0;\n let match;\n\n while ((match = ATTRIBUTE_RE.exec(raw)) !== null) {\n attrs[match[1].toLowerCase()] = match[2] ?? match[3] ?? match[4] ?? \"\";\n }\n\n return attrs;\n}\n\nfunction attributesFromElement(el: Element): Record<string, string> {\n const attrs: Record<string, string> = {};\n for (const name of [\n \"permalink\",\n \"url\",\n \"href\",\n \"repo\",\n \"path\",\n \"file\",\n \"ref\",\n \"sha\",\n \"branch\",\n \"loc\",\n \"lines\",\n \"line\",\n ]) {\n const value = getAttribute(el, name);\n if (value !== undefined) {\n attrs[name] = value;\n }\n }\n return attrs;\n}\n\nfunction sourceRefFromAttributes(attrs: Record<string, string>): GitHubSourceRef | null {\n const permalink = attrs.permalink ?? attrs.url ?? attrs.href;\n if (permalink) {\n return parseGitHubPermalink(permalink);\n }\n\n const repo = attrs.repo;\n const path = attrs.path ?? attrs.file;\n if (!repo || !path || !isSafeGitHubRepo(repo) || !isSafeGitHubPath(path)) {\n return null;\n }\n\n const ref = attrs.ref ?? attrs.sha ?? attrs.branch ?? \"main\";\n if (!isSafeGitHubRef(ref)) {\n return null;\n }\n\n const lines = parseGitHubLineRange(attrs.loc ?? attrs.lines ?? attrs.line);\n const source = { repo, ref, path, lines };\n return {\n ...source,\n permalink: createGitHubPermalink(source),\n };\n}\n\n/**\n * Pre-fetch all GitHub repos data.\n */\nexport async function prefetchGitHubRepos(\n repos: string[],\n options?: GitHubOptions,\n): Promise<Map<string, GitHubRepoData | null>> {\n const mergedOptions = { ...defaultOptions, ...options };\n const results = new Map<string, GitHubRepoData | null>();\n\n await Promise.all(\n Array.from(new Set(repos)).map(async (repo) => {\n const data = await fetchRepoData(repo, mergedOptions);\n results.set(repo, data);\n }),\n );\n\n return results;\n}\n\n/**\n * Pre-fetch all GitHub source files.\n */\nexport async function prefetchGitHubSources(\n sources: GitHubSourceRef[],\n options?: GitHubOptions,\n): Promise<Map<string, GitHubSourceData | null>> {\n const mergedOptions = { ...defaultOptions, ...options };\n const results = new Map<string, GitHubSourceData | null>();\n const uniqueSources = Array.from(\n new Map(sources.map((source) => [sourceKey(source), source])).values(),\n );\n\n await Promise.all(\n uniqueSources.map(async (source) => {\n const data = await fetchGitHubSource(source, mergedOptions);\n results.set(sourceKey(source), data);\n }),\n );\n\n return results;\n}\n\n/**\n * Rehype plugin to transform GitHub components.\n */\nfunction rehypeGitHub(\n repoDataMap: Map<string, GitHubRepoData | null>,\n sourceDataMap: Map<string, GitHubSourceData | null>,\n options: Required<GitHubOptions>,\n) {\n return (tree: Root) => {\n const visit = (node: Root | Element) => {\n if (\"children\" in node) {\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n\n if (child.type === \"element\") {\n // Check for <GitHub> component\n if (child.tagName.toLowerCase() === \"github\") {\n const attrs = attributesFromElement(child);\n const source = sourceRefFromAttributes(attrs);\n\n if (source) {\n const sourceData = sourceDataMap.get(sourceKey(source));\n node.children[i] = sourceData\n ? createGitHubSourceCard(sourceData, source.lines, options)\n : createFallbackCard(source.permalink);\n continue;\n }\n\n const repo = attrs.repo;\n if (repo) {\n const repoData = repoDataMap.get(repo);\n const cardElement = repoData\n ? createGitHubCard(repoData)\n : createFallbackCard(repo);\n node.children[i] = cardElement;\n }\n } else {\n visit(child);\n }\n }\n }\n }\n };\n\n visit(tree);\n };\n}\n\n/**\n * Transform GitHub components in HTML.\n */\nexport async function transformGitHub(\n html: string,\n repoDataMap?: Map<string, GitHubRepoData | null>,\n options?: GitHubOptions,\n): Promise<string> {\n const mergedOptions = { ...defaultOptions, ...options };\n // If no pre-fetched data, collect and fetch\n let dataMap = repoDataMap;\n if (!dataMap) {\n const repos = await collectGitHubRepos(html);\n dataMap = await prefetchGitHubRepos(repos, mergedOptions);\n }\n const sources = await collectGitHubSources(html);\n const sourceDataMap = await prefetchGitHubSources(sources, mergedOptions);\n\n const result = await unified()\n .use(rehypeParse, { fragment: true })\n .use(rehypeGitHub, dataMap, sourceDataMap, mergedOptions)\n .use(rehypeStringify)\n .process(html);\n\n return String(result);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,MAAM,iBAA0C;CAC9C,OAAO;CACP,OAAO;CACP,UAAU;CACV,gBAAgB;CAChB,gBAAgB;CACjB;AAGD,MAAM,4BAAY,IAAI,KAA0D;AAChF,MAAM,8BAAc,IAAI,KAA4D;AACpF,MAAM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