Skip to content

Commit b671fc7

Browse files
committed
add figure to deserializer
1 parent acc0b10 commit b671fc7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/convertHTMLtoPortableText.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@ function convertHTMLtoPortableText (HTMLDoc) {
1717
return []
1818
}
1919
const rules = [
20+
{
21+
deserialize(el, next, block) {
22+
if (el.tagName.toLowerCase() !== "figure") {
23+
return undefined;
24+
}
25+
const img = Array.from(el.children).find(
26+
child => child.tagName.toLowerCase() === "img"
27+
);
28+
const caption = Array.from(el.children).find(
29+
child => child.tagName.toLowerCase() === "figcaption"
30+
);
31+
32+
return block({
33+
_type: "figure",
34+
image: {
35+
// using the format for importing assets via the CLI
36+
// https://www.sanity.io/docs/data-store/importing-data#import-using-the-cli
37+
_sanityAsset: `image@${img.getAttribute("src")}`
38+
},
39+
alt: img.getAttribute("alt"),
40+
caption: caption.textContent
41+
});
42+
}
43+
},
2044
{
2145
// Special case for code blocks (wrapped in pre and code tag)
2246
deserialize (el, next, block) {

0 commit comments

Comments
 (0)