@ox-content/vite-plugin 2.75.0 → 2.75.1

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/github.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  const require_chunk = require("./chunk.cjs");
2
+ const require_interop = require("./interop.cjs");
2
3
  let unified = require("unified");
3
4
  let rehype_parse = require("rehype-parse");
4
5
  rehype_parse = require_chunk.__toESM(rehype_parse, 1);
@@ -575,6 +576,8 @@ function createGitHubSourceCard(source, lines, options) {
575
576
  }
576
577
  //#endregion
577
578
  //#region src/plugins/github/transform.ts
579
+ const rehypeParse = require_interop.interopDefault(rehype_parse.default);
580
+ const rehypeStringify = require_interop.interopDefault(rehype_stringify.default);
578
581
  /**
579
582
  * Rehype plugin to transform GitHub components.
580
583
  */
@@ -616,7 +619,7 @@ async function transformGitHub(html, repoDataMap, options) {
616
619
  let dataMap = repoDataMap;
617
620
  if (!dataMap) dataMap = await prefetchGitHubRepos(await collectGitHubRepos(html), mergedOptions);
618
621
  const sourceDataMap = await prefetchGitHubSources(await collectGitHubSources(html), mergedOptions);
619
- const result = await (0, unified.unified)().use(rehype_parse.default, { fragment: true }).use(rehypeGitHub, dataMap, sourceDataMap, mergedOptions).use(rehype_stringify.default).process(html);
622
+ const result = await (0, unified.unified)().use(rehypeParse, { fragment: true }).use(rehypeGitHub, dataMap, sourceDataMap, mergedOptions).use(rehypeStringify).process(html);
620
623
  return String(result);
621
624
  }
