Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serialize working right? #68

Open
konsumer opened this issue Jun 2, 2023 · 0 comments
Open

serialize working right? #68

konsumer opened this issue Jun 2, 2023 · 0 comments

Comments

@konsumer
Copy link

konsumer commented Jun 2, 2023

Here is a codesandbox illustrating problem. Basically serialize does not output what I expect.

I am using this markdown (basically same from README, but with an image):

# Heading one

## Heading two

### Heading three

#### Heading four

##### Heading five

###### Heading six

Normal paragraph

_italic text_

**bold text**

~~strike through text~~

[hyperlink](https://jackhanford.com)

![kitten](http://placekitten.com/g/200/200)

> A block quote.

- bullet list item 1
- bullet list item 2

1. ordered list item 1
1. ordered list item 2

Here are my 2 functions:

import { unified } from 'unified'
import remarkSlate, { serialize } from 'remark-slate'
import remarkParse from 'remark-parse'

// turn AST into MD
export const deserialize = src => {
  const { result } = unified()
    .use(remarkParse)
    .use(remarkSlate)
    .processSync(src)
  return result
}

// turn MD into AST
export { serialize }

If I run this:

const deserialized = deserialize(plainMd)
console.log({ deserialized, serialized: deserialized.map((v) => serialize(v)).join('') })

I get

# Heading one
## Heading two
### Heading three
#### Heading four
##### Heading five
###### Heading six
Normal paragraph
_italic text_
**bold text**
~~strike through text~~
[hyperlink](https://jackhanford.com)
<br>

> A block quote.



- bullet list item 1
- bullet list item 2


1. ordered list item 1
1. ordered list item 2

for serialized. It's missing image and the formatting is wrong.

and deserialized looks like this:
Screenshot 2023-06-02 at 10 12 38 AM
deserialize.json.zip

Versions:

Mac M1 running 13.3.1
Node v20.0.0
Npm 9.6.4

"remark-slate": "^1.8.6"
slate": "^0.94.1"
"unified": "^10.1.2"
"remark-parse": "^10.0.2"

Am I doing something wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant