Copy code block verbatim (fences live in content for Obsidian snippets)

This commit is contained in:
2026-06-03 15:34:15 +05:00
parent ecbca89cef
commit ecf48de7e8
+4 -12
View File
@@ -11,22 +11,14 @@ 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; attrs: Record<string, unknown> };
}) {
function CodeBlockStudentView({ node }: { node: { textContent: string } }) {
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;
// WYSIWYG: копируем содержимое блока ровно как показано. Для Obsidian-сниппетов
// (dataview/query) забор ```...``` хранится прямо в содержимом → копируется целиком.
try {
await navigator.clipboard.writeText(payload);
await navigator.clipboard.writeText(node.textContent);
setCopied(true);
setTimeout(() => setCopied(false), 1500);
} catch {