Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/editors/slate/elements/meta/index.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 { CodeMirrorStatic } from "@cocalc/frontend/jupyter/codemirror-static";
24
import { register } from "../register";
25
import infoToMode from "../code-block/info-to-mode";
26
import { Meta, createMetaNode } from "./type";
27
export type { Meta };
28
export { createMetaNode };
29
30
register({
31
slateType: "meta",
32
33
toSlate: ({ token }) => {
34
return createMetaNode(token.content);
35
},
36
37
StaticElement: ({ attributes, element }) => {
38
if (element.type != "meta") throw Error("bug");
39
return (
40
<div {...attributes}>
41
<code>---</code>
42
<CodeMirrorStatic
43
style={{ marginBottom: 0 }}
44
options={{ mode: infoToMode("yml"), lineWrapping: true }}
45
value={element.value}
46
/>
47
<code>---</code>
48
</div>
49
);
50
},
51
});
52
53