fix(webui): persist markdown video previews
This commit is contained in:
@@ -8,6 +8,7 @@ import remarkMath from "remark-math";
|
||||
|
||||
import { CodeBlock } from "@/components/CodeBlock";
|
||||
import { FileReferenceChip, isLikelyFilePath } from "@/components/FileReferenceChip";
|
||||
import { inferMediaKind } from "@/lib/media";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
import "katex/dist/katex.min.css";
|
||||
@@ -114,6 +115,29 @@ export default function MarkdownTextRenderer({
|
||||
const source = typeof src === "string" ? src : "";
|
||||
if (!source) return null;
|
||||
const label = typeof alt === "string" ? alt : "";
|
||||
if (inferMediaKind({ url: source, name: label }) === "video") {
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
"not-prose my-3 block w-fit max-w-full overflow-hidden rounded-[14px]",
|
||||
"border border-border/70 bg-background shadow-sm",
|
||||
)}
|
||||
>
|
||||
<video
|
||||
src={source}
|
||||
controls
|
||||
preload="metadata"
|
||||
className="block max-h-[26rem] max-w-full bg-black"
|
||||
aria-label={label ? `Video attachment: ${label}` : "Video attachment"}
|
||||
/>
|
||||
{label ? (
|
||||
<span className="block max-w-full truncate px-3 py-2 text-xs text-muted-foreground">
|
||||
{label}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<span
|
||||
className={cn(
|
||||
|
||||
@@ -15,4 +15,14 @@ describe("MarkdownTextRenderer", () => {
|
||||
);
|
||||
expect(screen.getByText("Diagram")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("renders markdown videos as inline players", () => {
|
||||
render(<MarkdownTextRenderer></MarkdownTextRenderer>);
|
||||
|
||||
const video = screen.getByLabelText("Video attachment: nanobot-intro.mp4");
|
||||
expect(video.tagName).toBe("VIDEO");
|
||||
expect(video).toHaveAttribute("src", "/api/media/sig/video");
|
||||
expect(video).toHaveAttribute("controls");
|
||||
expect(screen.queryByRole("img", { name: "nanobot-intro.mp4" })).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user