File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed
Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments