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 { Copy, Check } from "lucide-react";
import { KinescopePlayer } from "@/components/player/kinescope-player"; import { KinescopePlayer } from "@/components/player/kinescope-player";
function CodeBlockStudentView({ function CodeBlockStudentView({ node }: { node: { textContent: string } }) {
node,
}: {
node: { textContent: string; attrs: Record<string, unknown> };
}) {
const [copied, setCopied] = useState(false); const [copied, setCopied] = useState(false);
const handleCopy = async () => { const handleCopy = async () => {
const lang = (node.attrs?.language as string) || ""; // WYSIWYG: копируем содержимое блока ровно как показано. Для Obsidian-сниппетов
// Для блоков с языком (dataview/query/mermaid) копируем ПОЛНЫЙ markdown-забор — // (dataview/query) забор ```...``` хранится прямо в содержимом → копируется целиком.
// студент вставляет рабочий блок в Obsidian. Для блоков без языка — как есть.
const payload = lang
? "```" + lang + "\n" + node.textContent + "\n```"
: node.textContent;
try { try {
await navigator.clipboard.writeText(payload); await navigator.clipboard.writeText(node.textContent);
setCopied(true); setCopied(true);
setTimeout(() => setCopied(false), 1500); setTimeout(() => setCopied(false), 1500);
} catch { } catch {