From cda3647806003c15d16cc7be300ff9af374cace4 Mon Sep 17 00:00:00 2001 From: Paul-Elliot Date: Sun, 21 Apr 2024 11:11:38 +0200 Subject: [PATCH] Add delayed introduction of starting state Signed-off-by: Paul-Elliot --- compiler/src/lib/slipshow.ml | 60 +++++++++++++++++++++++------------ compiler/src/lib/slipshow.mli | 19 ++++++++++- docs/faq.rst | 5 +++ 3 files changed, 62 insertions(+), 22 deletions(-) diff --git a/compiler/src/lib/slipshow.ml b/compiler/src/lib/slipshow.ml index 98d2598..9ffb7b1 100644 --- a/compiler/src/lib/slipshow.ml +++ b/compiler/src/lib/slipshow.ml @@ -30,8 +30,8 @@ let slipshow_js_element slipshow_link = | Some (Remote r) -> Format.sprintf "" r | None -> Format.sprintf "" Data_files.(read Slipshow_js) -let embed_in_page content ~starting_state ~has_math ~math_link ~slip_css_link - ~theorem_css_link ~slipshow_js_link = +let embed_in_page content ~has_math ~math_link ~slip_css_link ~theorem_css_link + ~slipshow_js_link = let mathjax_element = mathjax_element has_math math_link in let slip_css_element = slip_css_element slip_css_link in let theorem_css_element = theorem_css_element theorem_css_link in @@ -45,16 +45,9 @@ let embed_in_page content ~starting_state ~has_math ~math_link ~slip_css_link let highlight_js_ocaml_element = "" in - let starting_state = - match starting_state with - | None -> "" - | Some (st, id) -> - "[" - ^ String.concat "," (List.map string_of_int st) - ^ "], \"" ^ id ^ "\"" - in - Format.sprintf - {| + let start = + Format.sprintf + {| @@ -82,21 +75,46 @@ let embed_in_page content ~starting_state ~has_math ~math_link ~slip_css_link -|} - mathjax_element slip_css_element theorem_css_element highlight_css_element - highlight_js_element highlight_js_ocaml_element content slipshow_js_element - starting_state + |} in + (start, end_) -let convert ?starting_state ?math_link ?slip_css_link ?theorem_css_link - ?slipshow_js_link ?(resolve_images = fun x -> Remote x) s = +type starting_state = int list * string +type delayed = string * string + +let delayed ?math_link ?slip_css_link ?theorem_css_link ?slipshow_js_link + ?(resolve_images = fun x -> Remote x) s = let md = Cmarkit.Doc.of_string ~heading_auto_ids:true ~strict:false s in let md = Cmarkit.Mapper.map_doc (Mappings.of_cmarkit resolve_images) md in let content = Cmarkit_renderer.doc_to_string Renderers.custom_html_renderer md in let has_math = Folders.has_math md in - embed_in_page ~starting_state ~has_math ~math_link ~slip_css_link - ~theorem_css_link ~slipshow_js_link content + embed_in_page ~has_math ~math_link ~slip_css_link ~theorem_css_link + ~slipshow_js_link content + +let add_starting_state (start, end_) starting_state = + let starting_state = + match starting_state with + | None -> "" + | Some (st, id) -> + "[" + ^ String.concat "," (List.map string_of_int st) + ^ "], \"" ^ id ^ "\"" + in + start ^ starting_state ^ end_ + +let convert ?starting_state ?math_link ?slip_css_link ?theorem_css_link + ?slipshow_js_link ?(resolve_images = fun x -> Remote x) s = + let delayed = + delayed ?math_link ?slip_css_link ?theorem_css_link ?slipshow_js_link + ~resolve_images s + in + add_starting_state delayed starting_state diff --git a/compiler/src/lib/slipshow.mli b/compiler/src/lib/slipshow.mli index 53bc168..4485f62 100644 --- a/compiler/src/lib/slipshow.mli +++ b/compiler/src/lib/slipshow.mli @@ -2,8 +2,25 @@ type asset = Ast.asset = | Local of { mime_type : string option; content : string } | Remote of string +type starting_state = int list * string +type delayed + +val delayed : + ?math_link:asset -> + ?slip_css_link:asset -> + ?theorem_css_link:asset -> + ?slipshow_js_link:asset -> + ?resolve_images:(string -> asset) -> + string -> + delayed +(** This function is used to delay the decision on the starting state. It allows + to run [convert] server-side (which is useful to get images and so on) but + let the previewer decide on the starting state. *) + +val add_starting_state : delayed -> starting_state option -> string + val convert : - ?starting_state:int list * string -> + ?starting_state:starting_state -> ?math_link:asset -> ?slip_css_link:asset -> ?theorem_css_link:asset -> diff --git a/docs/faq.rst b/docs/faq.rst index 7121de3..da1d99a 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -95,6 +95,11 @@ Can I export to PDF? export a presentation to latex and compile the produced latex. It is useful to send as notes, rather than sending the slipshow presentation! +Can I include a PDF in a presentation? +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Slipshow can only include images supported on the web. You can convert your pdf image to a supported format. + Will it look the same on all screens? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Mostly yes. Browser do what they can to render exactly the same. A low resolution might make your presentation blurry, but things will be at the same place.