Copy full markdown fence for language-tagged code blocks (dataview/query)

This commit is contained in:
2026-06-03 15:23:27 +05:00
parent cf942d223e
commit ecbca89cef
+12 -2
View File
@@ -11,12 +11,22 @@ import Underline from "@tiptap/extension-underline";
import { Copy, Check } from "lucide-react";
import { KinescopePlayer } from "@/components/player/kinescope-player";
function CodeBlockStudentView({ node }: { node: { textContent: string } }) {
function CodeBlockStudentView({
node,
}: {
node: { textContent: string; attrs: Record<string, unknown> };
}) {
const [copied, setCopied] = useState(false);
const handleCopy = async () => {
const lang = (node.attrs?.language as string) || "";
// Для блоков с языком (dataview/query/mermaid) копируем ПОЛНЫЙ markdown-забор —
// студент вставляет рабочий блок в Obsidian. Для блоков без языка — как есть.
const payload = lang
? "```" + lang + "\n" + node.textContent + "\n```"
: node.textContent;
try {
await navigator.clipboard.writeText(node.textContent);
await navigator.clipboard.writeText(payload);
setCopied(true);
setTimeout(() => setCopied(false), 1500);
} catch {