You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, this is quite difficult to do because you either:
query the parent of img to look for figures but then you end up wrapped inside your default element e.g. a paragraph and figcaption has its own text node
query img in figure and set the attributes, but then you end up with extra children you don't want
Only workaround i've found is super hacky:
htmlUpdaterMap: {figure: el=>{// strip all the child nodes from figures with images to make them flat for the elementMapconstcaption=findOne(node=>node.name==="figcaption",[el]);constimg=findOne(node=>node.name==="img",[el]);if(!img){returnel;}constsrc=img.attribs.src;constalt=img.attribs.alt;returnnewElement("figure",{
...el.attribs,"data-caption": caption ? textContent(caption) : "","data-src": src,"data-alt": alt,"data-type": "image",},[]);},},
Then I can add in a elementMap and extract these data attributes.
It would be nice if there was some nice way of mapping multiple dom nodes down to a single slate element
The text was updated successfully, but these errors were encountered:
Love this library, but hit a snag:
I have html like this
Ideally, I want to map this in slate with
htmlToSlate
to:Currently, this is quite difficult to do because you either:
img
to look for figures but then you end up wrapped inside your default element e.g. a paragraph and figcaption has its own text nodeimg
in figure and set the attributes, but then you end up with extra children you don't wantOnly workaround i've found is super hacky:
Then I can add in a elementMap and extract these data attributes.
It would be nice if there was some nice way of mapping multiple dom nodes down to a single slate element
The text was updated successfully, but these errors were encountered: