@@ -124,13 +124,16 @@ export function parseImageBlock(b: any): ImageSet {
124
124
const match = / \s * ( ..) \s * ( h t t p s : \/ \/ .* ) / . exec ( l ) ;
125
125
if ( match ) {
126
126
imageSet . localizedUrls . push ( {
127
- iso632Code : match [ 1 ] . toUpperCase ( ) ,
127
+ iso632Code : match [ 1 ] . toLowerCase ( ) ,
128
128
url : match [ 2 ] ,
129
129
} ) ;
130
130
} else {
131
- imageSet . caption += l + "\n" ;
131
+ // NB: carriage returns seem to mess up the markdown, so should be removed
132
+ imageSet . caption += l + " " ;
132
133
}
133
134
} ) ;
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.
134
137
imageSet . caption = imageSet . caption ?. trim ( ) ;
135
138
//console.log(JSON.stringify(imageSet, null, 2));
136
139
@@ -141,16 +144,29 @@ export function parseImageBlock(b: any): ImageSet {
141
144
// change the src to point to our copy of the image.
142
145
export async function processImageBlock ( b : any ) : Promise < void > {
143
146
//console.log(JSON.stringify(b));
144
- const img = parseImageBlock ( b ) ;
147
+ const imageSet = parseImageBlock ( b ) ;
145
148
146
- const newPath = imagePrefix + "/" + ( await saveImage ( img , imageOutputPath ) ) ;
149
+ const newPath =
150
+ imagePrefix + "/" + ( await saveImage ( imageSet , imageOutputPath ) ) ;
147
151
148
152
// change the src to point to our copy of the image
149
153
if ( "file" in b . image ) {
150
154
b . image . file . url = newPath ;
151
155
} else {
152
156
b . image . external . url = newPath ;
153
157
}
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
+ }
154
170
}
155
171
156
172
function imageWasSeen ( path : string ) {
0 commit comments