hanford / remark-slate

Remark plugin to compile Markdown as a slate 0.50+ compatible object.
155 stars 42 forks source link

Issue with Image node #44

Open vnugent opened 3 years ago

vnugent commented 3 years ago

I'm using remark-slate with Plate. Plate can load most markdown except for image (see differences below). I can pass an option to the deserialize function to change type=image to type=img. I don't think I can change how caption field is created. Any tips on how to fix this issue?

Plate image node: (working)

  {
    "type": "img",
    "url": "path to image",
    "children": [
      {
        "text": ""
      }
    ],
    "caption": [
      {
        "text": "foos"
      }
    ]
  }

remark-slate -> Plate: (not working)

      {
        "type": "image",  <-- expecting 'img'
        "children": [
          {
            "text": ""
          }
        ],
        "url": "path to image",
        "caption": "foos" <-- expecting an array 
      }
janaka commented 2 years ago

I'm hitting an issue which is caused by this as far as I can tell. Plate is throwing the error here. Expecting an array.

Error Cannot read properties of undefined (reading 'map') in ImageElement.tsx 108:1

I've had to set imageCaptionKey to something other than caption as a workaround.

.use(slate, { nodeTypes: plateNodeTypes, imageCaptionKey:'cap', imageSourceKey:'src'})

Being able to configure the caption deserialisation would be ideal IMO.

fwiw I've had to configure type from image to img along with a bunch of other elements using InputNodeTypes