@@ -124,13 +124,16 @@ export function parseImageBlock(b: any): ImageSet {
124124 const match = / \s * ( ..) \s * ( h t t p s : \/ \/ .* ) / . exec ( l ) ;
125125 if ( match ) {
126126 imageSet . localizedUrls . push ( {
127- iso632Code : match [ 1 ] . toUpperCase ( ) ,
127+ iso632Code : match [ 1 ] . toLowerCase ( ) ,
128128 url : match [ 2 ] ,
129129 } ) ;
130130 } else {
131- imageSet . caption += l + "\n" ;
131+ // NB: carriage returns seem to mess up the markdown, so should be removed
132+ imageSet . caption += l + " " ;
132133 }
133134 } ) ;
135+ // NB: currently notion-md puts the caption in Alt, which noone sees (unless the image isn't found)
136+ // We could inject a custom element handler to emit a <figure> in order to show the caption.
134137 imageSet . caption = imageSet . caption ?. trim ( ) ;
135138 //console.log(JSON.stringify(imageSet, null, 2));
136139
@@ -141,16 +144,29 @@ export function parseImageBlock(b: any): ImageSet {
141144// change the src to point to our copy of the image.
142145export async function processImageBlock ( b : any ) : Promise < void > {
143146 //console.log(JSON.stringify(b));
144- const img = parseImageBlock ( b ) ;
147+ const imageSet = parseImageBlock ( b ) ;
145148
146- const newPath = imagePrefix + "/" + ( await saveImage ( img , imageOutputPath ) ) ;
149+ const newPath =
150+ imagePrefix + "/" + ( await saveImage ( imageSet , imageOutputPath ) ) ;
147151
148152 // change the src to point to our copy of the image
149153 if ( "file" in b . image ) {
150154 b . image . file . url = newPath ;
151155 } else {
152156 b . image . external . url = newPath ;
153157 }
158+ // put back the simplified caption, stripped of the meta information
159+ if ( imageSet . caption ) {
160+ b . image . caption = [
161+ {
162+ type : "text" ,
163+ text : { content : imageSet . caption , link : null } ,
164+ plain_text : imageSet . caption ,
165+ } ,
166+ ] ;
167+ } else {
168+ b . image . caption = [ ] ;
169+ }
154170}
155171
156172function imageWasSeen ( path : string ) {
0 commit comments