622
625
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"github.cjs","names":["Buffer","rehypeParse","rehypeStringify"],"sources":["../src/plugins/github/validation.ts","../src/plugins/github/source.ts","../src/plugins/github/types.ts","../src/plugins/github/api.ts","../src/plugins/github/attributes.ts","../src/plugins/github/fallback-card.ts","../src/plugins/github/repo-card.ts","../src/plugins/github/source-card.ts","../src/plugins/github/transform.ts","../src/plugins/github.ts"],"sourcesContent":["const GITHUB_REPO_RE = /^[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+$/;\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\nexport function isSafeGitHubRef(ref: string): boolean {\n return Boolean(ref) && !hasControlChar(ref) && !hasUnsafePathSegment(ref);\n}\n\nexport function 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\nexport function encodePath(path: string): string {\n return path.split(\"/\").map(encodeURIComponent).join(\"/\");\n}\n","import type { GitHubLineRange, GitHubSourceRef } from \"./types\";\nimport { encodePath, isSafeGitHubPath, isSafeGitHubRef, isSafeGitHubRepo } from \"./validation\";\n\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\nexport function sourceKey(source: GitHubSourceRef): string {\n return `${source.repo}@${source.ref}:${source.path}`;\n}\n\nexport function 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\nexport function 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","export 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 /**\n * GitHub API token used for higher rate limits and private repository access.\n * @default ''\n */\n token?: string;\n\n /**\n * Cache fetched repository and source data in memory for the current process.\n * @default true\n */\n cache?: boolean;\n\n /**\n * Cache TTL in milliseconds.\n * @default 3600000\n */\n cacheTTL?: number;\n\n /**\n * Maximum source file size to inline in bytes.\n * @default 200000\n */\n maxSourceBytes?: number;\n\n /**\n * Maximum source lines to inline when no line range is specified.\n * @default 120\n */\n maxSourceLines?: number;\n}\n\nexport const defaultOptions: Required<GitHubOptions> = {\n token: \"\",\n cache: true,\n cacheTTL: 3600000,\n maxSourceBytes: 200000,\n maxSourceLines: 120,\n};\n","import { Buffer } from \"node:buffer\";\nimport { inferLanguage, sourceKey } from \"./source\";\nimport {\n defaultOptions,\n type GitHubOptions,\n type GitHubRepoData,\n type GitHubSourceData,\n type GitHubSourceRef,\n} from \"./types\";\nimport { encodePath, isSafeGitHubPath, isSafeGitHubRef, isSafeGitHubRepo } from \"./validation\";\n\nconst repoCache = new Map<string, { data: GitHubRepoData; timestamp: number }>();\nconst sourceCache = new Map<string, { data: GitHubSourceData; timestamp: number }>();\n\ninterface GitHubContentApiFile {\n type: string;\n encoding?: string;\n content?: string;\n size?: number;\n html_url?: string;\n}\n\nfunction githubHeaders(options: Required<GitHubOptions>): Record<string, string> {\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 return headers;\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 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 response = await fetch(`https://api.github.com/repos/${repo}`, {\n headers: githubHeaders(options),\n });\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 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 * 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 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: githubHeaders(options) });\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 * 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","import type { Element } from \"hast\";\nimport { createGitHubPermalink, parseGitHubLineRange, parseGitHubPermalink } from \"./source\";\nimport type { GitHubSourceRef } from \"./types\";\nimport { isSafeGitHubPath, isSafeGitHubRef, isSafeGitHubRepo } from \"./validation\";\n\nconst GITHUB_COMPONENT_RE = /<github\\b([^>]*)>/gi;\nconst ATTRIBUTE_RE = /([:\\w-]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'>/]+)))?/g;\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\nexport function 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 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\nexport function 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","import type { Element } from \"hast\";\nimport { isSafeGitHubRepo } from \"./validation\";\n\n/**\n * Create fallback element when repo data is unavailable.\n */\nexport function 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","import type { Element } from \"hast\";\nimport type { GitHubRepoData } from \"./types\";\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\nfunction iconPath(d: string): Element {\n return {\n type: \"element\",\n tagName: \"svg\",\n properties: { viewBox: \"0 0 16 16\", fill: \"currentColor\" },\n children: [{ type: \"element\", tagName: \"path\", properties: { d }, children: [] }],\n };\n}\n\nfunction createStatsChildren(repoData: GitHubRepoData): Element[\"children\"] {\n const statsChildren: Element[\"children\"] = [];\n\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 statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n iconPath(\n \"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 { type: \"text\", value: formatNumber(repoData.stargazers_count) },\n ],\n });\n\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n iconPath(\n \"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 { type: \"text\", value: formatNumber(repoData.forks_count) },\n ],\n });\n\n return statsChildren;\n}\n\n/**\n * Create GitHub card element from repo data.\n */\nexport function createGitHubCard(repoData: GitHubRepoData): Element {\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 {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n ...iconPath(\n \"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 properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\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 ...(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 {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-stats\"] },\n children: createStatsChildren(repoData),\n },\n ],\n };\n}\n","import type { Element } from \"hast\";\nimport { formatLineRange } from \"./source\";\nimport type { GitHubLineRange, GitHubOptions, GitHubSourceData } from \"./types\";\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\nexport function 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: { className: languageClass },\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","import type { Element, Root } from \"hast\";\nimport rehypeParse from \"rehype-parse\";\nimport rehypeStringify from \"rehype-stringify\";\nimport { unified } from \"unified\";\nimport { prefetchGitHubRepos, prefetchGitHubSources } from \"./api\";\nimport {\n attributesFromElement,\n collectGitHubRepos,\n collectGitHubSources,\n sourceRefFromAttributes,\n} from \"./attributes\";\nimport { createFallbackCard } from \"./fallback-card\";\nimport { createGitHubCard } from \"./repo-card\";\nimport { sourceKey } from \"./source\";\nimport { createGitHubSourceCard } from \"./source-card\";\nimport {\n defaultOptions,\n type GitHubOptions,\n type GitHubRepoData,\n type GitHubSourceData,\n} from \"./types\";\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 continue;\n }\n\n if (child.tagName.toLowerCase() !== \"github\") {\n visit(child);\n continue;\n }\n\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 node.children[i] = repoData ? createGitHubCard(repoData) : createFallbackCard(repo);\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 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","export {\n fetchGitHubSource,\n fetchRepoData,\n prefetchGitHubRepos,\n prefetchGitHubSources,\n} from \"./github/api\";\nexport { collectGitHubRepos, collectGitHubSources } from \"./github/attributes\";\nexport { createGitHubPermalink, parseGitHubLineRange, parseGitHubPermalink } from \"./github/source\";\nexport { transformGitHub } from \"./github/transform\";\nexport type {\n GitHubLineRange,\n GitHubOptions,\n GitHubRepoData,\n GitHubSourceData,\n GitHubSourceRef,\n} from \"./github/types\";\nexport { isSafeGitHubRepo } from \"./github/validation\";\n"],"mappings":";;;;;;;;AAAA,MAAM,iBAAiB;AAEvB,SAAS,eAAe,OAAwB;CAC9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}
1
+ {"version":3,"file":"github.cjs","names":["Buffer","interopDefault","rehypeParsePlugin","rehypeStringifyPlugin"],"sources":["../src/plugins/github/validation.ts","../src/plugins/github/source.ts","../src/plugins/github/types.ts","../src/plugins/github/api.ts","../src/plugins/github/attributes.ts","../src/plugins/github/fallback-card.ts","../src/plugins/github/repo-card.ts","../src/plugins/github/source-card.ts","../src/plugins/github/transform.ts","../src/plugins/github.ts"],"sourcesContent":["const GITHUB_REPO_RE = /^[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+$/;\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\nexport function isSafeGitHubRef(ref: string): boolean {\n return Boolean(ref) && !hasControlChar(ref) && !hasUnsafePathSegment(ref);\n}\n\nexport function 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\nexport function encodePath(path: string): string {\n return path.split(\"/\").map(encodeURIComponent).join(\"/\");\n}\n","import type { GitHubLineRange, GitHubSourceRef } from \"./types\";\nimport { encodePath, isSafeGitHubPath, isSafeGitHubRef, isSafeGitHubRepo } from \"./validation\";\n\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\nexport function sourceKey(source: GitHubSourceRef): string {\n return `${source.repo}@${source.ref}:${source.path}`;\n}\n\nexport function 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\nexport function 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","export 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 /**\n * GitHub API token used for higher rate limits and private repository access.\n * @default ''\n */\n token?: string;\n\n /**\n * Cache fetched repository and source data in memory for the current process.\n * @default true\n */\n cache?: boolean;\n\n /**\n * Cache TTL in milliseconds.\n * @default 3600000\n */\n cacheTTL?: number;\n\n /**\n * Maximum source file size to inline in bytes.\n * @default 200000\n */\n maxSourceBytes?: number;\n\n /**\n * Maximum source lines to inline when no line range is specified.\n * @default 120\n */\n maxSourceLines?: number;\n}\n\nexport const defaultOptions: Required<GitHubOptions> = {\n token: \"\",\n cache: true,\n cacheTTL: 3600000,\n maxSourceBytes: 200000,\n maxSourceLines: 120,\n};\n","import { Buffer } from \"node:buffer\";\nimport { inferLanguage, sourceKey } from \"./source\";\nimport {\n defaultOptions,\n type GitHubOptions,\n type GitHubRepoData,\n type GitHubSourceData,\n type GitHubSourceRef,\n} from \"./types\";\nimport { encodePath, isSafeGitHubPath, isSafeGitHubRef, isSafeGitHubRepo } from \"./validation\";\n\nconst repoCache = new Map<string, { data: GitHubRepoData; timestamp: number }>();\nconst sourceCache = new Map<string, { data: GitHubSourceData; timestamp: number }>();\n\ninterface GitHubContentApiFile {\n type: string;\n encoding?: string;\n content?: string;\n size?: number;\n html_url?: string;\n}\n\nfunction githubHeaders(options: Required<GitHubOptions>): Record<string, string> {\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 return headers;\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 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 response = await fetch(`https://api.github.com/repos/${repo}`, {\n headers: githubHeaders(options),\n });\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 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 * 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 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: githubHeaders(options) });\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 * 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","import type { Element } from \"hast\";\nimport { createGitHubPermalink, parseGitHubLineRange, parseGitHubPermalink } from \"./source\";\nimport type { GitHubSourceRef } from \"./types\";\nimport { isSafeGitHubPath, isSafeGitHubRef, isSafeGitHubRepo } from \"./validation\";\n\nconst GITHUB_COMPONENT_RE = /<github\\b([^>]*)>/gi;\nconst ATTRIBUTE_RE = /([:\\w-]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'>/]+)))?/g;\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\nexport function 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 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\nexport function 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","import type { Element } from \"hast\";\nimport { isSafeGitHubRepo } from \"./validation\";\n\n/**\n * Create fallback element when repo data is unavailable.\n */\nexport function 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","import type { Element } from \"hast\";\nimport type { GitHubRepoData } from \"./types\";\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\nfunction iconPath(d: string): Element {\n return {\n type: \"element\",\n tagName: \"svg\",\n properties: { viewBox: \"0 0 16 16\", fill: \"currentColor\" },\n children: [{ type: \"element\", tagName: \"path\", properties: { d }, children: [] }],\n };\n}\n\nfunction createStatsChildren(repoData: GitHubRepoData): Element[\"children\"] {\n const statsChildren: Element[\"children\"] = [];\n\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 statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n iconPath(\n \"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 { type: \"text\", value: formatNumber(repoData.stargazers_count) },\n ],\n });\n\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n iconPath(\n \"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 { type: \"text\", value: formatNumber(repoData.forks_count) },\n ],\n });\n\n return statsChildren;\n}\n\n/**\n * Create GitHub card element from repo data.\n */\nexport function createGitHubCard(repoData: GitHubRepoData): Element {\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 {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n ...iconPath(\n \"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 properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\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 ...(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 {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-stats\"] },\n children: createStatsChildren(repoData),\n },\n ],\n };\n}\n","import type { Element } from \"hast\";\nimport { formatLineRange } from \"./source\";\nimport type { GitHubLineRange, GitHubOptions, GitHubSourceData } from \"./types\";\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\nexport function 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: { className: languageClass },\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","import type { Element, Root } from \"hast\";\nimport rehypeParsePlugin from \"rehype-parse\";\nimport rehypeStringifyPlugin from \"rehype-stringify\";\nimport { unified } from \"unified\";\nimport { interopDefault } from \"../../interop\";\nimport { prefetchGitHubRepos, prefetchGitHubSources } from \"./api\";\nimport {\n attributesFromElement,\n collectGitHubRepos,\n collectGitHubSources,\n sourceRefFromAttributes,\n} from \"./attributes\";\nimport { createFallbackCard } from \"./fallback-card\";\nimport { createGitHubCard } from \"./repo-card\";\nimport { sourceKey } from \"./source\";\nimport { createGitHubSourceCard } from \"./source-card\";\nimport {\n defaultOptions,\n type GitHubOptions,\n type GitHubRepoData,\n type GitHubSourceData,\n} from \"./types\";\n\n// ESM-only plugins are double-wrapped by the CommonJS interop; unwrap. See #452.\nconst rehypeParse = interopDefault(rehypeParsePlugin);\nconst rehypeStringify = interopDefault(rehypeStringifyPlugin);\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 continue;\n }\n\n if (child.tagName.toLowerCase() !== \"github\") {\n visit(child);\n continue;\n }\n\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 node.children[i] = repoData ? createGitHubCard(repoData) : createFallbackCard(repo);\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 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","export {\n fetchGitHubSource,\n fetchRepoData,\n prefetchGitHubRepos,\n prefetchGitHubSources,\n} from \"./github/api\";\nexport { collectGitHubRepos, collectGitHubSources } from \"./github/attributes\";\nexport { createGitHubPermalink, parseGitHubLineRange, parseGitHubPermalink } from \"./github/source\";\nexport { transformGitHub } from \"./github/transform\";\nexport type {\n GitHubLineRange,\n GitHubOptions,\n GitHubRepoData,\n GitHubSourceData,\n GitHubSourceRef,\n} from \"./github/types\";\nexport { isSafeGitHubRepo } from \"./github/validation\";\n"],"mappings":";;;;;;;;;AAAA,MAAM,iBAAiB;AAEvB,SAAS,eAAe,OAAwB;CAC9C,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS;EACjD,MAAM,OAAO,MAAM,WAAW,MAAM;EACpC,IAAI,QAAQ,MAAQ,SAAS,KAC3B,OAAO;;CAGX,OAAO;;AAGT,SAAgB,iBAAiB,MAAuB;CACtD,OACE,eAAe,KAAK,KAAK,IAAI,CAAC,KAAK,MAAM,IAAI,CAAC,MAAM,SAAS,SAAS,OAAO,SAAS,KAAK;;AAI/F,SAAgB,gBAAgB,KAAsB;CACpD,OAAO,QAAQ,IAAI,IAAI,CAAC,eAAe,IAAI,IAAI,CAAC,qBAAqB,IAAI;;AAG3E,SAAgB,iBAAiB,MAAuB;CACtD,OAAO,QAAQ,KAAK,IAAI,CAAC,eAAe,KAAK,IAAI,CAAC,qBAAqB,KAAK;;AAG9E,SAAS,qBAAqB,OAAwB;CACpD,OAAO,MACJ,MAAM,IAAI,CACV,MAAM,SAAS,CAAC,QAAQ,SAAS,OAAO,SAAS,QAAQ,KAAK,SAAS,KAAK,CAAC;;AAGlF,SAAgB,WAAW,MAAsB;CAC/C,OAAO,KAAK,MAAM,IAAI,CAAC,IAAI,mBAAmB,CAAC,KAAK,IAAI;;;;AC9B1D,MAAM,yBAAyB,IAAI,IAAoB;C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,IAAI,KAAK;KACtC,KAAK,SAAS,KAAK,WAAW,iBAAiB,SAAS,GAAG,mBAAmB,KAAK;;;;EAM3F,MAAM,KAAK;;;;;;AAOf,eAAsB,gBACpB,MACA,aACA,SACiB;CACjB,MAAM,gBAAgB;EAAE,GAAG;EAAgB,GAAG;EAAS;CACvD,IAAI,UAAU;CACd,IAAI,CAAC,SAEH,UAAU,MAAM,oBAAoB,MADhB,mBAAmB,KAAK,EACD,cAAc;CAG3D,MAAM,gBAAgB,MAAM,sBAAsB,MAD5B,qBAAqB,KAAK,EACW,cAAc;CAEzE,MAAM,SAAS,OAAA,GAAA,QAAA,UAAe,CAC3B,IAAI,aAAa,EAAE,UAAU,MAAM,CAAC,CACpC,IAAI,cAAc,SAAS,eAAe,cAAc,CACxD,IAAI,gBAAgB,CACpB,QAAQ,KAAK;CAEhB,OAAO,OAAO,OAAO"}
package/dist/github.mjs CHANGED
@@ -1,6 +1,7 @@
1
+ import { t as interopDefault } from "./interop.mjs";
1
2
  import { unified } from "unified";
