Skip to content

Commit 4fd663e

Browse files
committed
review: more file format and less nesting
1 parent 064b992 commit 4fd663e

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

src/latex/generator.ml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -280,28 +280,30 @@ let non_empty_code_fragment c =
280280
let s = source (inline ~verbatim:false ~in_source:true) c in
281281
match s with [] -> [] | _ :: _ as l -> [ Code_fragment l ]
282282

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+
283300
let rec block ~in_source (l : Block.t) =
284301
let one (t : Block.one) =
285302
match t.desc with
286303
| 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
305307
| Paragraph i ->
306308
inline ~in_source:false ~verbatim:false i
307309
@ if in_source then [] else [ Break Paragraph ]

src/latex/raw.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ val small_table : ('a, Types.alignment list option * 'a list list) tr
6767

6868
val input : Fpath.t Fmt.t
6969

70-
val includegraphics: 'a t
70+
val includegraphics : 'a t
7171

7272
(** {1 Required OCaml-specific primitives }
7373
All the macro should be implemented as "ocaml"-suffixed macro

0 commit comments

Comments
 (0)