Skip to content

Commit 16a9535

Browse files
committed
Show frontmatter on story
1 parent 72c6c5e commit 16a9535

File tree

6 files changed

+401
-311
lines changed

6 files changed

+401
-311
lines changed

.storybook/components/slate-editor.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ const renderElement = ({
8888
</pre>
8989
);
9090
case "yaml":
91-
break;
91+
case "toml":
92+
return (
93+
<pre>
94+
<code {...attributes}>{children}</code>
95+
</pre>
96+
);
9297
case "definition":
9398
break;
9499
case "footnoteDefinition":

.storybook/components/slate0.47-editor.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,12 @@ export default forwardRef(
106106
</pre>
107107
);
108108
case "yaml":
109-
break;
109+
case "toml":
110+
return (
111+
<pre>
112+
<code {...attributes}>{children}</code>
113+
</pre>
114+
);
110115
case "definition":
111116
break;
112117
case "footnoteDefinition":

.storybook/playground-current.stories.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,24 @@ import { Node } from "slate";
33
import unified from "unified";
44
import markdown from "remark-parse";
55
import gfm from "remark-gfm";
6+
import frontmatter from "remark-frontmatter";
67
import stringify from "remark-stringify";
78
import { remarkToSlate, slateToRemark } from "../src";
89
import SlateEditor from "./components/slate-editor";
910
import TextEditor from "./components/text-editor";
1011
import Text from "./components/text";
1112
import text from "../fixture/article.md";
1213

13-
const toSlateProcessor = unified().use(markdown).use(gfm).use(remarkToSlate);
14-
const toRemarkProcessor = unified().use(slateToRemark).use(gfm).use(stringify);
14+
const toSlateProcessor = unified()
15+
.use(markdown)
16+
.use(gfm)
17+
.use(frontmatter)
18+
.use(remarkToSlate);
19+
const toRemarkProcessor = unified()
20+
.use(slateToRemark)
21+
.use(gfm)
22+
.use(frontmatter)
23+
.use(stringify);
1524

1625
const toSlate = (s: string) => toSlateProcessor.processSync(s).result as Node[];
1726
const toMd = (value: Node[]) => {

.storybook/playground-legacy.stories.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Value } from "slate_legacy";
33
import unified from "unified";
44
import markdown from "remark-parse";
55
import gfm from "remark-gfm";
6+
import frontmatter from "remark-frontmatter";
67
import stringify from "remark-stringify";
78
import { remarkToSlateLegacy, slateToRemarkLegacy } from "../src";
89
import SlateEditor from "./components/slate0.47-editor";
@@ -13,10 +14,12 @@ import text from "../fixture/article.md";
1314
const toSlateProcessor = unified()
1415
.use(markdown)
1516
.use(gfm)
17+
.use(frontmatter)
1618
.use(remarkToSlateLegacy);
1719
const toRemarkProcessor = unified()
1820
.use(slateToRemarkLegacy)
1921
.use(gfm)
22+
.use(frontmatter)
2023
.use(stringify);
2124

2225
const toSlate = (s: string) =>

fixture/article.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
---
2+
title: "This is frontmatter"
3+
date: 2020-04-30 12:34
4+
categories: [JavaScript, React]
5+
---
6+
17
# heading 1
28

39
## heading 2

0 commit comments

Comments
 (0)