Skip to content

serialize working right? #68

Description

@konsumer

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions