Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/slate/elements/meta/editable.tsx
1702 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
/*
7
8
YAML metadata node, e.g., at the VERY top like this:
9
10
---
11
title: HW02
12
subtitle: Basic Rmd and Statistics
13
output:
14
html_document:
15
theme: spacelab
16
highlight: tango
17
toc: true
18
---
19
20
21
*/
22
23
import { register } from "../register";
24
import { useSlate } from "../hooks";
25
import { A } from "@cocalc/frontend/components";
26
import { useSetElement } from "../set-element";
27
import { SlateCodeMirror } from "../codemirror";
28
29
register({
30
slateType: "meta",
31
32
Element: ({ attributes, children, element }) => {
33
if (element.type != "meta") throw Error("bug");
34
const editor = useSlate();
35
const setElement = useSetElement(editor, element);
36
37
return (
38
<div {...attributes}>
39
<div contentEditable={false}>
40
<span style={{ float: "right" }}>
41
<A href="https://docs.ansible.com/ansible/latest/reference_appendices/YAMLSyntax.html">
42
YAML
43
</A>{" "}
44
Header
45
</span>
46
<code>---</code>
47
<SlateCodeMirror
48
style={{ marginBottom: 0 }}
49
info="yml"
50
options={{ lineWrapping: true }}
51
value={element.value}
52
onChange={(value) => {
53
setElement({ value });
54
}}
55
/>
56
<code>---</code>
57
</div>
58
{children}
59
</div>
60
);
61
},
62
63
fromSlate: ({ node }) => `---\n${node.value}\n---\n`,
64
});
65
66