-
{entries.map(({ key, value }, index) => (
- {key}
-
{key === "memory_tags" && DemoTags ? (
) : ( value )}
import { useMemo } from "react";
import dynamic from "next/dynamic";
import { IS_DEMO } from "../studio-mode";
import WorkspaceMarkdown from "./WorkspaceMarkdown";
const DemoTags = IS_DEMO
? dynamic(() => import("../../demo/DemoTags"), { ssr: false })
: null;
import { parseMarkdownFrontmatter } from "./markdown";
import styles from "./files-workspace.module.css";
export type PreviewType = "markdown" | "csv" | "text";
export function getPreviewType(filePath: string): PreviewType {
const ext = filePath.split(".").pop()?.toLowerCase() ?? "";
if (ext === "md" || ext === "mdx") return "markdown";
if (ext === "csv") return "csv";
return "text";
}
function parseCsv(raw: string): string[][] {
return raw
.trimEnd()
.split(/\r?\n/)
.map((line) => {
const cells: string[] = [];
let current = "";
let quoted = false;
for (let index = 0; index < line.length; index += 1) {
const char = line[index];
if (char === '"') {
if (quoted && line[index + 1] === '"') {
current += '"';
index += 1;
} else quoted = !quoted;
} else if (char === "," && !quoted) {
cells.push(current);
current = "";
} else current += char;
}
cells.push(current);
return cells;
});
}
function MarkdownPreview({ content }: { content: string }) {
const { body, entries } = useMemo(
() => parseMarkdownFrontmatter(content),
[content],
);
return (
{entries.map(({ key, value }, index) => (
)}
| {cell} | ))}
|---|
| {cell} | ))}
{content};
}