this repo has no description

Add png, pdf and jpeg image support to the latex backend

authored by

Florian Angeletti and committed by
Paul-Elliot Anglès d'Auriac
c233e40b c33060ab

+31 -6
+19 -3
src/latex/generator.ml
··· 97 97 | Code_fragment _ | Tag _ | Break _ | Ligaturable _ -> 98 98 Small 99 99 | List _ | Section _ | Verbatim _ | Raw _ | Code_block _ | Indented _ 100 - | Description _ -> 100 + | Description _ | Image _ -> 101 101 Large 102 102 | Table _ | Layout_table _ -> Huge 103 103 ··· 167 167 | Indented x -> Raw.indent pp ppf x 168 168 | Ligaturable s -> Fmt.string ppf s 169 169 | Tag (s, t) -> tag s ppf t 170 + | Image target -> Raw.includegraphics Fpath.pp ppf target 170 171 171 172 and pp ppf = function 172 173 | [] -> () ··· 281 282 let one (t : Block.one) = 282 283 match t.desc with 283 284 | Inline i -> inline ~verbatim:false ~in_source:false i 284 - | Audio (_, content) | Video (_, content) | Image (_, content) -> 285 - txt ~verbatim:false ~in_source:false [ content ] 285 + | Image (Internal (Resolved x), alt) -> 286 + let dir, file = Link.get_dir_and_file x.page in 287 + begin match Fpath.(get_ext @@ v file) with 288 + | "" | ".jpeg" | ".png" | ".pdf" -> 289 + let fpath = Fpath.v (String.concat Fpath.dir_sep (dir @ [file])) in 290 + [ Image fpath ] 291 + | _ -> 292 + txt ~verbatim:false ~in_source:false [ alt ] 293 + @ if in_source then [] else [ Break Paragraph ] 294 + end 295 + | Image (Internal Unresolved, c) | Audio(Internal _, c) | Video (Internal _, c) -> 296 + txt ~verbatim:false ~in_source:false [ c ] 286 297 @ if in_source then [] else [ Break Paragraph ] 298 + | Audio (External l, content) | Video (External l, content) 299 + | Image (External l, content) -> 300 + let text = txt ~verbatim:false ~in_source:false [ content ] in 301 + let break = if in_source then [] else [ Break Paragraph ] in 302 + [ External_ref (l, Some text)] @ break 287 303 | Paragraph i -> 288 304 inline ~in_source:false ~verbatim:false i 289 305 @ if in_source then [] else [ Break Paragraph ]
+2
src/latex/raw.ml
··· 126 126 Fmt.cut ppf (); 127 127 mend ppf name 128 128 129 + let includegraphics pp = create "includegraphics" pp 130 + 129 131 let section pp = create "section" pp 130 132 131 133 let subsection pp = create "subsection" pp
+2
src/latex/raw.mli
··· 66 66 67 67 val input : Fpath.t Fmt.t 68 68 69 + val includegraphics: 'a t 70 + 69 71 (** {1 Required OCaml-specific primitives} 70 72 All the macro should be implemented as "ocaml"-suffixed macro in the latex 71 73 preamble *)
+1
src/latex/types.ml
··· 26 26 | Layout_table of layout_table 27 27 | Table of table 28 28 | Ligaturable of string 29 + | Image of Fpath.t 29 30 30 31 and section = { level : int; label : string option; content : t } 31 32
+1 -1
test/pages/medias.t/index.mld
··· 7 7 Some image: 8 8 9 9 - Without alt text:{image!caml.gif} 10 - - With an alt text: {{image!caml.gif}With alt text and {b emphasis}} 10 + - With an alt text: {{image!caml.png}With alt text and {b emphasis}} 11 11 - Unresolved without alt text: {image!caqzdqzdml.gif} 12 12 - Unresolved with alt text: {{image!camezfzeffl.gif}With alt text and {b emphasis}} 13 13
+6 -2
test/pages/medias.t/run.t
··· 3 3 $ odoc compile index.mld --parent-id pkg1/ --output-dir _odoc 4 4 5 5 $ odoc compile-asset --parent-id pkg1/ --output-dir _odoc --name caml.gif 6 + $ odoc compile-asset --parent-id pkg1/ --output-dir _odoc --name caml.png 6 7 $ odoc compile-asset --parent-id pkg1/ --output-dir _odoc --name Cri_du_chameau.ogg 7 8 $ odoc compile-asset --parent-id pkg1/ --output-dir _odoc --name flower.webm 8 9 ··· 28 29 $ cat html/pkg1/index.html | grep img 29 30 <a href="caml.gif" class="img-link"> 30 31 <img src="caml.gif" alt="caml.gif"/> 31 - <a href="caml.gif" class="img-link"> 32 - <img src="caml.gif" alt="With alt text and {b emphasis}"/> 32 + <a href="caml.png" class="img-link"> 33 + <img src="caml.png" alt="With alt text and {b emphasis}"/> 33 34 <a href="https://picsum.photos/200/300" class="img-link"> 34 35 <img src="https://picsum.photos/200/300" alt="reference"/> 35 36 <a href="https://picsum.photos/200/300" class="img-link"> ··· 71 72 $ cat latex/pkg1/index.tex | grep gif 72 73 caml.gif 73 74 ./caqzdqzdml.gif 75 + 76 + $ cat latex/pkg1/index.tex | grep png 77 + \includegraphics{pkg1/caml.png}}% 74 78 75 79 $ odoc man-generate -o man _odoc/pkg1/page-index.odocl 76 80 $ cat man/pkg1/index.3o | grep gif