Skip to content

Commit

Permalink
Show frontmatter on story
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Oct 17, 2020
1 parent 72c6c5e commit 16a9535
Show file tree
Hide file tree
Showing 6 changed files with 401 additions and 311 deletions.
7 changes: 6 additions & 1 deletion .storybook/components/slate-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,12 @@ const renderElement = ({
</pre>
);
case "yaml":
break;
case "toml":
return (
<pre>
<code {...attributes}>{children}</code>
</pre>
);
case "definition":
break;
case "footnoteDefinition":
Expand Down
7 changes: 6 additions & 1 deletion .storybook/components/slate0.47-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ export default forwardRef(
</pre>
);
case "yaml":
break;
case "toml":
return (
<pre>
<code {...attributes}>{children}</code>
</pre>
);
case "definition":
break;
case "footnoteDefinition":
Expand Down
13 changes: 11 additions & 2 deletions .storybook/playground-current.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@ import { Node } from "slate";
import unified from "unified";
import markdown from "remark-parse";
import gfm from "remark-gfm";
import frontmatter from "remark-frontmatter";
import stringify from "remark-stringify";
import { remarkToSlate, slateToRemark } from "../src";
import SlateEditor from "./components/slate-editor";
import TextEditor from "./components/text-editor";
import Text from "./components/text";
import text from "../fixture/article.md";

const toSlateProcessor = unified().use(markdown).use(gfm).use(remarkToSlate);
const toRemarkProcessor = unified().use(slateToRemark).use(gfm).use(stringify);
const toSlateProcessor = unified()
.use(markdown)
.use(gfm)
.use(frontmatter)
.use(remarkToSlate);
const toRemarkProcessor = unified()
.use(slateToRemark)
.use(gfm)
.use(frontmatter)
.use(stringify);

const toSlate = (s: string) => toSlateProcessor.processSync(s).result as Node[];
const toMd = (value: Node[]) => {
Expand Down
3 changes: 3 additions & 0 deletions .storybook/playground-legacy.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Value } from "slate_legacy";
import unified from "unified";
import markdown from "remark-parse";
import gfm from "remark-gfm";
import frontmatter from "remark-frontmatter";
import stringify from "remark-stringify";
import { remarkToSlateLegacy, slateToRemarkLegacy } from "../src";
import SlateEditor from "./components/slate0.47-editor";
Expand All @@ -13,10 +14,12 @@ import text from "../fixture/article.md";
const toSlateProcessor = unified()
.use(markdown)
.use(gfm)
.use(frontmatter)
.use(remarkToSlateLegacy);
const toRemarkProcessor = unified()
.use(slateToRemarkLegacy)
.use(gfm)
.use(frontmatter)
.use(stringify);

const toSlate = (s: string) =>
Expand Down
6 changes: 6 additions & 0 deletions fixture/article.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
---
title: "This is frontmatter"
date: 2020-04-30 12:34
categories: [JavaScript, React]
---

# heading 1

## heading 2
Expand Down
Loading

0 comments on commit 16a9535

Please sign in to comment.