Skip to content

Commit

Permalink
Add delayed introduction of starting state
Browse files Browse the repository at this point in the history
Signed-off-by: Paul-Elliot <peada@free.fr>
  • Loading branch information
panglesd committed Apr 21, 2024
1 parent 40e9f12 commit cda3647
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 22 deletions.
60 changes: 39 additions & 21 deletions compiler/src/lib/slipshow.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ let slipshow_js_element slipshow_link =
| Some (Remote r) -> Format.sprintf "<script src=\"%s\"></script>" r
| None -> Format.sprintf "<script>%s</script>" 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
Expand All @@ -45,16 +45,9 @@ let embed_in_page content ~starting_state ~has_math ~math_link ~slip_css_link
let highlight_js_ocaml_element =
"<script>" ^ Data_files.(read Highlight_js_ocaml) ^ "</script>"
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
{|
<!doctype html>
<html>
<head>
Expand Down Expand Up @@ -82,21 +75,46 @@ let embed_in_page content ~starting_state ~has_math ~math_link ~slip_css_link
<!-- Start the presentation () -->
<script>hljs.highlightAll();</script>
<script>
Slipshow.startSlipshow(%s);
Slipshow.startSlipshow(|}
mathjax_element slip_css_element theorem_css_element highlight_css_element
highlight_js_element highlight_js_ocaml_element content
slipshow_js_element
in
let end_ = {|);
</script>
</body>
</html>|}
mathjax_element slip_css_element theorem_css_element highlight_css_element
highlight_js_element highlight_js_ocaml_element content slipshow_js_element
starting_state
</html>|} 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
19 changes: 18 additions & 1 deletion compiler/src/lib/slipshow.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
5 changes: 5 additions & 0 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit cda3647

Please sign in to comment.