this repo has no description

Add Copy_from support file variant and configurable x-ocaml URLs

Support files can now either embed inline string content (Inline) or
reference a file path on disk to copy (Copy_from). This enables large
binary-like files such as x-ocaml.js (~16MB) to be managed via
`odoc support-files` without embedding them as OCaml string literals.

The scrollycode extension's x-ocaml script URLs are now configurable
via ODOC_X_OCAML_JS and ODOC_X_OCAML_WORKER environment variables,
and ODOC_X_OCAML_JS_PATH registers the file as a Copy_from support file.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

+72 -24
+1 -1
odoc-admonition-extension/src/admonition_extension.ml
··· 155 155 (* Register CSS as a support file *) 156 156 Registry.register_support_file ~prefix { 157 157 filename = "extensions/admonition.css"; 158 - content = admonition_css; 158 + content = Inline admonition_css; 159 159 }
+1 -1
odoc-dot-extension/src/dot_extension.ml
··· 288 288 Api.Registry.register_extension_info extension_info; 289 289 Api.Registry.register_support_file ~prefix:"dot" { 290 290 filename = "extensions/dot.css"; 291 - content = dot_css; 291 + content = Inline dot_css; 292 292 }
+1 -1
odoc-mermaid-extension/src/mermaid_extension.ml
··· 275 275 Api.Registry.register_extension_info extension_info; 276 276 Api.Registry.register_support_file ~prefix:"mermaid" { 277 277 filename = "extensions/mermaid.css"; 278 - content = mermaid_css; 278 + content = Inline mermaid_css; 279 279 }
+1 -1
odoc-msc-extension/src/msc_extension.ml
··· 327 327 Api.Registry.register_extension_info extension_info; 328 328 Api.Registry.register_support_file ~prefix:"msc" { 329 329 filename = "extensions/msc.css"; 330 - content = msc_css; 330 + content = Inline msc_css; 331 331 }
+1 -1
odoc-rfc-extension/src/rfc_extension.ml
··· 125 125 end); 126 126 Registry.register_support_file ~prefix { 127 127 filename = "extensions/rfc.css"; 128 - content = rfc_css; 128 + content = Inline rfc_css; 129 129 }
+21 -4
odoc-scrollycode-extension/src/scrollycode_extension.ml
··· 698 698 Buffer.add_string buf "</script>\n"; 699 699 700 700 (* x-ocaml for playground *) 701 - Buffer.add_string buf {|<script src="/_x-ocaml/x-ocaml.js" src-worker="/_x-ocaml/worker.js" backend="jtw"></script> 702 - |}; 701 + let x_ocaml_js_url = 702 + match Sys.getenv_opt "ODOC_X_OCAML_JS" with 703 + | Some url -> url 704 + | None -> "/_x-ocaml/x-ocaml.js" 705 + in 706 + let x_ocaml_worker_url = 707 + match Sys.getenv_opt "ODOC_X_OCAML_WORKER" with 708 + | Some url -> url 709 + | None -> "/_x-ocaml/worker.js" 710 + in 711 + Printf.bprintf buf {|<script src="%s" src-worker="%s" backend="jtw"></script> 712 + |} x_ocaml_js_url x_ocaml_worker_url; 703 713 704 714 Buffer.contents buf 705 715 ··· 737 747 Odoc_extension_api.Registry.register (module Scrolly); 738 748 Odoc_extension_api.Registry.register_support_file ~prefix:"scrolly" { 739 749 filename = "extensions/scrollycode.css"; 740 - content = Scrollycode_css.structural_css; 741 - } 750 + content = Inline Scrollycode_css.structural_css; 751 + }; 752 + (match Sys.getenv_opt "ODOC_X_OCAML_JS_PATH" with 753 + | Some path -> 754 + Odoc_extension_api.Registry.register_support_file ~prefix:"scrolly" { 755 + filename = "_x-ocaml/x-ocaml.js"; 756 + content = Copy_from path; 757 + } 758 + | None -> ())
+1 -1
odoc-scrollycode-extension/src/scrollycode_themes.ml
··· 521 521 let register name content = 522 522 Odoc_extension_api.Registry.register_support_file ~prefix:"scrolly" { 523 523 filename = "extensions/scrollycode-" ^ name ^ ".css"; 524 - content; 524 + content = Inline content; 525 525 } 526 526 in 527 527 register "warm" warm_css;
+5 -1
odoc/src/extension_api/odoc_extension_api.ml
··· 138 138 will be output by [odoc support-files]. 139 139 *) 140 140 141 + type support_file_content = Odoc_extension_registry.support_file_content = 142 + | Inline of string 143 + | Copy_from of string 144 + 141 145 type support_file = Odoc_extension_registry.support_file = { 142 146 filename : string; (** Relative path, e.g., "extensions/admonition.css" *) 143 - content : string; (** File content *) 147 + content : support_file_content; 144 148 } 145 149 146 150 (** {1 Extension Registry}
+6 -1
odoc/src/extension_registry/odoc_extension_registry.ml
··· 15 15 | Js_inline of string 16 16 | Css_inline of string 17 17 18 + (** Content of a support file: either inline string or path to copy from disk *) 19 + type support_file_content = 20 + | Inline of string 21 + | Copy_from of string (** Absolute path to source file *) 22 + 18 23 (** Support files that extensions want to output *) 19 24 type support_file = { 20 25 filename : string; (** Relative path, e.g., "extensions/admonition.css" *) 21 - content : string; (** File content *) 26 + content : support_file_content; 22 27 } 23 28 24 29 (** Binary asset generated by an extension (e.g., rendered PNG) *)
+34 -12
odoc/src/odoc/support_files.ml
··· 9 9 | _ -> true 10 10 else true 11 11 12 - let iter_files f ?(without_theme = false) output_directory = 12 + let write ?(without_theme = false) output_directory = 13 13 let file name content = 14 14 let name = Fs.File.create ~directory:output_directory ~name in 15 - f name content 15 + let dir = Fs.File.dirname name in 16 + Fs.Directory.mkdir_p dir; 17 + let name = Fs.File.to_string name in 18 + Io_utils.with_open_out name (fun oc -> output_string oc content) 16 19 in 17 20 (* Built-in support files *) 18 21 let files = Odoc_html_support_files.file_list in ··· 26 29 let extension_files = Odoc_extension_registry.list_support_files () in 27 30 List.iter 28 31 (fun (ext_file : Odoc_extension_registry.support_file) -> 29 - file ext_file.filename ext_file.content) 32 + match ext_file.content with 33 + | Inline content -> file ext_file.filename content 34 + | Copy_from src_path -> 35 + let dst = Fs.File.create ~directory:output_directory ~name:ext_file.filename in 36 + let dir = Fs.File.dirname dst in 37 + Fs.Directory.mkdir_p dir; 38 + let src = Fs.File.of_string src_path in 39 + (match Fs.File.copy ~src ~dst with 40 + | Ok () -> () 41 + | Error (`Msg msg) -> 42 + Printf.eprintf "Warning: could not copy %s: %s\n" src_path msg)) 30 43 extension_files 31 44 32 - let write = 33 - iter_files (fun name content -> 34 - let dir = Fs.File.dirname name in 35 - Fs.Directory.mkdir_p dir; 36 - let name = Fs.File.to_string name in 37 - Io_utils.with_open_out name (fun oc -> output_string oc content)) 38 - 39 - let print_filenames = 40 - iter_files (fun name _content -> print_endline (Fs.File.to_string name)) 45 + let print_filenames ?(without_theme = false) output_directory = 46 + (* Built-in support files *) 47 + let files = Odoc_html_support_files.file_list in 48 + List.iter 49 + (fun f -> 50 + match Odoc_html_support_files.read f with 51 + | Some _ when should_include ~without_theme f -> 52 + let name = Fs.File.create ~directory:output_directory ~name:f in 53 + print_endline (Fs.File.to_string name) 54 + | _ -> ()) 55 + files; 56 + (* Extension support files *) 57 + let extension_files = Odoc_extension_registry.list_support_files () in 58 + List.iter 59 + (fun (ext_file : Odoc_extension_registry.support_file) -> 60 + let name = Fs.File.create ~directory:output_directory ~name:ext_file.filename in 61 + print_endline (Fs.File.to_string name)) 62 + extension_files