Files
pgn_to_tex/bin/main.ml
T
owenrees 79155255f6 Transfer code (#1)
* copy project root files

* import previously created code and rename where needed

* fix license and lint

* main is now just a JS wrapper

* minified main.cjs rather than copying to a newly named file
2026-05-28 12:35:03 +02:00

36 lines
1.0 KiB
OCaml

open Js_of_ocaml
open Pgn_logic
open Ast
let parse_diagram_json json_str =
let json = Yojson.Basic.from_string json_str in
let json_list = Yojson.Basic.Util.to_list json in
List.fold_left
(fun acc item ->
let move_int =
item |> Yojson.Basic.Util.member "ply" |> Yojson.Basic.Util.to_int
in
let fen_str =
item |> Yojson.Basic.Util.member "fen" |> Yojson.Basic.Util.to_string
in
Pgn2tex.MoveMap.add move_int fen_str acc)
Pgn2tex.MoveMap.empty json_list
let convert_js pgn_js diagram_json_js display_clock =
let pgn = Js.to_string pgn_js in
(* convert JS string into OCaml string *)
let json_str = Js.to_string diagram_json_js in
let diagram_data =
if json_str = "" || json_str = "{}" then Pgn2tex.MoveMap.empty
else parse_diagram_json json_str
in
let result = Pgn2tex.to_tex pgn ~diagram_data ~clock:display_clock in
Js.string result
(* Exporting the module to the global JavaScript scope *)
let () = Js.export "to_tex" (Js.wrap_callback convert_js)