2
- import rehypeParse from "rehype-parse";
3
- import rehypeStringify from "rehype-stringify";
3
+ import rehypeParsePlugin from "rehype-parse";
4
+ import rehypeStringifyPlugin from "rehype-stringify";
4
5
  import { Buffer } from "node:buffer";
5
6
  //#region src/plugins/github/validation.ts
6
7
  const GITHUB_REPO_RE = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
@@ -572,6 +573,8 @@ function createGitHubSourceCard(source, lines, options) {
572
573
  }
573
574
  //#endregion
574
575
  //#region src/plugins/github/transform.ts
576
+ const rehypeParse = interopDefault(rehypeParsePlugin);
577
+ const rehypeStringify = interopDefault(rehypeStringifyPlugin);
575
578
  /**
576
579
  * Rehype plugin to transform GitHub components.
577
580
  */
@@ -1 +1 @@
1
- {"version":3,"file":"github.mjs","names":[],"sources":["../src/plugins/github/validation.ts","../src/plugins/github/source.ts","../src/plugins/github/types.ts","../src/plugins/github/api.ts","../src/plugins/github/attributes.ts","../src/plugins/github/fallback-card.ts","../src/plugins/github/repo-card.ts","../src/plugins/github/source-card.ts","../src/plugins/github/transform.ts"],"sourcesContent":["const GITHUB_REPO_RE = /^[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+$/;\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\nexport function isSafeGitHubRef(ref: string): boolean {\n return Boolean(ref) && !hasControlChar(ref) && !hasUnsafePathSegment(ref);\n}\n\nexport function 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\nexport function encodePath(path: string): string {\n return path.split(\"/\").map(encodeURIComponent).join(\"/\");\n}\n","import type { GitHubLineRange, GitHubSourceRef } from \"./types\";\nimport { encodePath, isSafeGitHubPath, isSafeGitHubRef, isSafeGitHubRepo } from \"./validation\";\n\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\nexport function sourceKey(source: GitHubSourceRef): string {\n return `${source.repo}@${source.ref}:${source.path}`;\n}\n\nexport function 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\nexport function 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","export 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 /**\n * GitHub API token used for higher rate limits and private repository access.\n * @default ''\n */\n token?: string;\n\n /**\n * Cache fetched repository and source data in memory for the current process.\n * @default true\n */\n cache?: boolean;\n\n /**\n * Cache TTL in milliseconds.\n * @default 3600000\n */\n cacheTTL?: number;\n\n /**\n * Maximum source file size to inline in bytes.\n * @default 200000\n */\n maxSourceBytes?: number;\n\n /**\n * Maximum source lines to inline when no line range is specified.\n * @default 120\n */\n maxSourceLines?: number;\n}\n\nexport const defaultOptions: Required<GitHubOptions> = {\n token: \"\",\n cache: true,\n cacheTTL: 3600000,\n maxSourceBytes: 200000,\n maxSourceLines: 120,\n};\n","import { Buffer } from \"node:buffer\";\nimport { inferLanguage, sourceKey } from \"./source\";\nimport {\n defaultOptions,\n type GitHubOptions,\n type GitHubRepoData,\n type GitHubSourceData,\n type GitHubSourceRef,\n} from \"./types\";\nimport { encodePath, isSafeGitHubPath, isSafeGitHubRef, isSafeGitHubRepo } from \"./validation\";\n\nconst repoCache = new Map<string, { data: GitHubRepoData; timestamp: number }>();\nconst sourceCache = new Map<string, { data: GitHubSourceData; timestamp: number }>();\n\ninterface GitHubContentApiFile {\n type: string;\n encoding?: string;\n content?: string;\n size?: number;\n html_url?: string;\n}\n\nfunction githubHeaders(options: Required<GitHubOptions>): Record<string, string> {\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 return headers;\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 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 response = await fetch(`https://api.github.com/repos/${repo}`, {\n headers: githubHeaders(options),\n });\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 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 * 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 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: githubHeaders(options) });\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 * 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","import type { Element } from \"hast\";\nimport { createGitHubPermalink, parseGitHubLineRange, parseGitHubPermalink } from \"./source\";\nimport type { GitHubSourceRef } from \"./types\";\nimport { isSafeGitHubPath, isSafeGitHubRef, isSafeGitHubRepo } from \"./validation\";\n\nconst GITHUB_COMPONENT_RE = /<github\\b([^>]*)>/gi;\nconst ATTRIBUTE_RE = /([:\\w-]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'>/]+)))?/g;\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\nexport function 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 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\nexport function 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","import type { Element } from \"hast\";\nimport { isSafeGitHubRepo } from \"./validation\";\n\n/**\n * Create fallback element when repo data is unavailable.\n */\nexport function 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","import type { Element } from \"hast\";\nimport type { GitHubRepoData } from \"./types\";\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\nfunction iconPath(d: string): Element {\n return {\n type: \"element\",\n tagName: \"svg\",\n properties: { viewBox: \"0 0 16 16\", fill: \"currentColor\" },\n children: [{ type: \"element\", tagName: \"path\", properties: { d }, children: [] }],\n };\n}\n\nfunction createStatsChildren(repoData: GitHubRepoData): Element[\"children\"] {\n const statsChildren: Element[\"children\"] = [];\n\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 statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n iconPath(\n \"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 { type: \"text\", value: formatNumber(repoData.stargazers_count) },\n ],\n });\n\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n iconPath(\n \"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 { type: \"text\", value: formatNumber(repoData.forks_count) },\n ],\n });\n\n return statsChildren;\n}\n\n/**\n * Create GitHub card element from repo data.\n */\nexport function createGitHubCard(repoData: GitHubRepoData): Element {\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 {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n ...iconPath(\n \"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 properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\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 ...(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 {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-stats\"] },\n children: createStatsChildren(repoData),\n },\n ],\n };\n}\n","import type { Element } from \"hast\";\nimport { formatLineRange } from \"./source\";\nimport type { GitHubLineRange, GitHubOptions, GitHubSourceData } from \"./types\";\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\nexport function 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: { className: languageClass },\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","import type { Element, Root } from \"hast\";\nimport rehypeParse from \"rehype-parse\";\nimport rehypeStringify from \"rehype-stringify\";\nimport { unified } from \"unified\";\nimport { prefetchGitHubRepos, prefetchGitHubSources } from \"./api\";\nimport {\n attributesFromElement,\n collectGitHubRepos,\n collectGitHubSources,\n sourceRefFromAttributes,\n} from \"./attributes\";\nimport { createFallbackCard } from \"./fallback-card\";\nimport { createGitHubCard } from \"./repo-card\";\nimport { sourceKey } from \"./source\";\nimport { createGitHubSourceCard } from \"./source-card\";\nimport {\n defaultOptions,\n type GitHubOptions,\n type GitHubRepoData,\n type GitHubSourceData,\n} from \"./types\";\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 continue;\n }\n\n if (child.tagName.toLowerCase() !== \"github\") {\n visit(child);\n continue;\n }\n\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 node.children[i] = repoData ? createGitHubCard(repoData) : createFallbackCard(repo);\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 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":";;;;;AAAA,MAAM,iBAAiB;AAEvB,SAAS,eAAe,OAAwB;CAC9C,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS;EACjD,MAAM,OAAO,MAAM,WAAW,MAAM;EACpC,IAAI,QAAQ,MAAQ,SAAS,KAC3B,OAAO;;CAGX,OAAO;;AAGT,SAAgB,iBAAiB,MAAuB;CACtD,OACE,eAAe,KAAK,KAAK,IAAI,CAA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;IAC7C,MAAM,QAAQ,KAAK,SAAS;IAE5B,IAAI,MAAM,SAAS,WACjB;IAGF,IAAI,MAAM,QAAQ,aAAa,KAAK,UAAU;KAC5C,MAAM,MAAM;KACZ;;IAGF,MAAM,QAAQ,sBAAsB,MAAM;IAC1C,MAAM,SAAS,wBAAwB,MAAM;IAE7C,IAAI,QAAQ;KACV,MAAM,aAAa,cAAc,IAAI,UAAU,OAAO,CAAC;KACvD,KAAK,SAAS,KAAK,aACf,uBAAuB,YAAY,OAAO,OAAO,QAAQ,GACzD,mBAAmB,OAAO,UAAU;KACxC;;IAGF,MAAM,OAAO,MAAM;IACnB,IAAI,MAAM;KACR,MAAM,WAAW,YAAY,IAAI,KAAK;KACtC,KAAK,SAAS,KAAK,WAAW,iBAAiB,SAAS,GAAG,mBAAmB,KAAK;;;;EAM3F,MAAM,KAAK;;;;;;AAOf,eAAsB,gBACpB,MACA,aACA,SACiB;CACjB,MAAM,gBAAgB;EAAE,GAAG;EAAgB,GAAG;EAAS;CACvD,IAAI,UAAU;CACd,IAAI,CAAC,SAEH,UAAU,MAAM,oBAAoB,MADhB,mBAAmB,KAAK,EACD,cAAc;CAG3D,MAAM,gBAAgB,MAAM,sBAAsB,MAD5B,qBAAqB,KAAK,EACW,cAAc;CAEzE,MAAM,SAAS,MAAM,SAAS,CAC3B,IAAI,aAAa,EAAE,UAAU,MAAM,CAAC,CACpC,IAAI,cAAc,SAAS,eAAe,cAAc,CACxD,IAAI,gBAAgB,CACpB,QAAQ,KAAK;CAEhB,OAAO,OAAO,OAAO"}
1
+ {"version":3,"file":"github.mjs","names":[],"sources":["../src/plugins/github/validation.ts","../src/plugins/github/source.ts","../src/plugins/github/types.ts","../src/plugins/github/api.ts","../src/plugins/github/attributes.ts","../src/plugins/github/fallback-card.ts","../src/plugins/github/repo-card.ts","../src/plugins/github/source-card.ts","../src/plugins/github/transform.ts"],"sourcesContent":["const GITHUB_REPO_RE = /^[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+$/;\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\nexport function isSafeGitHubRef(ref: string): boolean {\n return Boolean(ref) && !hasControlChar(ref) && !hasUnsafePathSegment(ref);\n}\n\nexport function 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\nexport function encodePath(path: string): string {\n return path.split(\"/\").map(encodeURIComponent).join(\"/\");\n}\n","import type { GitHubLineRange, GitHubSourceRef } from \"./types\";\nimport { encodePath, isSafeGitHubPath, isSafeGitHubRef, isSafeGitHubRepo } from \"./validation\";\n\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\nexport function sourceKey(source: GitHubSourceRef): string {\n return `${source.repo}@${source.ref}:${source.path}`;\n}\n\nexport function 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\nexport function 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","export 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 /**\n * GitHub API token used for higher rate limits and private repository access.\n * @default ''\n */\n token?: string;\n\n /**\n * Cache fetched repository and source data in memory for the current process.\n * @default true\n */\n cache?: boolean;\n\n /**\n * Cache TTL in milliseconds.\n * @default 3600000\n */\n cacheTTL?: number;\n\n /**\n * Maximum source file size to inline in bytes.\n * @default 200000\n */\n maxSourceBytes?: number;\n\n /**\n * Maximum source lines to inline when no line range is specified.\n * @default 120\n */\n maxSourceLines?: number;\n}\n\nexport const defaultOptions: Required<GitHubOptions> = {\n token: \"\",\n cache: true,\n cacheTTL: 3600000,\n maxSourceBytes: 200000,\n maxSourceLines: 120,\n};\n","import { Buffer } from \"node:buffer\";\nimport { inferLanguage, sourceKey } from \"./source\";\nimport {\n defaultOptions,\n type GitHubOptions,\n type GitHubRepoData,\n type GitHubSourceData,\n type GitHubSourceRef,\n} from \"./types\";\nimport { encodePath, isSafeGitHubPath, isSafeGitHubRef, isSafeGitHubRepo } from \"./validation\";\n\nconst repoCache = new Map<string, { data: GitHubRepoData; timestamp: number }>();\nconst sourceCache = new Map<string, { data: GitHubSourceData; timestamp: number }>();\n\ninterface GitHubContentApiFile {\n type: string;\n encoding?: string;\n content?: string;\n size?: number;\n html_url?: string;\n}\n\nfunction githubHeaders(options: Required<GitHubOptions>): Record<string, string> {\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 return headers;\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 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 response = await fetch(`https://api.github.com/repos/${repo}`, {\n headers: githubHeaders(options),\n });\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 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 * 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 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: githubHeaders(options) });\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 * 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","import type { Element } from \"hast\";\nimport { createGitHubPermalink, parseGitHubLineRange, parseGitHubPermalink } from \"./source\";\nimport type { GitHubSourceRef } from \"./types\";\nimport { isSafeGitHubPath, isSafeGitHubRef, isSafeGitHubRepo } from \"./validation\";\n\nconst GITHUB_COMPONENT_RE = /<github\\b([^>]*)>/gi;\nconst ATTRIBUTE_RE = /([:\\w-]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'>/]+)))?/g;\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\nexport function 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 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\nexport function 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","import type { Element } from \"hast\";\nimport { isSafeGitHubRepo } from \"./validation\";\n\n/**\n * Create fallback element when repo data is unavailable.\n */\nexport function 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","import type { Element } from \"hast\";\nimport type { GitHubRepoData } from \"./types\";\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\nfunction iconPath(d: string): Element {\n return {\n type: \"element\",\n tagName: \"svg\",\n properties: { viewBox: \"0 0 16 16\", fill: \"currentColor\" },\n children: [{ type: \"element\", tagName: \"path\", properties: { d }, children: [] }],\n };\n}\n\nfunction createStatsChildren(repoData: GitHubRepoData): Element[\"children\"] {\n const statsChildren: Element[\"children\"] = [];\n\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 statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n iconPath(\n \"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 { type: \"text\", value: formatNumber(repoData.stargazers_count) },\n ],\n });\n\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n iconPath(\n \"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 { type: \"text\", value: formatNumber(repoData.forks_count) },\n ],\n });\n\n return statsChildren;\n}\n\n/**\n * Create GitHub card element from repo data.\n */\nexport function createGitHubCard(repoData: GitHubRepoData): Element {\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 {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n ...iconPath(\n \"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 properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\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 ...(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 {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-stats\"] },\n children: createStatsChildren(repoData),\n },\n ],\n };\n}\n","import type { Element } from \"hast\";\nimport { formatLineRange } from \"./source\";\nimport type { GitHubLineRange, GitHubOptions, GitHubSourceData } from \"./types\";\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\nexport function 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: { className: languageClass },\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","import type { Element, Root } from \"hast\";\nimport rehypeParsePlugin from \"rehype-parse\";\nimport rehypeStringifyPlugin from \"rehype-stringify\";\nimport { unified } from \"unified\";\nimport { interopDefault } from \"../../interop\";\nimport { prefetchGitHubRepos, prefetchGitHubSources } from \"./api\";\nimport {\n attributesFromElement,\n collectGitHubRepos,\n collectGitHubSources,\n sourceRefFromAttributes,\n} from \"./attributes\";\nimport { createFallbackCard } from \"./fallback-card\";\nimport { createGitHubCard } from \"./repo-card\";\nimport { sourceKey } from \"./source\";\nimport { createGitHubSourceCard } from \"./source-card\";\nimport {\n defaultOptions,\n type GitHubOptions,\n type GitHubRepoData,\n type GitHubSourceData,\n} from \"./types\";\n\n// ESM-only plugins are double-wrapped by the CommonJS interop; unwrap. See #452.\nconst rehypeParse = interopDefault(rehypeParsePlugin);\nconst rehypeStringify = interopDefault(rehypeStringifyPlugin);\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 continue;\n }\n\n if (child.tagName.toLowerCase() !== \"github\") {\n visit(child);\n continue;\n }\n\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 node.children[i] = repoData ? createGitHubCard(repoData) : createFallbackCard(repo);\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 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":";;;;;;AAAA,MAAM,iBAAiB;AAEvB,SAAS,eAAe,OAAwB;CAC9C,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SAAS;EACjD,MAAM,OAAO,MAAM,WAAW,MAAM;EACpC,IAAI,QAAQ,MAAQ,SAAS,KAC3B,OAAO;;CAGX,OAAO;;AAGT,SAAgB,iBAAiB,MAAuB;CACtD,OACE,eAAe,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AS,SAAyB;GACtC,IAAI,cAAc,MAChB,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,SAAS,QAAQ,KAAK;IAC7C,MAAM,QAAQ,KAAK,SAAS;IAE5B,IAAI,MAAM,SAAS,WACjB;IAGF,IAAI,MAAM,QAAQ,aAAa,KAAK,UAAU;KAC5C,MAAM,MAAM;KACZ;;IAGF,MAAM,QAAQ,sBAAsB,MAAM;IAC1C,MAAM,SAAS,wBAAwB,MAAM;IAE7C,IAAI,QAAQ;KACV,MAAM,aAAa,cAAc,IAAI,UAAU,OAAO,CAAC;KACvD,KAAK,SAAS,KAAK,aACf,uBAAuB,YAAY,OAAO,OAAO,QAAQ,GACzD,mBAAmB,OAAO,UAAU;KACxC;;IAGF,MAAM,OAAO,MAAM;IACnB,IAAI,MAAM;KACR,MAAM,WAAW,YAAY,IAAI,KAAK;KACtC,KAAK,SAAS,KAAK,WAAW,iBAAiB,SAAS,GAAG,mBAAmB,KAAK;;;;EAM3F,MAAM,KAAK;;;;;;AAOf,eAAsB,gBACpB,MACA,aACA,SACiB;CACjB,MAAM,gBAAgB;EAAE,GAAG;EAAgB,GAAG;EAAS;CACvD,IAAI,UAAU;CACd,IAAI,CAAC,SAEH,UAAU,MAAM,oBAAoB,MADhB,mBAAmB,KAAK,EACD,cAAc;CAG3D,MAAM,gBAAgB,MAAM,sBAAsB,MAD5B,qBAAqB,KAAK,EACW,cAAc;CAEzE,MAAM,SAAS,MAAM,SAAS,CAC3B,IAAI,aAAa,EAAE,UAAU,MAAM,CAAC,CACpC,IAAI,cAAc,SAAS,eAAe,cAAc,CACxD,IAAI,gBAAgB,CACpB,QAAQ,KAAK;CAEhB,OAAO,OAAO,OAAO"}
package/dist/index.cjs CHANGED
@@ -1,5 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("./chunk.cjs");
3
+ const require_interop = require("./interop.cjs");
3
4
  const require_napi = require("./napi.cjs");
4
5
  const require_mermaid = require("./mermaid.cjs");
5
6
  const require_tabs = require("./tabs.cjs");
@@ -117,6 +118,8 @@ function createMarkdownEnvironment(options) {
117
118
  /**
118
119
  * Syntax highlighting with Shiki via rehype.
119
120
  */
121
+ const rehypeParse$1 = require_interop.interopDefault(rehype_parse.default);
122
+ const rehypeStringify$1 = require_interop.interopDefault(rehype_stringify.default);
120
123
  const BUILTIN_LANGS = [
121
124
  "javascript",
122
125
  "typescript",
@@ -195,7 +198,7 @@ function rehypeShikiHighlight(options) {
195
198
  lang,
196
199
  theme: themeName
197
200
  });
198
- const parsed = (0, unified.unified)().use(rehype_parse.default, { fragment: true }).parse(highlighted);
201
+ const parsed = (0, unified.unified)().use(rehypeParse$1, { fragment: true }).parse(highlighted);
199
202
  if (parsed.children[0]?.type === "element") {
200
203
  const highlightedPre = parsed.children[0];
201
204
  highlightedPre.properties ??= {};
@@ -217,7 +220,7 @@ function rehypeShikiHighlight(options) {
217
220
  lang,
218
221
  theme: themeName
219
222
  });
220
- const parsed = (0, unified.unified)().use(rehype_parse.default, { fragment: true }).parse(highlighted);
223
+ const parsed = (0, unified.unified)().use(rehypeParse$1, { fragment: true }).parse(highlighted);
221
224
  if (parsed.children[0]?.type === "element") {
222
225
  const highlightedCode = parsed.children[0].children.find((child) => child.type === "element" && child.tagName === "code");
223
226
  if (highlightedCode) {
@@ -273,10 +276,10 @@ function normalizeClassName(className) {
273
276
  * Apply syntax highlighting to HTML using Shiki.
274
277
  */
275
278
  async function highlightCode(html, theme = "github-dark", langs = []) {
276
- const result = await (0, unified.unified)().use(rehype_parse.default, { fragment: true }).use(rehypeShikiHighlight, {
279
+ const result = await (0, unified.unified)().use(rehypeParse$1, { fragment: true }).use(rehypeShikiHighlight, {
277
280
  theme,
278
281
  langs
279
- }).use(rehype_stringify.default).process(html);
282
+ }).use(rehypeStringify$1).process(html);
280
283
  return String(result);
281
284
  }
282
285
  //#endregion
@@ -1667,6 +1670,8 @@ async function renderSinglePage(entry, templateFn, templateSource, options, cach
1667
1670
  * Detects <Island> components in HTML and transforms them
1668
1671
  * into hydration-ready elements with data attributes.
1669
1672
  */
1673
+ const rehypeParse = require_interop.interopDefault(rehype_parse.default);
1674
+ const rehypeStringify = require_interop.interopDefault(rehype_stringify.default);
1670
1675
  /**
1671
1676
  * Get element attribute value.
1672
1677
  */
@@ -1797,7 +1802,7 @@ function rehypeIslands(collectedIslands) {
1797
1802
  */
1798
1803
  async function transformIslands(html) {
1799
1804
  const islands = [];
1800
- const result = await (0, unified.unified)().use(rehype_parse.default, { fragment: true }).use(rehypeIslands, islands).use(rehype_stringify.default).process(html);
1805
+ const result = await (0, unified.unified)().use(rehypeParse, { fragment: true }).use(rehypeIslands, islands).use(rehypeStringify).process(html);
1801
1806
  return {
1802
1807
  html: String(result),
1803
1808
  islands