Skip to content

Commit

Permalink
Support mdast v5 and unified 11
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Dec 7, 2023
1 parent 64c228d commit c2d092a
Show file tree
Hide file tree
Showing 21 changed files with 202 additions and 7,591 deletions.
71 changes: 13 additions & 58 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@

This plugin supports slate 0.50+.
The data structure is described [here](https://docs.slatejs.org/concepts/02-nodes).
And also support ~0.47.9 currently, but I don't know in the future.
slate ~0.47.9 was supported until 0.8.1.

All nodes in [mdast](https://github.com/syntax-tree/mdast) syntax tree are supported, including nodes created with...

- [remark-gfm](https://github.com/remarkjs/remark-gfm)
- [remark-footnotes](https://github.com/remarkjs/remark-footnotes)
- [remark-frontmatter](https://github.com/remarkjs/remark-frontmatter)
- `math` and `inlineMath` from [remark-math](https://github.com/remarkjs/remark-math).

Expand All @@ -33,18 +32,17 @@ npm install remark-slate-transformer

### Supported unified versions

| remark-slate-transformer | unified |
| ------------------------ | -------- |
| >=0.7.0 | >=10.1.0 |
| >=0.5.0 <0.7.0 | >=10.0.0 |
| <0.5.0 | <10.0.0 |
| remark-slate-transformer | unified |
| ------------------------ | ---------------- |
| >=0.9.0 | >=11.0.0 |
| >=0.7.0 <0.9.0 | >=10.1.0 <11.0.0 |
| >=0.5.0 <0.7.0 | >=10.0.0 |
| <0.5.0 | <10.0.0 |

## Usage

### Transform remark to slate

#### 0.50+

```javascript
import { unified } from "unified";
import markdown from "remark-parse";
Expand All @@ -58,58 +56,18 @@ const value = processor.processSync(text).result;
console.log(value);
```

#### ~0.47.9

```javascript
import { Value } from "slate";
import { unified } from "unified";
import markdown from "remark-parse";
import { remarkToSlateLegacy } from "remark-slate-transformer";

const processor = unified().use(markdown).use(remarkToSlateLegacy);

const text = "# hello world";

const value = Value.fromJSON(processor.processSync(text).result);
console.log(value);
```

### Transform slate to remark

#### 0.50+

```javascript
import { unified } from "unified";
import stringify from "remark-stringify";
import { slateToRemark } from "remark-slate-transformer";

const processor = unified().use(slateToRemark).use(stringify);

const value = ...; // value passed to slate editor

const ast = processor.runSync({
type: "root",
children: value,
});
const text = processor.stringify(ast);
console.log(text);
```

#### ~0.47.9

```javascript
import { unified } from "unified";
import stringify from "remark-stringify";
import { slateToRemarkLegacy } from "remark-slate-transformer";

const processor = unified().use(slateToRemarkLegacy).use(stringify);
const processor = unified().use(stringify);

const value = ...; // value passed to slate editor

const ast = processor.runSync({
type: "root",
children: value.toJSON().document.nodes,
});
const ast = processor.runSync(slateToRemark(value));
const text = processor.stringify(ast);
console.log(text);
```
Expand Down Expand Up @@ -142,8 +100,9 @@ const r2s = unified()
const value = r2s.processSync(text).result;
console.log(value);

const s2r = unified()
.use(slateToRemark, {
const s2r = unified().use(stringify);
const ast = s2r.runSync(
slateToRemark(value, {
overrides: {
head: (node, next) => ({
type: "heading",
Expand All @@ -153,11 +112,7 @@ const s2r = unified()
foo: (node, next) => ({ type: "foo", bar: node.value }),
},
})
.use(stringify);
const ast = s2r.runSync({
type: "root",
children: value,
});
);
const text = s2r.stringify(ast);
console.log(text);
```
Expand Down
2 changes: 1 addition & 1 deletion fixtures/node-footnotes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
This is footnote[^1]. And this is also ^[inline footnote].
This is footnote[^1].

[^1]: Here is the footnote.
23 changes: 9 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"prepublishOnly": "rimraf lib && npm run build"
},
"dependencies": {
"@types/mdast": "^3.0.10",
"@types/mdast": "^4.0.3",
"mdast-util-math": "^3.0.0",
"tslib": "^2.6.2"
},
Expand All @@ -42,9 +42,7 @@
"@storybook/react-vite": "7.6.2",
"@storybook/source-loader": "7.6.2",
"@storybook/test-runner": "0.16.0",
"@types/slate_legacy": "npm:@types/[email protected]",
"@types/slate-react_legacy": "npm:@types/[email protected]",
"@types/unist": "2.0.10",
"@types/unist": "3.0.2",
"babel-jest": "29.7.0",
"concurrently": "7.6.0",
"github-markdown-css": "4.0.0",
Expand All @@ -53,26 +51,23 @@
"react-dom": "18.2.0",
"react-is": "18.2.0",
"react-syntax-highlighter": "15.5.0",
"remark-footnotes": "4.0.1",
"remark-frontmatter": "4.0.1",
"remark-gfm": "3.0.1",
"remark-math": "5.1.1",
"remark-parse": "10.0.2",
"remark-stringify": "10.0.3",
"remark-frontmatter": "5.0.0",
"remark-gfm": "4.0.0",
"remark-math": "6.0.0",
"remark-parse": "11.0.0",
"remark-stringify": "11.0.0",
"rimraf": "5.0.5",
"rollup": "4.6.1",
"slate": "0.93.0",
"slate_legacy": "npm:[email protected]",
"slate-history": "0.93.0",
"slate-react": "0.93.0",
"slate-react_legacy": "npm:[email protected]",
"storybook": "^7.6.0",
"typescript": "5.3.3",
"unified": "10.1.2",
"unified": "11.0.4",
"vite": "5.0.6"
},
"peerDependencies": {
"unified": ">=10.1.0"
"unified": ">=11.0.0"
},
"repository": {
"type": "git",
Expand Down
4 changes: 0 additions & 4 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
{
"matchPackageNames": ["slate", "slate-react", "slate-history"],
"automerge": false
},
{
"packagePatterns": ["slate_legacy", "slate-react_legacy"],
"enabled": false
}
]
}
Loading

0 comments on commit c2d092a

Please sign in to comment.