"use client";
import React, { createContext, useContext } from "react";
import ReactMarkdown from "react-markdown";
import type { Components } from "react-markdown";
import type { Element } from "hast";
// Lets the `code` renderer know it's inside a `pre` block vs. inline.
// React renders parent-to-child, so the Provider in `pre` is active
// when `code` renders inside it.
const InsidePreContext = createContext(false);
function GoldDot() {
return (
);
}
function BlueDot() {
return (
);
}
function KeyBadge({ children }: { children: React.ReactNode }) {
return (
{children}
);
}
// Extracts plain text from a HAST element's text children,
// stripping a trailing colon (e.g. "Backend:" → "Backend").
function extractHastText(node: Element): string {
return (node.children ?? [])
.filter((c): c is { type: "text"; value: string } => c.type === "text")
.map((c) => c.value)
.join("")
.replace(/:$/, "")
.trim();
}
function CodeRenderer({ children }: { children?: React.ReactNode }) {
const insidePre = useContext(InsidePreContext);
if (insidePre) {
return (
{children}
);
}
return (
{children}
);
}
const components: Components = {
h1: ({ children }) => (
{children}
), ul: ({ children }) => (
{children}