]*>([\s\S]*?)<\/code>/gi, "`$1`")
.replace(/]*>([\s\S]*?)<\/sub>/gi, "$1")
.replace(/]*>([\s\S]*?)<\/span>/gi, "$1")
.replace(/<[^>]+>/g, "")
.trim();
}
function normalizeReadmeMarkdown(content: string) {
return content
.replace(
/]*>([\s\S]*?)<\/h\1>/gi,
(_match, depth: string, value: string) =>
`${"#".repeat(Number(depth))} ${htmlInlineToMarkdown(value)}\n\n`,
)
.replace(
/]*>([\s\S]*?)<\/p>/gi,
(_match, value: string) => `${htmlInlineToMarkdown(value)}\n\n`,
)
.replace(
/
]*>([\s\S]*?)<\/div>/gi,
(_match, value: string) => `${htmlInlineToMarkdown(value)}\n\n`,
)
.replace(
/]*>([\s\S]*?)<\/center>/gi,
(_match, value: string) => `${htmlInlineToMarkdown(value)}\n\n`,
)
.replace(/\n{3,}/g, "\n\n")
.trim();
}
export function ReadmePanel({
accessChannelId,
file,
gitDataState,
externalHost,
externalUrl,
hideHeader,
ownerAvatarUrl,
ownerIsAgent,
ownerName,
sourceControls,
unavailableReason,
}: {
/** `buzz-channel` binding of the repository, for access-restricted copy. */
accessChannelId?: string | null;
file: ProjectRepoFile | null;
gitDataState: "checking" | "available" | "empty" | "unavailable";
externalHost?: string;
externalUrl?: string | null;
/**
* Skip the header rows entirely — the workspace layout renders the source
* controls and last-changed timestamp itself.
*/
hideHeader?: boolean;
ownerAvatarUrl?: string | null;
ownerIsAgent?: boolean;
ownerName?: string;
unavailableReason?: ProjectRepoUnavailableReason;
/** Branch picker + remote/local toggle rendered in the panel header. */
sourceControls?: RepoSourceHeaderControls;
}) {
const externalOpenUrl = projectExternalRefUrl(
externalUrl,
sourceControls?.selectedTag ?? sourceControls?.branch,
);
// Two header rows, mirroring the files panel: controls on top, then the
// file identity row.
const header = hideHeader ? null : (
<>
{sourceControls ? (
) : null}
{file ? baseName(file.path) : "README"}
{file ? (
Last changed {formatLastChangedAt(file.lastChangedAt)}
) : null}
>
);
if (gitDataState === "checking") {
return (
{header}
);
}
if (gitDataState === "unavailable") {
if (!externalHost) {
return (
);
}
return (
{externalHost === "github.com" ? (
) : (
)}
Code hosted on {externalHost}
Clone this repository locally to explore its files, commits, and
contributors in Buzz.
{externalOpenUrl ? (
{externalOpenUrl}
) : null}
{sourceControls?.onCloneLocal ? (
) : null}
{externalOpenUrl ? (
) : null}
);
}
if (!file?.previewContent) {
return (
{header}
{gitDataState === "empty"
? "No files have been pushed to this repository yet."
: "Add a README to this repository to describe setup, usage, and project context."}
);
}
const language = languageForPath(file.path);
const isMarkdown = /\.(?:md|markdown|mdx)$/i.test(file.path);
const readmeContent = isMarkdown
? normalizeReadmeMarkdown(file.previewContent)
: file.previewContent;
return (
{header}
{isMarkdown ? (
) : language ? (
) : (
{file.previewContent}
)}
);
}