Skip to content

Commit

Permalink
Merge pull request #175 from inokawa/mdast-v5
Browse files Browse the repository at this point in the history
Support mdast v5 and unified 11
  • Loading branch information
inokawa authored Dec 7, 2023
2 parents 64c228d + 71265ce commit 1f51a09
Show file tree
Hide file tree
Showing 22 changed files with 5,754 additions and 12,249 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.
Loading

0 comments on commit 1f51a09

Please sign in to comment.