@@ -280,28 +280,30 @@ let non_empty_code_fragment c =
280
280
let s = source (inline ~verbatim: false ~in_source: true ) c in
281
281
match s with [] -> [] | _ :: _ as l -> [ Code_fragment l ]
282
282
283
+ let alt_text ~in_source (target : Target.t ) alt =
284
+ let text = txt ~verbatim: false ~in_source: false [ alt ] in
285
+ let break = if in_source then [] else [ Break Paragraph ] in
286
+ match target with
287
+ | Internal _ -> text @ break
288
+ | External l -> [ External_ref (l, Some text) ] @ break
289
+
290
+ let image ~in_source (internal_url : Url.t ) alt =
291
+ let dir, file = Link. get_dir_and_file internal_url.page in
292
+ match Fpath. (get_ext @@ v file) with
293
+ (* list imported from pdftex.def *)
294
+ | " " | " .pdf" | " .png" | " .jpg" | " .mps" | " .jpeg" | " .jbig2" | " .jb2"
295
+ | ".PDF" | ".PNG" | ".JPG" | ".JPEG" | ".JBIG2" | ".JB2" ->
296
+ let fpath = Fpath. v (String. concat Fpath. dir_sep (dir @ [ file ])) in
297
+ [ Image fpath ]
298
+ | _ -> alt_text ~in_source (Internal (Resolved internal_url)) alt
299
+
283
300
let rec block ~in_source (l : Block.t ) =
284
301
let one (t : Block.one ) =
285
302
match t.desc with
286
303
| Inline i -> inline ~verbatim: false ~in_source: false i
287
- | Image (Internal (Resolved x ), alt ) ->
288
- let dir, file = Link. get_dir_and_file x.page in
289
- begin match Fpath. (get_ext @@ v file) with
290
- | "" | ".jpeg" | ".png" | ".pdf" ->
291
- let fpath = Fpath. v (String. concat Fpath. dir_sep (dir @ [file])) in
292
- [ Image fpath ]
293
- | _ ->
294
- txt ~verbatim: false ~in_source: false [ alt ]
295
- @ if in_source then [] else [ Break Paragraph ]
296
- end
297
- | Image (Internal Unresolved , c ) | Audio (Internal _ , c ) | Video (Internal _ , c ) ->
298
- txt ~verbatim: false ~in_source: false [ c ]
299
- @ if in_source then [] else [ Break Paragraph ]
300
- | Audio (External l, content) | Video (External l, content)
301
- | Image (External l , content ) ->
302
- let text = txt ~verbatim: false ~in_source: false [ content ] in
303
- let break = if in_source then [] else [ Break Paragraph ] in
304
- [ External_ref (l, Some text)] @ break
304
+ | Image (Internal (Resolved x ), alt ) -> image ~in_source x alt
305
+ | Image (t , alt ) | Audio (t , alt ) | Video (t , alt ) ->
306
+ alt_text ~in_source t alt
305
307
| Paragraph i ->
306
308
inline ~in_source: false ~verbatim: false i
307
309
@ if in_source then [] else [ Break Paragraph ]
0 commit comments