diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index e2e8875..7c51c11 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,8 +1,8 @@ -name: Main workflow +name: Builds, tests & co on: - pull_request: push: + pull_request: schedule: # Prime the caches every Monday - cron: 0 1 * * MON @@ -13,23 +13,18 @@ jobs: fail-fast: false matrix: os: - - macos-latest - ubuntu-latest + - macos-latest - windows-latest - runs-on: ${{ matrix.os }} - steps: - name: Checkout tree uses: actions/checkout@v4 - - name: Set-up OCaml uses: ocaml/setup-ocaml@v3 with: ocaml-compiler: "4.14" - - run: opam install . --deps-only - - run: opam exec -- make all lint-doc: @@ -37,12 +32,10 @@ jobs: steps: - name: Checkout tree uses: actions/checkout@v4 - - name: Set-up OCaml uses: ocaml/setup-ocaml@v3 with: ocaml-compiler: "4.14" - - uses: ocaml/setup-ocaml/lint-doc@v3 lint-fmt: @@ -50,12 +43,10 @@ jobs: steps: - name: Checkout tree uses: actions/checkout@v4 - - name: Set-up OCaml uses: ocaml/setup-ocaml@v3 with: ocaml-compiler: "4.14" - - uses: ocaml/setup-ocaml/lint-fmt@v3 lint-opam: @@ -63,10 +54,8 @@ jobs: steps: - name: Checkout tree uses: actions/checkout@v4 - - name: Set-up OCaml uses: ocaml/setup-ocaml@v3 with: ocaml-compiler: "4.14" - - uses: ocaml/setup-ocaml/lint-opam@v3 diff --git a/.ocamlformat b/.ocamlformat index cfcf346..d20e3da 100644 --- a/.ocamlformat +++ b/.ocamlformat @@ -1,20 +1,3 @@ -version=0.26.2 +version=0.27.0 profile=conventional -break-cases=fit-or-vertical -break-separators=before -break-sequences=true -cases-exp-indent=2 -doc-comments=before -dock-collection-brackets=false -field-space=loose -if-then-else=keyword-first -indicate-nested-or-patterns=unsafe-no -let-and=sparse -let-and=sparse parse-docstrings=true -sequence-style=terminator -space-around-arrays -space-around-lists -space-around-records -type-decl=sparse -wrap-comments=true diff --git a/dune-project b/dune-project index c1e0493..da3ebac 100644 --- a/dune-project +++ b/dune-project @@ -1,41 +1,26 @@ -(lang dune 2.0) - -(using menhir 2.0) - +(lang dune 3.17) (name html_of_wiki) +(generate_opam_files true) (implicit_transitive_deps false) (license "LGPL-2.1 with OCaml linking exception") - (authors "The ocsigen team ") - -(maintainers - "The ocsigen team " - "Leo Valais ") - -(source - (github ocsigen/html_of_wiki)) - -(bug_reports "https://github.com/ocsigen/html_of_wiki/issues") - -(homepage "https://github.com/ocsigen/html_of_wiki") - +(maintainers "The ocsigen team " "Leo Valais ") +(source (github ocsigen/html_of_wiki)) (documentation "https://ocsigen.org/html_of_wiki/2.0/manual/intro") -(generate_opam_files true) - (package (name html_of_wiki) (synopsis "A wikicreole to HTML compiler") - (description - "a static website generator for software projects, using wikicreole syntax.") + (description "a static website generator for software projects, using wikicreole syntax.") (depends + (ocaml (< 5.0)) ("cmdliner" (>= 1.1.1)) - "js_of_ocaml-ppx_deriving_json" + ("tyxml"(>= 4.6.0)) + "base64" "js_of_ocaml-ppx" + "js_of_ocaml-ppx_deriving_json" "ocamlfind" "re" - "base64" - "reason" - ("tyxml"(>= 4.6.0)))) + "reason")) diff --git a/html_of_wiki.opam b/html_of_wiki.opam index 5363c0a..bbeebbc 100644 --- a/html_of_wiki.opam +++ b/html_of_wiki.opam @@ -12,18 +12,20 @@ homepage: "https://github.com/ocsigen/html_of_wiki" doc: "https://ocsigen.org/html_of_wiki/2.0/manual/intro" bug-reports: "https://github.com/ocsigen/html_of_wiki/issues" depends: [ - "dune" {>= "2.0"} + "dune" {>= "3.17"} + "ocaml" {< "5.0"} "cmdliner" {>= "1.1.1"} - "js_of_ocaml-ppx_deriving_json" + "tyxml" {>= "4.6.0"} + "base64" "js_of_ocaml-ppx" + "js_of_ocaml-ppx_deriving_json" "ocamlfind" "re" - "base64" "reason" - "tyxml" {>= "4.6.0"} + "odoc" {with-doc} ] build: [ - ["dune" "subst"] {pinned} + ["dune" "subst"] {dev} [ "dune" "build" diff --git a/ohow-help.txt b/ohow-help.txt index 5358f50..891669b 100644 --- a/ohow-help.txt +++ b/ohow-help.txt @@ -118,7 +118,8 @@ OPTIONS -r, --hl, --headless Produces raw HTML without head tag and not inside a body tag. - --root=DIR (absent=/home/hugo/html_of_wiki/_build/default) + --root=DIR + (absent=/Users/smorimoto/src/github.com/ocsigen/html_of_wiki/_build/default) Use the given root directory. -t FILE, --template=FILE @@ -134,7 +135,7 @@ COMMON OPTIONS Show version information. EXIT STATUS - ohow exits with the following status: + ohow exits with: 0 on success. diff --git a/src/client/HTML5outliner.ml b/src/client/HTML5outliner.ml index e728ae8..e8a78e8 100644 --- a/src/client/HTML5outliner.ml +++ b/src/client/HTML5outliner.ml @@ -10,14 +10,7 @@ let heading_content = [ "h1"; "h2"; "h3"; "h4"; "h5"; "h6"; "hgroup" ] (* The h1 element is said to have the highest rank, the h6 element has the lowest rank, and two elements with the same name have equal rank. *) -type rank = - | H6 - | H5 - | H4 - | H3 - | H2 - | H1 - | Top +type rank = H6 | H5 | H4 | H3 | H2 | H1 | Top type outline = section list and section = Section of Dom.node Js.t list * string option * outline @@ -28,22 +21,22 @@ type heading = | Unnamed of string | Named of (rank * Dom.node Js.t list * string option) -type state = - { heading : heading - ; outline : outline - ; context : ((rank * Dom.node Js.t list * string option) * outline) list - ; ignore : Dom.node Js.t -> bool - } +type state = { + heading : heading; + outline : outline; + context : ((rank * Dom.node Js.t list * string option) * outline) list; + ignore : Dom.node Js.t -> bool; +} exception FoundNode of Dom.node Js.t let find_first_heading node = let rec find node = let tag = String.lowercase_ascii (Js.to_string node##.nodeName) in - if List.mem tag [ "h1"; "h2"; "h3"; "h4"; "h5"; "h6" ] - then raise (FoundNode node) - else if not (List.mem tag sectionning_tag) - then List.iter find (Dom.list_of_nodeList node##.childNodes) + if List.mem tag [ "h1"; "h2"; "h3"; "h4"; "h5"; "h6" ] then + raise (FoundNode node) + else if not (List.mem tag sectionning_tag) then + List.iter find (Dom.list_of_nodeList node##.childNodes) in try find node; @@ -59,10 +52,9 @@ let find_previous_heading node = in let rec find node = let tag = String.lowercase_ascii (Js.to_string node##.nodeName) in - if List.mem tag [ "h1"; "h2"; "h3"; "h4"; "h5"; "h6" ] - then raise (FoundNode node) - else if not (List.mem tag sectionning_tag) - then ( + if List.mem tag [ "h1"; "h2"; "h3"; "h4"; "h5"; "h6" ] then + raise (FoundNode node) + else if not (List.mem tag sectionning_tag) then ( List.iter find (List.rev (Dom.list_of_nodeList node##.childNodes)); find (previous node)) in @@ -104,38 +96,40 @@ let get_fragment node = (fun s -> Some (Js.to_string s))) let unnamed tag = - [ (Dom_html.document##createTextNode (Js.string ("Unnamed " ^ tag)) - :> Dom.node Js.t) + [ + (Dom_html.document##createTextNode (Js.string ("Unnamed " ^ tag)) + :> Dom.node Js.t); ] let step_up st = match st.context with | [] -> assert false | (upper_heading, upper_outline) :: context -> - let heading, fragment = - match st.heading with - | Named (_, nodes, fragment) -> (nodes, fragment) - | Unnamed tag -> (unnamed tag, None) - in - { st with - heading = Named upper_heading - ; outline = - Section (heading, fragment, List.rev st.outline) :: upper_outline - ; context - } + let heading, fragment = + match st.heading with + | Named (_, nodes, fragment) -> (nodes, fragment) + | Unnamed tag -> (unnamed tag, None) + in + { + st with + heading = Named upper_heading; + outline = + Section (heading, fragment, List.rev st.outline) :: upper_outline; + context; + } let rec insert_heading st ((rank, _, _) as node) = match st.heading with | Unnamed _ -> assert false | Named ((candidate_rank, _, _) as candidate) -> - if candidate_rank > rank - then - { st with - heading = Named node - ; outline = [] - ; context = (candidate, st.outline) :: st.context - } - else insert_heading (step_up st) node + if candidate_rank > rank then + { + st with + heading = Named node; + outline = []; + context = (candidate, st.outline) :: st.context; + } + else insert_heading (step_up st) node let rec rebuild st = match (st.context, st.heading) with @@ -143,18 +137,17 @@ let rec rebuild st = | _, Named _ | _, Unnamed _ -> rebuild (step_up st) let init_st ?(ignore = fun _ -> false) tag = - { heading = Unnamed tag - ; outline = [] - ; context = [ ((Top, [], None), []) ] - ; ignore + { + heading = Unnamed tag; + outline = []; + context = [ ((Top, [], None), []) ]; + ignore; } let rec walk st node = let tag = String.lowercase_ascii (Js.to_string node##.nodeName) in - if st.ignore node - then st - else if List.mem tag heading_content - then + if st.ignore node then st + else if List.mem tag heading_content then let node = find_first_heading node in let childrens = List.map @@ -165,21 +158,18 @@ let rec walk st node = match st.heading with | Unnamed _ when st.outline = [] -> { st with heading = Named candidate } | Unnamed tag when st.context = [ ((Top, [], None), []) ] -> - { st with - heading = Named candidate - ; outline = [] - ; context = ((Top, unnamed tag, fragment), st.outline) :: st.context - } + { + st with + heading = Named candidate; + outline = []; + context = ((Top, unnamed tag, fragment), st.outline) :: st.context; + } | Unnamed _ -> assert false | Named _ -> insert_heading st candidate - else if List.mem tag sectionning_root - then st (* ignore these nodes... *) - else if List.mem tag sectionning_content - then + else if List.mem tag sectionning_root then st (* ignore these nodes... *) + else if List.mem tag sectionning_content then let st = - match st.context with - | [] | [ ((Top, _, _), _) ] -> st - | _ -> step_up st + match st.context with [] | [ ((Top, _, _), _) ] -> st | _ -> step_up st in let nodes = Dom.list_of_nodeList node##.childNodes in let outline = @@ -209,14 +199,9 @@ let find_fragment fragment outline = | Section (_, _, outline) -> find_l outline and find_l = function | [] -> None - | x :: xs -> ( - match find x with - | None -> find_l xs - | Some _ as x -> x) + | x :: xs -> ( match find x with None -> find_l xs | Some _ as x -> x) in - match find_l outline with - | None -> [] - | Some x -> x + match find_l outline with None -> [] | Some x -> x let rec build_ol ?(depth = 0) outline = (* depth = 0 means as deep as infinity (for a value of infinity equal to @@ -232,10 +217,10 @@ and build_li ~depth (Section (heading, fragment, outline)) = (match fragment with | None -> List.iter (Dom.appendChild li) heading | Some fragment -> - let a = Dom_html.createA Dom_html.document in - a##setAttribute (Js.string "href") (Js.string @@ "#" ^ fragment); - List.iter (Dom.appendChild a) heading; - Dom.appendChild li a); - if outline <> [] && depth <> 0 - then Dom.appendChild li (build_ol ~depth outline); + let a = Dom_html.createA Dom_html.document in + a##setAttribute (Js.string "href") (Js.string @@ "#" ^ fragment); + List.iter (Dom.appendChild a) heading; + Dom.appendChild li a); + if outline <> [] && depth <> 0 then + Dom.appendChild li (build_ol ~depth outline); li diff --git a/src/client/client.ml b/src/client/client.ml index 27f16c8..43935d3 100644 --- a/src/client/client.ml +++ b/src/client/client.ml @@ -15,50 +15,46 @@ let () = let elem, restrict2 = match elem with | `Id id -> - ( (Dom_html.document##getElementById (Js.string id) - :> Dom.node Js.t Js.opt) - , None ) + ( (Dom_html.document##getElementById (Js.string id) + :> Dom.node Js.t Js.opt), + None ) | `Container -> - let fragment = - if div - then - try - Js.Opt.case - (HTML5outliner.find_previous_heading nav) - (fun () -> None) - (fun x -> HTML5outliner.get_fragment x) - with Not_found -> None - else None - in - (HTML5outliner.find_container nav, fragment) + let fragment = + if div then + try + Js.Opt.case + (HTML5outliner.find_previous_heading nav) + (fun () -> None) + (fun x -> HTML5outliner.get_fragment x) + with Not_found -> None + else None + in + (HTML5outliner.find_container nav, fragment) in let restrict = - match restrict with - | None -> restrict2 - | _ -> restrict + match restrict with None -> restrict2 | _ -> restrict in match Js.Opt.to_option elem with | None -> () | Some elem -> - let outline = - HTML5outliner.outline ~ignore - (Dom.list_of_nodeList elem##.childNodes) - in - let outline = - match restrict with - | Some fragment -> HTML5outliner.find_fragment fragment outline - | None -> ( - match outline with - | [ HTML5outliner.Section (_, _, outline) ] -> outline - | _ -> outline) - in - Dom.appendChild nav (HTML5outliner.build_ol ?depth outline) + let outline = + HTML5outliner.outline ~ignore + (Dom.list_of_nodeList elem##.childNodes) + in + let outline = + match restrict with + | Some fragment -> HTML5outliner.find_fragment fragment outline + | None -> ( + match outline with + | [ HTML5outliner.Section (_, _, outline) ] -> outline + | _ -> outline) + in + Dom.appendChild nav (HTML5outliner.build_ol ?depth outline) end) let to_list l = let rec f acc i = - if i < l##.length - then + if i < l##.length then match Js.Opt.to_option (l##item i) with | None -> f acc (i + 1) | Some x -> f (x :: acc) (i + 1) @@ -103,15 +99,15 @@ let translate existing = match Js.Opt.to_option existing##.textContent with | None -> () | Some ocaml -> ( - try - (* to_bytestring is required because there are 0xa0 bytes *) - let reason = ocaml |> Js.to_bytestring |> to_reason |> Js.string in - let code' = create_code ~language:"reason" reason in - insert_after ~existing code'; - highlight_element code'; - (* remove translatable, so that we only do this once *) - existing##.className := Js.string "language-ocaml" - with _e -> existing##.className := Js.string "language-ocaml error") + try + (* to_bytestring is required because there are 0xa0 bytes *) + let reason = ocaml |> Js.to_bytestring |> to_reason |> Js.string in + let code' = create_code ~language:"reason" reason in + insert_after ~existing code'; + highlight_element code'; + (* remove translatable, so that we only do this once *) + existing##.className := Js.string "language-ocaml" + with _e -> existing##.className := Js.string "language-ocaml error") let convert pre = let code = Dom_html.(createCode document) in @@ -123,8 +119,9 @@ let convert pre = let remove_error_message n = let p = Js.Unsafe.coerce n in - if Js.string p##.firstChild == Js.string "[object Text]" - && p##.firstChild##.data == Js.string reason_error + if + Js.string p##.firstChild == Js.string "[object Text]" + && p##.firstChild##.data == Js.string reason_error then Js.Opt.iter n##.firstChild (fun c -> ignore (n##removeChild c)) let add_error_message n = @@ -137,8 +134,7 @@ let toggle_reason () = to_list (Dom_html.document##getElementsByTagName n) |> List.iter (fun body -> let class_list = body##.classList in - if Js.to_bool (class_list##contains (Js.string "reason")) - then ( + if Js.to_bool (class_list##contains (Js.string "reason")) then ( let t = Js.string "language-ocaml error" in to_list (Dom_html.document##getElementsByClassName t) |> List.iter remove_error_message; @@ -161,26 +157,26 @@ let () = (match Dom_html.(getElementById_coerce "search" CoerceTo.form) with | None -> () | Some form -> - form##.onsubmit := - Dom_html.handler @@ fun _ -> - let engine = "https://google.com/search?q=" in - let filter = " site:ocsigen.org" in - let q = - (match Dom_html.(getElementById_coerce "q" CoerceTo.input) with - | None -> filter - | Some q -> Js.to_string q##.value ^ filter) - |> Js.string |> Js.encodeURIComponent |> Js.to_string - in - Dom_html.window##.location##.href := Js.string (engine ^ q); - Js.bool false); + form##.onsubmit := + Dom_html.handler @@ fun _ -> + let engine = "https://google.com/search?q=" in + let filter = " site:ocsigen.org" in + let q = + (match Dom_html.(getElementById_coerce "q" CoerceTo.input) with + | None -> filter + | Some q -> Js.to_string q##.value ^ filter) + |> Js.string |> Js.encodeURIComponent |> Js.to_string + in + Dom_html.window##.location##.href := Js.string (engine ^ q); + Js.bool false); (* language switch *) (match Dom_html.getElementById_opt "reason" with | None -> () | Some btn -> - btn##.onclick := - Dom_html.handler @@ fun _ -> - toggle_reason (); - Js.bool true); + btn##.onclick := + Dom_html.handler @@ fun _ -> + toggle_reason (); + Js.bool true); (* API conversion *) let f = Js.string "odocwiki_code" in to_list (Dom_html.document##getElementsByClassName f) diff --git a/src/common/bridge.ml b/src/common/bridge.ml index 890a50b..cb2c0ff 100644 --- a/src/common/bridge.ml +++ b/src/common/bridge.ml @@ -1,17 +1,13 @@ [@@@ocaml.warning "-39"] -type elem = - [ `Id of string - | `Container - ] -[@@deriving json] +type elem = [ `Id of string | `Container ] [@@deriving json] -type outline_params = - { elem : elem - ; restrict : string option - ; depth : int option - ; ignore : string list - ; nav : string - ; div : bool - } +type outline_params = { + elem : elem; + restrict : string option; + depth : int option; + ignore : string list; + nav : string; + div : bool; +} [@@deriving json] diff --git a/src/ohow/api.ml b/src/ohow/api.ml index b19d00b..4fe4f13 100644 --- a/src/ohow/api.ml +++ b/src/ohow/api.ml @@ -9,33 +9,32 @@ let is_capitalized s = let check_capitalized_path path = List.iter (fun name -> - if not (is_capitalized name) - then raise (Error (Printf.sprintf "%S is not a valid module name" name))) + if not (is_capitalized name) then + raise (Error (Printf.sprintf "%S is not a valid module name" name))) path let parse_lid id = match List.rev (String.split_on_char '.' (String.concat "" id)) with | id :: rpath when not (is_capitalized id) -> - check_capitalized_path rpath; - (List.rev rpath, id) + check_capitalized_path rpath; + (List.rev rpath, id) | _ -> - raise (Error (Printf.sprintf "invalid ocaml id %S" (String.concat "" id))) + raise (Error (Printf.sprintf "invalid ocaml id %S" (String.concat "" id))) let parse_uid id = match List.rev (String.split_on_char '.' (String.concat "" id)) with | id :: rpath when is_capitalized id -> - check_capitalized_path rpath; - (List.rev rpath, id) + check_capitalized_path rpath; + (List.rev rpath, id) | _ -> - raise (Error (Printf.sprintf "invalid ocaml id %S" (String.concat "" id))) + raise (Error (Printf.sprintf "invalid ocaml id %S" (String.concat "" id))) let parse_method id = match String.split_on_char '#' id with | [ id; mid ] when (not (is_capitalized id)) && not (is_capitalized mid) -> - (id, mid) + (id, mid) | _ -> raise (Error (Printf.sprintf "invalid method name %S" id)) -(** OCaml identifier *) type t = string list * [ `Mod of string @@ -57,8 +56,8 @@ type t = | `IndexClasses | `IndexClassTypes | `IndexModules - | `IndexModuleTypes - ] + | `IndexModuleTypes ] +(** OCaml identifier *) let index : t = ([], `Index) let seps = Re.rep1 (Re.alt [ Re.blank; Re.char '\n' ]) |> Re.compile @@ -67,65 +66,66 @@ let parse_contents contents = match contents with | None | Some "" -> raise (Error "contents must be an Ocaml id") | Some def -> ( - let def = Re.split seps def in - match def with - | [ "intro" ] -> ([], `Index) - | [ "index" ] -> ([], `Index) - | "index" :: "types" :: _ -> ([], `IndexTypes) - | "index" :: "exceptions" :: _ -> ([], `IndexExceptions) - | "index" :: "values" :: _ -> ([], `IndexValues) - | "index" :: "attributes" :: _ -> ([], `IndexAttributes) - | "index" :: "methods" :: _ -> ([], `IndexMethods) - | "index" :: "classes" :: _ -> ([], `IndexClasses) - | "index" :: "class" :: "types" :: _ -> ([], `IndexClassTypes) - | "index" :: "modules" :: _ -> ([], `IndexModules) - | "index" :: "module" :: "types" :: _ -> ([], `IndexModuleTypes) - | "val" :: lid | "value" :: lid -> - let path, id = parse_lid lid in - (path, `Value id) - | "type" :: lid -> - let path, id = parse_lid lid in - (path, `Type id) - | "class" :: "type" :: lid -> - let path, id = parse_lid lid in - (path, `ClassType id) - | "class" :: lid -> - let path, id = parse_lid lid in - (path, `Class id) - | "module" :: "type" :: uid | "mod" :: "type" :: uid -> - let path, id = parse_uid uid in - (path, `ModType id) - | "module" :: uid | "mod" :: uid -> - let path, id = parse_uid uid in - (path, `Mod id) - | "exception" :: uid | "exc" :: uid -> - let path, id = parse_uid uid in - (path, `Exc id) - | "attribute" :: lid | "attr" :: lid -> - let path, id = parse_lid lid in - let id, did = parse_method id in - (path, `Attr (id, did)) - | "method" :: lid -> - let path, id = parse_lid lid in - let id, mid = parse_method id in - (path, `Method (id, mid)) - | "section" :: lid -> - let path, id = parse_lid lid in - (path, `Section id) - | x :: _ -> raise (Error ("invalid contents: " ^ x)) - | [] -> raise (Error "empty contents")) + let def = Re.split seps def in + match def with + | [ "intro" ] -> ([], `Index) + | [ "index" ] -> ([], `Index) + | "index" :: "types" :: _ -> ([], `IndexTypes) + | "index" :: "exceptions" :: _ -> ([], `IndexExceptions) + | "index" :: "values" :: _ -> ([], `IndexValues) + | "index" :: "attributes" :: _ -> ([], `IndexAttributes) + | "index" :: "methods" :: _ -> ([], `IndexMethods) + | "index" :: "classes" :: _ -> ([], `IndexClasses) + | "index" :: "class" :: "types" :: _ -> ([], `IndexClassTypes) + | "index" :: "modules" :: _ -> ([], `IndexModules) + | "index" :: "module" :: "types" :: _ -> ([], `IndexModuleTypes) + | "val" :: lid | "value" :: lid -> + let path, id = parse_lid lid in + (path, `Value id) + | "type" :: lid -> + let path, id = parse_lid lid in + (path, `Type id) + | "class" :: "type" :: lid -> + let path, id = parse_lid lid in + (path, `ClassType id) + | "class" :: lid -> + let path, id = parse_lid lid in + (path, `Class id) + | "module" :: "type" :: uid | "mod" :: "type" :: uid -> + let path, id = parse_uid uid in + (path, `ModType id) + | "module" :: uid | "mod" :: uid -> + let path, id = parse_uid uid in + (path, `Mod id) + | "exception" :: uid | "exc" :: uid -> + let path, id = parse_uid uid in + (path, `Exc id) + | "attribute" :: lid | "attr" :: lid -> + let path, id = parse_lid lid in + let id, did = parse_method id in + (path, `Attr (id, did)) + | "method" :: lid -> + let path, id = parse_lid lid in + let id, mid = parse_method id in + (path, `Method (id, mid)) + | "section" :: lid -> + let path, id = parse_lid lid in + (path, `Section id) + | x :: _ -> raise (Error ("invalid contents: " ^ x)) + | [] -> raise (Error "empty contents")) let string_of_id ?(spacer = ".") : t -> string = function | path, (`Method (cl, name) | `Attr (cl, name)) -> - name ^ " [" ^ String.concat spacer (path @ [ cl ]) ^ "]" - | ( path - , ( `Mod name + name ^ " [" ^ String.concat spacer (path @ [ cl ]) ^ "]" + | ( path, + ( `Mod name | `ModType name | `Class name | `ClassType name | `Value name | `Type name - | `Exc name ) ) -> String.concat spacer (path @ [ name ]) + | `Exc name ) ) -> + String.concat spacer (path @ [ name ]) | _, `Index -> "Api introduction" | _, `IndexTypes | _, `IndexExceptions @@ -136,15 +136,12 @@ let string_of_id ?(spacer = ".") : t -> string = function | _, `IndexClassTypes | _, `IndexModules | _, `IndexModuleTypes - | _, `Section _ -> "" + | _, `Section _ -> + "" module Ocamldoc = struct let path_of_id ?prefix id = - let add_prefix s = - match prefix with - | None -> s - | Some p -> p ^ s - in + let add_prefix s = match prefix with None -> s | Some p -> p ^ s in match id with | _path, `Index -> add_prefix "index" | _path, `IndexTypes -> add_prefix "index_types" @@ -157,17 +154,17 @@ module Ocamldoc = struct | _path, `IndexModules -> add_prefix "index_modules" | _path, `IndexModuleTypes -> add_prefix "index_module_types" | path, `ModType name | path, `Mod name -> - String.concat "." (path @ [ name ]) + String.concat "." (path @ [ name ]) | path, `ClassType name | path, `Class name -> ( - match prefix with - | None -> String.concat "." (path @ [ name ]) ^ "-c" - | Some p -> p ^ String.concat "." (path @ [ name ])) + match prefix with + | None -> String.concat "." (path @ [ name ]) ^ "-c" + | Some p -> p ^ String.concat "." (path @ [ name ])) | path, `Attr (cl, _) | path, `Method (cl, _) -> ( - match prefix with - | None -> String.concat "." (path @ [ cl ]) ^ "-c" - | Some p -> p ^ String.concat "." (path @ [ cl ])) + match prefix with + | None -> String.concat "." (path @ [ cl ]) ^ "-c" + | Some p -> p ^ String.concat "." (path @ [ cl ])) | path, `Value _ | path, `Type _ | path, `Exc _ | path, `Section _ -> - add_prefix (String.concat "." path) + add_prefix (String.concat "." path) let fragment_of_id : t -> string option = function | _, `Value name -> Some ("VAL" ^ name) @@ -188,8 +185,7 @@ module Odoc = struct | `Argument | `Class | `ClassType - | `File - ] + | `File ] let string_of_path_kind : path_kind -> string = function | `Page -> "page" @@ -236,8 +232,7 @@ module Odoc = struct | `Method | `Val | `Constructor - | `Field - ] + | `Field ] let string_of_kind : anchor_kind -> string = function | #path_kind as x -> string_of_path_kind x @@ -273,5 +268,6 @@ module Odoc = struct | _, `IndexClasses | _, `IndexClassTypes | _, `IndexModules - | _, `IndexModuleTypes -> None + | _, `IndexModuleTypes -> + None end diff --git a/src/ohow/cli.ml b/src/ohow/cli.ml index 6d5d75a..b61d8e7 100644 --- a/src/ohow/cli.ml +++ b/src/ohow/cli.ml @@ -96,63 +96,64 @@ let info_cmd = Cmdliner.( let doc = "Converts a wikicreole file into an HTML file." in let man = - [ `S Manpage.s_description - ; `P + [ + `S Manpage.s_description; + `P "$(tname) is a command line utility for compiling Wikicreole files \ - into HTML." - ; `S "EXTENSIONS" - ; `P + into HTML."; + `S "EXTENSIONS"; + `P "Extensions are supported. Some are built-in which are described in \ - the following sections." - ; `S "<>" - ; `P + the following sections."; + `S "<>"; + `P "Expands to a link to the `chapter' page inside `project''s manual \ directory and for a given `version'. A `fragment' can be added. \ - Default values:" - ; `P "- project: current project" - ; `P "- chapter: `project''s index page" - ; `P "- version: \"latest\"" - ; `P "- fragment: \"\"" - ; `P "The expansion fails when neither `project' nor `chapter' is given." - ; `S "<>" - ; `P + Default values:"; + `P "- project: current project"; + `P "- chapter: `project''s index page"; + `P "- version: \"latest\""; + `P "- fragment: \"\""; + `P "The expansion fails when neither `project' nor `chapter' is given."; + `S "<>"; + `P "Expands to a link to the `thing' of the given `project' or/and \ `subproject' of the given `version'. The link's text can be chosen \ - using the `text' argument. Default values:" - ; `P "- project: current project" - ; `P "- subproject: \"\"" - ; `P "- version: \"latest\"" - ; `P "- text: `thing'" - ; `S "<>" - ; `P "See a_api." - ; `S "<>" - ; `P "See a_api." - ; `S "LINKS" - ; `P + using the `text' argument. Default values:"; + `P "- project: current project"; + `P "- subproject: \"\""; + `P "- version: \"latest\""; + `P "- text: `thing'"; + `S "<>"; + `P "See a_api."; + `S "<>"; + `P "See a_api."; + `S "LINKS"; + `P "$(tname) is supposed to compile each wiki independently but these \ might contain links. Since $(tname) is not responsible for checking \ for dead links, it guesses the redirection for each link in a \ consistent way. However $(tname) sill needs to assume a bunch of \ - things and requires some extra information." - ; `P + things and requires some extra information."; + `P "- All the projects which links to each other must be placed inside \ - the same directory." - ; `P + the same directory."; + `P "- Inside each project directory are the root directories of each \ - version of the documentation." - ; `P + version of the documentation."; + `P "- The architecture inside each root (version of project) directory \ is less strict. However, if the a_manual tag is used, then the \ - manual directory must not contain wikis in sub-directories." - ; `P + manual directory must not contain wikis in sub-directories."; + `P "- If any of the a_api* tags is used, then each sub-project \ directory - if any - must be located inside the api directory and \ every wiki must be directly inside the api directory or its \ - sub-project directory (i.e: no sub-directories are allowed)." - ; `P + sub-project directory (i.e: no sub-directories are allowed)."; + `P "The options $(b,--root), $(b,--manual) and $(b,--api) can be used \ to explicitly provide the path to the, respectively, the root \ - directory, the manual directory and the api directory." + directory, the manual directory and the api directory."; ] in Cmd.info "ohow" ~version:"v2.0" ~doc ~man) @@ -165,30 +166,29 @@ let register_options k print headless outfile project root manual api let read_lines f = read_file_lines f |> List.filter_map (fun s -> - match String.trim s with - | "" -> None - | s -> Some s) + match String.trim s with "" -> None | s -> Some s) in let csw = csw <$> read_lines |? [] in let docversions = docversions <$> read_lines |? [] in let opts = - { Global.print - ; pretty - ; headless - ; outfile - ; suffix - ; project - ; root - ; manual - ; api - ; default_subproject - ; images - ; assets - ; template - ; csw - ; docversions - ; local - ; files + { + Global.print; + pretty; + headless; + outfile; + suffix; + project; + root; + manual; + api; + default_subproject; + images; + assets; + template; + csw; + docversions; + local; + files; } in Global.with_options opts (fun () -> k opts) diff --git a/src/ohow/code.ml b/src/ohow/code.ml index ff7301f..43c7ab8 100644 --- a/src/ohow/code.ml +++ b/src/ohow/code.ml @@ -7,20 +7,18 @@ let attrs args = match lang with | None -> ([], []) | Some lang -> - let pre_classes, code_classes = - if List.Assoc.get_opt args "translated" = None && lang = "ocaml" - then ([], [ "translatable" ]) - else ([ "manually-translated" ], []) - in - ( attrs @ [ Html.a_class pre_classes ] - , [ Html.a_class @@ (("language-" ^ lang) :: code_classes) ] ) + let pre_classes, code_classes = + if List.Assoc.get_opt args "translated" = None && lang = "ocaml" then + ([], [ "translatable" ]) + else ([ "manually-translated" ], []) + in + ( attrs @ [ Html.a_class pre_classes ], + [ Html.a_class @@ (("language-" ^ lang) :: code_classes) ] ) let code _bi args contents = `Flow5 (let contents = - match contents with - | None -> "" - | Some x -> String.trim x + match contents with None -> "" | Some x -> String.trim x in let p_a, c_a = attrs args in [ Html.(pre ~a:p_a [ code ~a:c_a [ txt contents ] ]) ]) @@ -28,9 +26,7 @@ let code _bi args contents = let code_inline _bi args contents = `Phrasing_without_interactive (let contents = - match contents with - | None -> "" - | Some x -> String.trim x + match contents with None -> "" | Some x -> String.trim x in let _, c_a = attrs args in [ Html.(code ~a:c_a [ txt contents ]) ]) diff --git a/src/ohow/document.ml b/src/ohow/document.ml index b09f827..a03c674 100644 --- a/src/ohow/document.ml +++ b/src/ohow/document.ml @@ -1,10 +1,6 @@ type t = | Site of string - | Project of - { page : project_page - ; version : Version.t - ; project : string - } + | Project of { page : project_page; version : Version.t; project : string } | Deadlink of exn and project_page = @@ -12,37 +8,30 @@ and project_page = | Template | Page of string | Manual of string - | Api of - { subproject : string option - ; file : string - } + | Api of { subproject : string option; file : string } let to_string d = match d with | Site s -> s | Project { page = Template; project; _ } -> project ^ "/template" | Project { page; version = v; project } -> - let p = - match page with - | Page p -> p - | Manual m -> "manual/" ^ m - | Api { subproject; file } -> - "api/" - ^ (match subproject with - | None -> "" - | Some subproject -> subproject ^ "/") - ^ file - | Template -> assert false (* handled above... *) - | Static (p, `File) | Static (p, `Folder) -> "manual/files/" ^ p - in - project ^ "/" ^ (v |> Version.to_string) ^ "/" ^ p + let p = + match page with + | Page p -> p + | Manual m -> "manual/" ^ m + | Api { subproject; file } -> + "api/" + ^ (match subproject with + | None -> "" + | Some subproject -> subproject ^ "/") + ^ file + | Template -> assert false (* handled above... *) + | Static (p, `File) | Static (p, `Folder) -> "manual/files/" ^ p + in + project ^ "/" ^ (v |> Version.to_string) ^ "/" ^ p | Deadlink e -> - Printf.eprintf "Deadlink: %s\n" (Printexc.to_string e); - "data:text/plain;base64," ^ Base64.encode_string (Printexc.to_string e) + Printf.eprintf "Deadlink: %s\n" (Printexc.to_string e); + "data:text/plain;base64," ^ Base64.encode_string (Printexc.to_string e) let to_uri ?fragment x = - "/" ^ to_string x - ^ - match fragment with - | None -> "" - | Some f -> "#" ^ f + "/" ^ to_string x ^ match fragment with None -> "" | Some f -> "#" ^ f diff --git a/src/ohow/document.mli b/src/ohow/document.mli index e08bc28..3eb7c09 100644 --- a/src/ohow/document.mli +++ b/src/ohow/document.mli @@ -1,10 +1,6 @@ type t = | Site of string - | Project of - { page : project_page - ; version : Version.t - ; project : string - } + | Project of { page : project_page; version : Version.t; project : string } | Deadlink of exn and project_page = @@ -12,9 +8,6 @@ and project_page = | Template | Page of string | Manual of string - | Api of - { subproject : string option - ; file : string - } + | Api of { subproject : string option; file : string } val to_uri : ?fragment:string -> t -> string diff --git a/src/ohow/dune b/src/ohow/dune deleted file mode 100644 index 60205ec..0000000 --- a/src/ohow/dune +++ /dev/null @@ -1,9 +0,0 @@ -(executables - (names ohow) - (public_names ohow) - (package html_of_wiki) - (libraries tyxml tyxml.functor re cmdliner unix common base64) - (modules_without_implementation wiki_syntax_types)) - -(ocamllex - (modules wikicreole)) diff --git a/src/ohow/error.ml b/src/ohow/error.ml index 5d4c77b..4b86e3e 100644 --- a/src/ohow/error.ml +++ b/src/ohow/error.ml @@ -11,13 +11,13 @@ let wrap_phrasing name f bi args contents = (let content = try f bi args contents with | Error msg as exc -> - bi.Wiki_widgets_interface.bi_add_link (Document.Deadlink exc); - error (Format.sprintf "Error %s: %s" name msg) + bi.Wiki_widgets_interface.bi_add_link (Document.Deadlink exc); + error (Format.sprintf "Error %s: %s" name msg) | exc -> - bi.Wiki_widgets_interface.bi_add_link (Document.Deadlink exc); - error - (Format.sprintf "Error %s: exception %s" name - (Printexc.to_string exc)) + bi.Wiki_widgets_interface.bi_add_link (Document.Deadlink exc); + error + (Format.sprintf "Error %s: exception %s" name + (Printexc.to_string exc)) in [ Html.span content ]) @@ -26,5 +26,5 @@ let wrap_flow5 name f bi args contents = (try f bi args contents with | Error msg -> error (Format.sprintf "Error %s: %s" name msg) | exc -> - error - (Format.sprintf "Error %s: exception %s" name (Printexc.to_string exc))) + error + (Format.sprintf "Error %s: exception %s" name (Printexc.to_string exc))) diff --git a/src/ohow/extensions.ml b/src/ohow/extensions.ml index 9ceffa4..1df317e 100644 --- a/src/ohow/extensions.ml +++ b/src/ohow/extensions.ml @@ -5,12 +5,10 @@ let get_opts ?defaults opts args : string option list = match defaults with | None -> values | Some defaults -> - let pick_first_some first second = - match first with - | Some _ -> first - | None -> second - in - List.map2 (fun v def -> pick_first_some v def) values defaults + let pick_first_some first second = + match first with Some _ -> first | None -> second + in + List.map2 (fun v def -> pick_first_some v def) values defaults let _reg name f = let wp_rec = Wiki_syntax.phrasing_wikicreole_parser in diff --git a/src/ohow/extensions.mli b/src/ohow/extensions.mli index b58cf79..bef70fb 100644 --- a/src/ohow/extensions.mli +++ b/src/ohow/extensions.mli @@ -1,14 +1,14 @@ val get_opts : - ?defaults:string option list - -> string list (* opts *) - -> (string * string) list (* args *) - -> string option list + ?defaults:string option list -> + string list (* opts *) -> + (string * string) list (* args *) -> + string option list val register : - ?defaults:string option list - -> string (* name *) - -> string list (* opts *) - -> ( string option - -> string option list - -> [< Html_types.span_content_fun > `Span ] Tyxml_html.elt list) - -> unit + ?defaults:string option list -> + string (* name *) -> + string list (* opts *) -> + (string option -> + string option list -> + [< Html_types.span_content_fun > `Span ] Tyxml_html.elt list) -> + unit diff --git a/src/ohow/global.ml b/src/ohow/global.ml index 844f72c..c56602f 100644 --- a/src/ohow/global.ml +++ b/src/ohow/global.ml @@ -23,17 +23,14 @@ let using_current_file k = let current_file () = using_current_file (fun x -> x) -type menu_file = - | Manual of string - | Api of string +type menu_file = Manual of string | Api of string let ref_menu_file : menu_file option ref = ref None let with_menu_file mf k = ignore - ( (!ref_menu_file >>= function - | Manual s | Api s -> Some s) - >>= fun s -> failwith @@ "menu_file " ^ s ^ "already set. Abort." ); + ( (!ref_menu_file >>= function Manual s | Api s -> Some s) >>= fun s -> + failwith @@ "menu_file " ^ s ^ "already set. Abort." ); ref_menu_file := Some mf; let r = k () in ref_menu_file := None; @@ -43,34 +40,29 @@ let using_menu_file k = !ref_menu_file <$> k let menu_file () = !ref_menu_file let manual_menu_file () = - !ref_menu_file >>= function - | Manual s -> Some s - | _ -> None - -let api_menu_file () = - !ref_menu_file >>= function - | Api s -> Some s - | _ -> None - -type cli_options = - { files : string list - ; print : bool - ; pretty : bool - ; headless : bool - ; local : bool - ; outfile : string option - ; suffix : string - ; project : string option - ; root : string - ; manual : string option - ; api : string option - ; default_subproject : string option - ; images : string option - ; assets : string option - ; template : string option - ; csw : string list - ; docversions : string list - } + !ref_menu_file >>= function Manual s -> Some s | _ -> None + +let api_menu_file () = !ref_menu_file >>= function Api s -> Some s | _ -> None + +type cli_options = { + files : string list; + print : bool; + pretty : bool; + headless : bool; + local : bool; + outfile : string option; + suffix : string; + project : string option; + root : string; + manual : string option; + api : string option; + default_subproject : string option; + images : string option; + assets : string option; + template : string option; + csw : string list; + docversions : string list; +} let ref_options : cli_options option ref = ref None @@ -95,9 +87,7 @@ let the_manual () = | None -> failwith "no manual given" let the_api () = - match (options ()).api with - | Some s -> s - | None -> failwith "no api given" + match (options ()).api with Some s -> s | None -> failwith "no api given" let the_images () = match (options ()).images with diff --git a/src/ohow/global.mli b/src/ohow/global.mli index 748492d..19ecfdf 100644 --- a/src/ohow/global.mli +++ b/src/ohow/global.mli @@ -1,97 +1,96 @@ +val with_current_file : string -> (unit -> 'a) -> 'a (** [with_current_file f k] sets the [current_file] to [f] and calls [k ()]. Unsets the [current_file] after [k] finishes and returns its value. *) -val with_current_file : string -> (unit -> 'a) -> 'a -(** [using_current_file k] calls [k @@ current_file ()] and returns its value. *) val using_current_file : (string -> 'a) -> 'a +(** [using_current_file k] calls [k @@ current_file ()] and returns its value. +*) -(** Returns the current file path. *) val current_file : unit -> string +(** Returns the current file path. *) (** Denotes the menu(.wiki) file currently being compiled. *) -type menu_file = - | Manual of string - | Api of string +type menu_file = Manual of string | Api of string +val with_menu_file : menu_file -> (unit -> 'a) -> 'a (** [with_menu_file mf k] sets the [menu_file] fo [mf] and calls [k ()]. Unsets the [menu_file] after [k] finishes and returns its value. *) -val with_menu_file : menu_file -> (unit -> 'a) -> 'a -(** [using_menu_file k] calls [k @@ menu_file ()] and returns its value. *) val using_menu_file : (menu_file -> 'a) -> 'a option +(** [using_menu_file k] calls [k @@ menu_file ()] and returns its value. *) -(** Returns the currently set [menu_file] or an error if none. *) val menu_file : unit -> menu_file option +(** Returns the currently set [menu_file] or an error if none. *) +val manual_menu_file : unit -> string option (** Returns [Some (menu_file ())] if [menu_file ()] is [Manual f] or [None] otherwise. *) -val manual_menu_file : unit -> string option +val api_menu_file : unit -> string option (** Returns [Some (menu_file ())] if [menu_file ()] is [Api f] or [None] otherwise. *) -val api_menu_file : unit -> string option +type cli_options = { + files : string list; + print : bool; + pretty : bool; + headless : bool; + local : bool; + outfile : string option; + suffix : string; + project : string option; + root : string; + manual : string option; + api : string option; + default_subproject : string option; + images : string option; + assets : string option; + template : string option; + csw : string list; + docversions : string list; +} (** A type containing the values of the CLI options accepted by ohow. *) -type cli_options = - { files : string list - ; print : bool - ; pretty : bool - ; headless : bool - ; local : bool - ; outfile : string option - ; suffix : string - ; project : string option - ; root : string - ; manual : string option - ; api : string option - ; default_subproject : string option - ; images : string option - ; assets : string option - ; template : string option - ; csw : string list - ; docversions : string list - } +val with_options : cli_options -> (unit -> 'a) -> 'a (** [with_options opts k] sets the [options] fo [opts] and calls [k ()]. Unsets the [options] after [k] finishes and returns its value. *) -val with_options : cli_options -> (unit -> 'a) -> 'a -(** [using_options k] calls [k @@ options ()] and returns its value. *) val using_options : (cli_options -> 'a) -> 'a +(** [using_options k] calls [k @@ options ()] and returns its value. *) -(** Returns the more recently set [cli_options]. *) val options : unit -> cli_options +(** Returns the more recently set [cli_options]. *) -(** Returns [(options ()).suffix]. *) val suffix : unit -> string +(** Returns [(options ()).suffix]. *) -(** Returns the value of [(options ()).manual] is any, or raises [Failure]. *) val the_manual : unit -> string +(** Returns the value of [(options ()).manual] is any, or raises [Failure]. *) -(** Returns the value of [(options ()).api] is any, or raises [Failure]. *) val the_api : unit -> string +(** Returns the value of [(options ()).api] is any, or raises [Failure]. *) -(** Returns the value of [(options ()).images] is any, or raises [Failure]. *) val the_images : unit -> string +(** Returns the value of [(options ()).images] is any, or raises [Failure]. *) -(** Returns the value of [(options ()).assets] is any, or raises [Failure]. *) val the_assets : unit -> string +(** Returns the value of [(options ()).assets] is any, or raises [Failure]. *) -(** Returns [(options ()).root]. *) val root : unit -> string +(** Returns [(options ()).root]. *) -(** Alias for [root ()]. *) val version_dir : unit -> string +(** Alias for [root ()]. *) +val project_dir : unit -> string (** Returns the absolute path to the project directory ([root]'s parent directory). *) -val project_dir : unit -> string +val all_projects_dir : unit -> string (** Returns the absolute path to the directory containing all projects ([project_dir]'s parent directory). *) -val all_projects_dir : unit -> string +val root_to_site : string ref (** The path to take from the project's root to end up in the website root (i.e., where the links [[site:x]] starts to). Defaults to [[""]]---the project's root is the website root. *) -val root_to_site : string ref diff --git a/src/ohow/import.ml b/src/ohow/import.ml index 10b73a9..11ae3a3 100644 --- a/src/ohow/import.ml +++ b/src/ohow/import.ml @@ -1,28 +1,11 @@ module Option = struct include Option - let bind ~f x = - match x with - | Some x -> f x - | None -> None - - let map ~f x = - match x with - | Some x -> Some (f x) - | None -> None - - let value x ~default = - match x with - | Some x -> x - | None -> default - - let is_some = function - | Some _ -> true - | None -> false - - let is_none = function - | Some _ -> false - | None -> true + let bind ~f x = match x with Some x -> f x | None -> None + let map ~f x = match x with Some x -> Some (f x) | None -> None + let value x ~default = match x with Some x -> x | None -> default + let is_some = function Some _ -> true | None -> false + let is_none = function Some _ -> false | None -> true end module String = struct @@ -33,8 +16,8 @@ module String = struct try let seppos = String.index s char in Some - ( String.trim (String.sub s 0 seppos) - , String.trim (String.sub s (seppos + 1) (len - seppos - 1)) ) + ( String.trim (String.sub s 0 seppos), + String.trim (String.sub s (seppos + 1) (len - seppos - 1)) ) with Not_found -> None let spaces = Re.rep1 Re.blank |> Re.compile @@ -42,10 +25,8 @@ module String = struct let remove_leading char s = let rec loop p = - if p >= String.length s - then "" - else if String.get s p = char - then loop (succ p) + if p >= String.length s then "" + else if String.get s p = char then loop (succ p) else String.sub s p (String.length s - p) in loop 0 @@ -75,10 +56,10 @@ let dir_files = sorted_dir_files (fun x -> x) let rec find_files name = function | file when Filename.basename file = name -> [ file ] | dir when try Sys.is_directory dir with Sys_error _ -> false -> - dir_files dir - |> List.map (fun f -> Paths.(dir +/+ f)) - |> List.map (find_files name) - |> List.concat + dir_files dir + |> List.map (fun f -> Paths.(dir +/+ f)) + |> List.map (find_files name) + |> List.concat | _ -> [] let uri_absolute = diff --git a/src/ohow/import.mli b/src/ohow/import.mli index 29f53ca..fe3290a 100644 --- a/src/ohow/import.mli +++ b/src/ohow/import.mli @@ -1,17 +1,17 @@ module Option : sig - (** Bind operator for the Maybe monad *) val bind : f:('a -> 'b option) -> 'a option -> 'b option + (** Bind operator for the Maybe monad *) - (** Map operator for the Maybe monad *) val map : f:('a -> 'b) -> 'a option -> 'b option + (** Map operator for the Maybe monad *) val value : 'a option -> default:'a -> 'a - (** [is_some x] returns whether [x] is [Some y]. *) val is_some : 'a option -> bool + (** [is_some x] returns whether [x] is [Some y]. *) - (** [is_none x] returns whether [x] is [None]. *) val is_none : 'a option -> bool + (** [is_none x] returns whether [x] is [None]. *) end module String : sig @@ -22,9 +22,9 @@ module String : sig val cut : char -> string -> (string * string) option val split_on_blank : string -> string list + val remove_leading : char -> string -> string (** [remove_leading c s] returns [s] with the trailing occurences of [c] removed. *) - val remove_leading : char -> string -> string end module List : sig @@ -41,28 +41,28 @@ end (** Defines general purpose operators. *) module Operators : sig - (** Bind operator for the Maybe monad *) val ( >>= ) : 'a option -> ('a -> 'b option) -> 'b option + (** Bind operator for the Maybe monad *) - (** Map operator for the Maybe monad *) val ( <$> ) : 'a option -> ('a -> 'b) -> 'b option + (** Map operator for the Maybe monad *) - (** Elvis operator *) val ( |? ) : 'a option -> 'a -> 'a + (** Elvis operator *) - (** Path concatenation operator. See module [Paths]. *) val ( +/+ ) : string -> string -> string + (** Path concatenation operator. See module [Paths]. *) end +val find_files : string -> string -> string list (** [find_files name dir] returns the paths to all the files with [name] recursively found inside [dir]. *) -val find_files : string -> string -> string list -(** [uri_absolute uri] returns whether [uri] is an absolute URI. *) val uri_absolute : string -> bool +(** [uri_absolute uri] returns whether [uri] is an absolute URI. *) -(** Reads and returns the lines inside the given file. *) val read_file_lines : string -> string list +(** Reads and returns the lines inside the given file. *) -(** Read all the content of file and returns it as a string. *) val read_file : string -> string +(** Read all the content of file and returns it as a string. *) diff --git a/src/ohow/links.ml b/src/ohow/links.ml index 573c1ca..fb1b576 100644 --- a/src/ohow/links.ml +++ b/src/ohow/links.ml @@ -9,117 +9,115 @@ let a_link_of_uri ?fragment suffix uri contents = let manual_link contents = function | [ project; chapter; fragment; Some version ] -> - let file = Global.current_file () in - let root, manual = Global.(root (), the_manual ()) in - let uri = - match (project, chapter) with - | Some p, Some c -> - Paths.( - rewind root file - (* inside this version dir *) - +/+ !Global.root_to_site - (* inside project dir *) - +/+ p - +/+ version +/+ manual +/+ c) - | Some p, None -> - Paths.(rewind root file +/+ !Global.root_to_site +/+ p +/+ "index.html") - | None, Some c -> Paths.(rewind root file +/+ manual +/+ c) - | None, None -> failwith "a_manual: no project nor chapter arg found" - in - let link = - match fragment with - | Some fragment -> a_link_of_uri ~fragment - | None -> a_link_of_uri ?fragment:None - in - [ link (Some (Global.suffix ())) uri contents ] + let file = Global.current_file () in + let root, manual = Global.(root (), the_manual ()) in + let uri = + match (project, chapter) with + | Some p, Some c -> + Paths.( + rewind root file + (* inside this version dir *) + +/+ !Global.root_to_site + (* inside project dir *) + +/+ p + +/+ version +/+ manual +/+ c) + | Some p, None -> + Paths.( + rewind root file +/+ !Global.root_to_site +/+ p +/+ "index.html") + | None, Some c -> Paths.(rewind root file +/+ manual +/+ c) + | None, None -> failwith "a_manual: no project nor chapter arg found" + in + let link = + match fragment with + | Some fragment -> a_link_of_uri ~fragment + | None -> a_link_of_uri ?fragment:None + in + [ link (Some (Global.suffix ())) uri contents ] | _ -> assert false let api_link prefix contents = function | project :: subproject :: text :: Some version :: (([] | [ _ ]) as kind_opt) -> - let kind = - match kind_opt with - | [ Some "odoc" ] -> `Odoc - | [ Some "ocamldoc" ] -> `Ocamldoc - | [ Some _ ] -> `Ocamldoc - | [ None ] | [] -> ( - let target_project = - match project with - | None -> (Global.options ()).project - | Some p -> Some p - in - match target_project with - | Some "js_of_ocaml" -> ( - match version with - | "latest" | "dev" -> `Odoc - | v -> - let v = Version.parse v in - if Version.compare v (Version.parse "3.5.0") < 0 - then `Ocamldoc - else `Odoc) - | Some _ -> `Ocamldoc - | None -> `Ocamldoc) - | _ :: _ :: _ -> assert false - in - let prefix = - match kind with - | `Odoc -> None - | `Ocamldoc -> prefix - in - let file = Global.current_file () in - let root, api = Global.(root (), the_api ()) in - let id = Api.parse_contents (contents <$> String.trim) in - let dsp = (Global.options ()).default_subproject in - let base = - match (project, subproject, dsp, kind) with - | Some p, Some s, _, _ -> - Paths.( - rewind root file +/+ !Global.root_to_site +/+ p +/+ version +/+ api - +/+ s) - | Some p, None, _, `Ocamldoc -> - Paths.( - rewind root file +/+ !Global.root_to_site +/+ p +/+ version +/+ api) - | Some p, None, _, `Odoc -> - Paths.( - rewind root file +/+ !Global.root_to_site +/+ p +/+ version +/+ api - +/+ p) - | None, Some s, _, _ | None, None, Some s, _ -> - Paths.(rewind root file +/+ api +/+ s) - | None, None, None, _ -> Paths.rewind root file +/+ api - in - let path_of_id = - match (kind, prefix) with - | `Ocamldoc, ((None | Some _) as prefix) -> - Api.Ocamldoc.path_of_id ?prefix id - | `Odoc, None -> Api.Odoc.path_of_id id - | `Odoc, Some _ -> assert false - in - let uri = Filename.concat base @@ path_of_id in - let fragment = - match kind with - | `Ocamldoc -> Api.Ocamldoc.fragment_of_id id - | `Odoc -> Api.Odoc.fragment_of_id id - in - let body = text |? Api.string_of_id ~spacer:"." id in - [ a_link_of_uri ?fragment (Some (Global.suffix ())) uri (Some body) ] + let kind = + match kind_opt with + | [ Some "odoc" ] -> `Odoc + | [ Some "ocamldoc" ] -> `Ocamldoc + | [ Some _ ] -> `Ocamldoc + | [ None ] | [] -> ( + let target_project = + match project with + | None -> (Global.options ()).project + | Some p -> Some p + in + match target_project with + | Some "js_of_ocaml" -> ( + match version with + | "latest" | "dev" -> `Odoc + | v -> + let v = Version.parse v in + if Version.compare v (Version.parse "3.5.0") < 0 then + `Ocamldoc + else `Odoc) + | Some _ -> `Ocamldoc + | None -> `Ocamldoc) + | _ :: _ :: _ -> assert false + in + let prefix = match kind with `Odoc -> None | `Ocamldoc -> prefix in + let file = Global.current_file () in + let root, api = Global.(root (), the_api ()) in + let id = Api.parse_contents (contents <$> String.trim) in + let dsp = (Global.options ()).default_subproject in + let base = + match (project, subproject, dsp, kind) with + | Some p, Some s, _, _ -> + Paths.( + rewind root file +/+ !Global.root_to_site +/+ p +/+ version + +/+ api +/+ s) + | Some p, None, _, `Ocamldoc -> + Paths.( + rewind root file +/+ !Global.root_to_site +/+ p +/+ version + +/+ api) + | Some p, None, _, `Odoc -> + Paths.( + rewind root file +/+ !Global.root_to_site +/+ p +/+ version + +/+ api +/+ p) + | None, Some s, _, _ | None, None, Some s, _ -> + Paths.(rewind root file +/+ api +/+ s) + | None, None, None, _ -> Paths.rewind root file +/+ api + in + let path_of_id = + match (kind, prefix) with + | `Ocamldoc, ((None | Some _) as prefix) -> + Api.Ocamldoc.path_of_id ?prefix id + | `Odoc, None -> Api.Odoc.path_of_id id + | `Odoc, Some _ -> assert false + in + let uri = Filename.concat base @@ path_of_id in + let fragment = + match kind with + | `Ocamldoc -> Api.Ocamldoc.fragment_of_id id + | `Odoc -> Api.Odoc.fragment_of_id id + in + let body = text |? Api.string_of_id ~spacer:"." id in + [ a_link_of_uri ?fragment (Some (Global.suffix ())) uri (Some body) ] | _ -> assert false let img_link _contents = function | [ Some src ] -> - let file = Global.current_file () in - let root, images = Global.(root (), the_images ()) in - let uri = Paths.(rewind root file +/+ images +/+ src) in - let alt = Filename.basename src in - [ Html.img ~src:uri ~alt () ] + let file = Global.current_file () in + let root, images = Global.(root (), the_images ()) in + let uri = Paths.(rewind root file +/+ images +/+ src) in + let alt = Filename.basename src in + [ Html.img ~src:uri ~alt () ] | [ None ] -> failwith "a_img: no src argument error" | _ -> assert false let file_link contents = function | [ Some src ] -> - let file = Global.current_file () in - let root, assets = Global.(root (), the_assets ()) in - let uri = Paths.(rewind root file +/+ assets +/+ src) in - [ a_link_of_uri None uri (Some (contents |? Filename.basename uri)) ] + let file = Global.current_file () in + let root, assets = Global.(root (), the_assets ()) in + let uri = Paths.(rewind root file +/+ assets +/+ src) in + [ a_link_of_uri None uri (Some (contents |? Filename.basename uri)) ] | [ None ] -> failwith "a_file: no src argument error" | _ -> assert false diff --git a/src/ohow/menu.ml b/src/ohow/menu.ml index 190ee33..e4801ee 100644 --- a/src/ohow/menu.ml +++ b/src/ohow/menu.ml @@ -19,29 +19,27 @@ let doctree _ args _ = Global.( match mf with | Manual _ -> - Document.Project - { page = Manual ""; project = ""; version = Version.Dev } + Document.Project + { page = Manual ""; project = ""; version = Version.Dev } | Api _ -> - Document.Project - { page = Api { subproject = None; file = "" } - ; project = "" - ; version = Version.Dev - }) + Document.Project + { + page = Api { subproject = None; file = "" }; + project = ""; + version = Version.Dev; + }) in Wiki_widgets_interface. - { bi_page - ; bi_sectioning = true - ; bi_add_link = ignore - ; bi_content = [] - ; bi_title = "" + { + bi_page; + bi_sectioning = true; + bi_add_link = ignore; + bi_content = []; + bi_title = ""; } in let compile_with_menu_file mf = - let f = - Global.( - match mf with - | Manual f | Api f -> f) - in + let f = Global.(match mf with Manual f | Api f -> f) in let bi = bi_of_menu_file mf in Global.(with_menu_file mf (fun () -> compile bi f)) in @@ -80,13 +78,14 @@ let docversion _bi args _contents = (txt v)) in `Flow5 - [ txt "Version " - ; select + [ + txt "Version "; + select ~a: (a_class [ "how-versions" ] :: a_onchange "location = this.value;" :: attrs) - links + links; ] let init () = diff --git a/src/ohow/ohow.ml b/src/ohow/ohow.ml index 040ee4f..a9d5600 100644 --- a/src/ohow/ohow.ml +++ b/src/ohow/ohow.ml @@ -20,45 +20,41 @@ let build_page file content = let rec f = function | [] -> None | x :: t -> ( - match Tyxml_xml.content x with - | Tyxml_xml.Node ("h1", _, title) -> - List.map flatten title |> List.flatten - |> List.map (Format.asprintf "%a" (Tyxml_xml.pp ())) - |> String.concat "" - |> fun t -> Some t - (* the first one, depth first *) - | Tyxml_xml.Node (_, _, children) -> ( - match f children with - | Some _title as r -> r (* return the first one *) - | None -> f t (* not found among children, try with the siblings *)) - | _ -> None) + match Tyxml_xml.content x with + | Tyxml_xml.Node ("h1", _, title) -> + List.map flatten title |> List.flatten + |> List.map (Format.asprintf "%a" (Tyxml_xml.pp ())) + |> String.concat "" + |> fun t -> Some t + (* the first one, depth first *) + | Tyxml_xml.Node (_, _, children) -> ( + match f children with + | Some _title as r -> r (* return the first one *) + | None -> + f t (* not found among children, try with the siblings *)) + | _ -> None) (* not found at all *) in f @@ List.map Tyxml_html.toelt blocks in - let ti = - match extract_h1 content with - | Some s -> s - | None -> "" - in + let ti = match extract_h1 content with Some s -> s | None -> "" in let a_cl = file - :: - (match (Global.options ()).project with - | Some p -> [ p ] - | None -> []) + :: (match (Global.options ()).project with Some p -> [ p ] | None -> []) in Tyxml.Html.( html (head (title (txt ti)) - ([ meta ~a:[ a_charset "utf8" ] () - ; meta + ([ + meta ~a:[ a_charset "utf8" ] (); + meta ~a: - [ a_content "width=device-width, initial-scale=1" - ; a_name "viewport" + [ + a_content "width=device-width, initial-scale=1"; + a_name "viewport"; ] - () + (); ] @ Site_ocsimore.(List.map make_css @@ List.rev !css_links) @ Site_ocsimore.(List.map make_script @@ List.rev !head_scripts))) @@ -77,11 +73,10 @@ let ohow ~indent file oc = ( ( file |> read_file |> fun wiki -> match (Global.options ()).template with | Some template -> - read_file template |> Wiki_syntax.compile_with_content wiki + read_file template |> Wiki_syntax.compile_with_content wiki | None -> Wiki_syntax.compile wiki ) |> fun c -> - if (Global.options ()).headless - then List.iter (pprint ~indent oc) c + if (Global.options ()).headless then List.iter (pprint ~indent oc) c else pprint ~indent oc (build_page (Filename.basename (infer_wiki_name file)) c) ); @@ -106,26 +101,27 @@ let init_extensions () = Site_ocsimore.init () let main - { Global.print - ; pretty - ; headless - ; outfile - ; suffix - ; project - ; root - ; manual - ; api - ; default_subproject - ; images - ; assets - ; template - ; csw - ; docversions - ; local - ; files + { + Global.print; + pretty; + headless; + outfile; + suffix; + project; + root; + manual; + api; + default_subproject; + images; + assets; + template; + csw; + docversions; + local; + files; } = - if not (List.for_all Sys.file_exists files) - then failwith "Some input files doesn't exist..."; + if not (List.for_all Sys.file_exists files) then + failwith "Some input files doesn't exist..."; init_extensions (); let root = Paths.realpath root in let relative_to_root p = @@ -136,23 +132,24 @@ let main let images = images <$> relative_to_root in let assets = assets <$> relative_to_root in let opts = - { Global.print - ; pretty - ; headless - ; outfile - ; suffix - ; project - ; root - ; manual - ; api - ; default_subproject - ; images - ; assets - ; template - ; csw - ; docversions - ; local - ; files + { + Global.print; + pretty; + headless; + outfile; + suffix; + project; + root; + manual; + api; + default_subproject; + images; + assets; + template; + csw; + docversions; + local; + files; } in (match Sys.getenv_opt "HOW_IN_PROJECT" with diff --git a/src/ohow/paths.ml b/src/ohow/paths.ml index 6f77409..d025cd6 100644 --- a/src/ohow/paths.ml +++ b/src/ohow/paths.ml @@ -27,15 +27,13 @@ let rewind dir file = let rec rew = function | p when path_eql p dir -> "." | "." | "/" -> - failwith @@ "rewind: " ^ file ^ " cannot be rewinded to dir " ^ dir + failwith @@ "rewind: " ^ file ^ " cannot be rewinded to dir " ^ dir | p -> Filename.concat ".." @@ rew @@ Filename.dirname p in file |> realpath |> Filename.dirname |> rew let is_inside_dir dir file = - match rewind dir file with - | _ -> true - | exception Failure _ -> false + match rewind dir file with _ -> true | exception Failure _ -> false let rec remove_prefixl l l' = match (l, l') with @@ -47,10 +45,7 @@ let path_rm_prefix prefix p = (* works the other way round ;) *) remove_prefixl (list_of_path prefix) (list_of_path p) |> path_of_list -let is_visible = function - | "" -> false - | f -> f.[0] <> '.' - +let is_visible = function "" -> false | f -> f.[0] <> '.' let is_visible_dir d = Sys.is_directory d && is_visible d let concat_uri_suffix suffix = function diff --git a/src/ohow/paths.mli b/src/ohow/paths.mli index 13bc3a5..03dd43d 100644 --- a/src/ohow/paths.mli +++ b/src/ohow/paths.mli @@ -1,45 +1,48 @@ val up : string val here : string -(** Operator for [Filename.concat]. *) val ( +/+ ) : string -> string -> string +(** Operator for [Filename.concat]. *) -(** Concatenates the paths together in one single path *) val path_of_list : string list -> string +(** Concatenates the paths together in one single path *) -(** Splits the given path in a list of basenames *) val list_of_path : string -> string list +(** Splits the given path in a list of basenames *) -(** Returns the absolute path of the given path (returns it if already absolute) *) val realpath : string -> string +(** Returns the absolute path of the given path (returns it if already absolute) +*) -(** Checks whether two absolute path or two relative path are equal. *) val path_eql : string -> string -> bool +(** Checks whether two absolute path or two relative path are equal. *) +val rewind : string -> string -> string (** [rewind dir file] returns the relative path to take to go back from file's directory to dir directory. Example: [rewind "foo/" "foo/bar/f.txt"] => "../../" *) -val rewind : string -> string -> string -(** [is_inside_dir dir file] returns whether [file] is located inside [dir]. *) val is_inside_dir : string -> string -> bool +(** [is_inside_dir dir file] returns whether [file] is located inside [dir]. *) -(** [remove_prefixl l l'] returns the l or l' with the prefix l' or l removed. *) val remove_prefixl : 'a list -> 'a list -> 'a list +(** [remove_prefixl l l'] returns the l or l' with the prefix l' or l removed. +*) -(** Does the same work thab remove_prefixl but for paths. *) val path_rm_prefix : string -> string -> string +(** Does the same work thab remove_prefixl but for paths. *) -(** [is_visible d] returns whether [d] is a visible file (unix only). *) val is_visible : string -> bool +(** [is_visible d] returns whether [d] is a visible file (unix only). *) -(** [is_visible_dir d] returns whether [d] is a visible directory (unix only). *) val is_visible_dir : string -> bool +(** [is_visible_dir d] returns whether [d] is a visible directory (unix only). +*) +val concat_uri_suffix : string -> string -> string (** [concat_uri_suffix s u] concatenates [u] with [s] if [u] doesn't ends with a ['/']. Raises [Failure] when [u] is [""]. *) -val concat_uri_suffix : string -> string -> string +val apply_path : string -> string (** [apply_path p] returns the path [p] without [..]s and [.]s. Example: [apply_path "a//../b/.//./c/.." = "b"] *) -val apply_path : string -> string diff --git a/src/ohow/site_ocsimore.ml b/src/ohow/site_ocsimore.ml index a73b84f..82e3a8b 100644 --- a/src/ohow/site_ocsimore.ml +++ b/src/ohow/site_ocsimore.ml @@ -22,13 +22,12 @@ open Operators (*****************************************************************************) (** Extension script *) -type script_kind = - | Src of string - | Js of string +type script_kind = Src of string | Js of string let make_script = function | Src src -> - Html.(script ~a:[ a_script_type `Javascript; a_src src ] (cdata_script "")) + Html.( + script ~a:[ a_script_type `Javascript; a_src src ] (cdata_script "")) | Js js -> Html.(script ~a:[ a_script_type `Javascript ] (cdata_script js)) let process_script args c = @@ -48,9 +47,7 @@ let do_head_script _ args c = (*****************************************************************************) (** Extension css *) -type css_kind = - | Href of string - | Css of string +type css_kind = Href of string | Css of string let make_css = function | Href href -> Html.(link ~rel:[ `Stylesheet ] ~href ()) @@ -84,9 +81,10 @@ let do_wip _bi _args xml = | None -> [] in Html. - [ aside + [ + aside ~a:[ a_class [ "wip" ] ] - (header [ h5 [ txt "Work in progress" ] ] :: xml) + (header [ h5 [ txt "Work in progress" ] ] :: xml); ]) let do_wip_inline _bi args xml = @@ -111,9 +109,10 @@ let do_concepts _bi args xml = in let attrs = Wiki_syntax.parse_common_attribs args in Html. - [ aside + [ + aside ~a:(a_class [ "concepts" ] :: attrs) - (header [ h5 [ txt "Concepts" ] ] :: xml) + (header [ h5 [ txt "Concepts" ] ] :: xml); ]) (* Concept *) @@ -131,15 +130,18 @@ let do_concept bi args xml = let t = get_title bi args in let attrs = Wiki_syntax.parse_common_attribs args in Html. - [ aside + [ + aside ~a:(a_class [ "concept" ] :: attrs) (header - [ h5 - [ span ~a:[ a_class [ "concept_prefix" ] ] [ txt "Concept: " ] - ; txt t - ] + [ + h5 + [ + span ~a:[ a_class [ "concept_prefix" ] ] [ txt "Concept: " ]; + txt t; + ]; ] - :: xml) + :: xml); ]) (*****************************************************************************) @@ -147,11 +149,7 @@ let do_concept bi args xml = let do_paragraph _bi args xml = `Flow5 - (let xml = - match xml with - | Some c -> (c :> _ Html.elt list) - | None -> [] - in + (let xml = match xml with Some c -> (c :> _ Html.elt list) | None -> [] in let attrs = Wiki_syntax.parse_common_attribs args in Html.[ div ~a:(a_class [ "paragraph" ] :: attrs) xml ]) @@ -162,49 +160,57 @@ let do_client_server_switch _ args _ = match (Global.options ()).api with | None -> `Flow5 [] | Some api -> - let client = "client" in - let server = "server" in - let { Global.csw; root; _ } = Global.options () in - let file = Global.current_file () in - let attrs = Wiki_syntax.parse_common_attribs args in - let is_api = Paths.(is_inside_dir (root +/+ api) file) in - let is_client = Paths.(is_inside_dir (root +/+ api +/+ client) file) in - let is_server = Paths.(is_inside_dir (root +/+ api +/+ server) file) in - let wiki = Filename.basename file in - let make_switch = function - | None -> [] - | Some other -> - let html = Filename.chop_extension wiki ^ Global.suffix () in - let href = Paths.(rewind (root +/+ api) file +/+ other +/+ html) in - let checked = if other = server then [ Html.a_checked () ] else [] in - let onchange = "location = '" ^ href ^ "';" in - Html. - [ label - ~a:(a_class [ "csw-switch" ] :: attrs) - [ input - ~a:([ a_input_type `Checkbox; a_onchange onchange ] @ checked) - () - ; span - ~a:[ a_class [ "csw-slider"; "csw-slider-style-round" ] ] - [] - ; span ~a:[ a_class [ "csw-slider-no" ] ] [ txt "Server version" ] - ; span - ~a:[ a_class [ "csw-slider-yes" ] ] - [ txt "Client version" ] + let client = "client" in + let server = "server" in + let { Global.csw; root; _ } = Global.options () in + let file = Global.current_file () in + let attrs = Wiki_syntax.parse_common_attribs args in + let is_api = Paths.(is_inside_dir (root +/+ api) file) in + let is_client = Paths.(is_inside_dir (root +/+ api +/+ client) file) in + let is_server = Paths.(is_inside_dir (root +/+ api +/+ server) file) in + let wiki = Filename.basename file in + let make_switch = function + | None -> [] + | Some other -> + let html = Filename.chop_extension wiki ^ Global.suffix () in + let href = Paths.(rewind (root +/+ api) file +/+ other +/+ html) in + let checked = + if other = server then [ Html.a_checked () ] else [] + in + let onchange = "location = '" ^ href ^ "';" in + Html. + [ + label + ~a:(a_class [ "csw-switch" ] :: attrs) + [ + input + ~a: + ([ a_input_type `Checkbox; a_onchange onchange ] + @ checked) + (); + span + ~a:[ a_class [ "csw-slider"; "csw-slider-style-round" ] ] + []; + span + ~a:[ a_class [ "csw-slider-no" ] ] + [ txt "Server version" ]; + span + ~a:[ a_class [ "csw-slider-yes" ] ] + [ txt "Client version" ]; + ]; ] - ] - in - let make = function - | [] -> [] - | wikis when is_api && List.exists (fun s -> s = wiki) wikis -> ( - match (is_client, is_server) with - | true, false -> make_switch @@ Some server - | false, true -> make_switch @@ Some client - | false, false -> make_switch None - | _, _ -> assert false) - | _ -> [] - in - `Flow5 (make csw) + in + let make = function + | [] -> [] + | wikis when is_api && List.exists (fun s -> s = wiki) wikis -> ( + match (is_client, is_server) with + | true, false -> make_switch @@ Some server + | false, true -> make_switch @@ Some client + | false, false -> make_switch None + | _, _ -> assert false) + | _ -> [] + in + `Flow5 (make csw) (*****************************************************************************) (** Extension google search *) @@ -221,28 +227,32 @@ let do_google_search _ args _ = | None -> failwith "googlesearch: must provide an \"domain\"" in Html. - [ form + [ + form ~a:[ a_id "googlesearch"; a_action "https://google.com/search" ] - [ input + [ + input ~a: - [ a_name "q" - ; a_id "gsearch-box" - ; a_placeholder "Search using Google" + [ + a_name "q"; + a_id "gsearch-box"; + a_placeholder "Search using Google"; ] - () - ; label + (); + label ~a:[ a_label_for "gsearch-box" ] - [ img ~src:image ~alt:"" ~a:[ a_id "gsearch-icon" ] () ] - ; input + [ img ~src:image ~alt:"" ~a:[ a_id "gsearch-icon" ] () ]; + input ~a: - [ a_input_type `Submit - ; a_id "gsearch-submit" - ; a_onclick + [ + a_input_type `Submit; + a_id "gsearch-submit"; + a_onclick @@ "document.getElementById('gsearch-box').value += ' site:" - ^ domain ^ "';" + ^ domain ^ "';"; ] - () - ] + (); + ]; ] |> fun x -> `Flow5 x diff --git a/src/ohow/version.ml b/src/ohow/version.ml index 53a4240..9623571 100644 --- a/src/ohow/version.ml +++ b/src/ohow/version.ml @@ -1,25 +1,23 @@ open Import -type t = - | Dev - | V of string * int list * string option +type t = Dev | V of string * int list * string option let parse s = match s with | "dev" -> Dev | s -> ( - try - let s', extra = - match String.split_on_char '+' s with - | [] -> assert false - | [ _ ] -> (s, None) - | [ x; extra ] -> (x, Some extra) - | _ -> assert false - in - let l = String.split_on_char '.' s' in - let l = List.map int_of_string l in - V (s, l, extra) - with _ -> assert false) + try + let s', extra = + match String.split_on_char '+' s with + | [] -> assert false + | [ _ ] -> (s, None) + | [ x; extra ] -> (x, Some extra) + | _ -> assert false + in + let l = String.split_on_char '.' s' in + let l = List.map int_of_string l in + V (s, l, extra) + with _ -> assert false) let compint (a : int) b = compare a b @@ -29,19 +27,15 @@ let compare v v' = | Dev, _ -> 1 | _, Dev -> -1 | V (_, v, _), V (_, v', _) -> - let rec cmp v v' = - match (v, v') with - | [ x ], [ y ] -> compint x y - | [], [] -> 0 - | [], y :: _ -> compint 0 y - | x :: _, [] -> compint x 0 - | x :: xs, y :: ys -> ( - match compint x y with - | 0 -> cmp xs ys - | n -> n) - in - cmp v v' + let rec cmp v v' = + match (v, v') with + | [ x ], [ y ] -> compint x y + | [], [] -> 0 + | [], y :: _ -> compint 0 y + | x :: _, [] -> compint x 0 + | x :: xs, y :: ys -> ( + match compint x y with 0 -> cmp xs ys | n -> n) + in + cmp v v' -let to_string = function - | Dev -> "dev" - | V (s, _, _) -> s +let to_string = function Dev -> "dev" | V (s, _, _) -> s diff --git a/src/ohow/version.mli b/src/ohow/version.mli index 488f4cf..9b7e17b 100644 --- a/src/ohow/version.mli +++ b/src/ohow/version.mli @@ -1,6 +1,4 @@ -type t = - | Dev - | V of string * int list * string option +type t = Dev | V of string * int list * string option val to_string : t -> string val parse : string -> t diff --git a/src/ohow/wiki_ext.ml b/src/ohow/wiki_ext.ml index 0f297fc..b9655d2 100644 --- a/src/ohow/wiki_ext.ml +++ b/src/ohow/wiki_ext.ml @@ -34,14 +34,14 @@ let do_outline wp bi args c = match c with | None -> [] | Some c -> - (Wiki_syntax.xml_of_wiki wp bi c :> Html_types.flow5 Html.elt list) + (Wiki_syntax.xml_of_wiki wp bi c :> Html_types.flow5 Html.elt list) in let ignore = match List.Assoc.get_opt args "ignore" with | None -> [ "nav"; "aside" ] | Some x -> - String.split_on_char ' ' x - |> List.map (fun x -> String.trim x |> String.lowercase_ascii) + String.split_on_char ' ' x + |> List.map (fun x -> String.trim x |> String.lowercase_ascii) in let div = (elem = `Container && not bi.Wiki_widgets_interface.bi_sectioning) @@ -80,37 +80,33 @@ let f_link _bi args c = match c with | Some c -> c | None -> ( - match page with - | Some page -> [ Html.txt page ] - | None -> failwith "extension:link: cannot infer text for link") + match page with + | Some page -> [ Html.txt page ] + | None -> failwith "extension:link: cannot infer text for link") in (* class and id attributes will be taken by Wiki_syntax.a_elem *) ( Wiki_syntax_types.Absolute (match href with | Some href -> - (match (wiki, page, fragment) with - | None, None, None -> () - | _ -> - failwith - "extension:link: wiki, page and fragment arguments cannot be used \ - together with href"); - href + (match (wiki, page, fragment) with + | None, None, None -> () + | _ -> + failwith + "extension:link: wiki, page and fragment arguments cannot be \ + used together with href"); + href | None -> - let fragment = - match fragment with - | None -> "" - | Some f -> "#" ^ f - in - let url = - match (wiki, page) with - | None, None -> "/" - | Some wiki, Some page -> Printf.sprintf "/%s/%s" wiki page - | Some wiki, None -> Printf.sprintf "/%s/" wiki - | None, Some page -> Printf.sprintf "/%s" page - in - url ^ fragment) - , args - , content ) + let fragment = match fragment with None -> "" | Some f -> "#" ^ f in + let url = + match (wiki, page) with + | None, None -> "/" + | Some wiki, Some page -> Printf.sprintf "/%s/%s" wiki page + | Some wiki, None -> Printf.sprintf "/%s/" wiki + | None, Some page -> Printf.sprintf "/%s" page + in + url ^ fragment), + args, + content ) let do_drawer wp bi args c = let open Html in @@ -119,7 +115,7 @@ let do_drawer wp bi args c = let content = match c with | Some c -> - (Wiki_syntax.xml_of_wiki wp bi c :> Html_types.flow5 Html.elt list) + (Wiki_syntax.xml_of_wiki wp bi c :> Html_types.flow5 Html.elt list) | None -> [] in let button = @@ -145,16 +141,16 @@ let do_when_project _ _ args c = | [ Some p; None ] -> (p, ( = )) | [ None; Some p ] -> (p, ( <> )) | [ None; None ] -> - fail "required arguments missing: \"when\" or \"unless\"" + fail "required arguments missing: \"when\" or \"unless\"" | [ Some _; Some _ ] -> - fail "mutually incompatible arguments provided: \"when\", \"unless\"" + fail "mutually incompatible arguments provided: \"when\", \"unless\"" | _ -> fail "unexpected argument list provided" in (Global.options ()).project >>= (fun current -> - if predicate project current - then Some (`Flow5 (c <$> Wiki_syntax.compile |? [])) - else None) + if predicate project current then + Some (`Flow5 (c <$> Wiki_syntax.compile |? [])) + else None) |? `Flow5 [] let do_when_local _ _ _ c = @@ -165,8 +161,7 @@ let do_when_local _ _ _ c = let do_unless_local _ _ _ c = let open Operators in `Flow5 - (if not (Global.options ()).local - then c <$> Wiki_syntax.compile |? [] + (if not (Global.options ()).local then c <$> Wiki_syntax.compile |? [] else []) let init () = diff --git a/src/ohow/wiki_models.mli b/src/ohow/wiki_models.mli index 22f80ed..5f5be60 100644 --- a/src/ohow/wiki_models.mli +++ b/src/ohow/wiki_models.mli @@ -22,23 +22,23 @@ type wiki_preprocessor = (module Wiki_syntax_types.Preprocessor) val identity_preprocessor : wiki_preprocessor -(** See [Wiki_syntax_types.Preprocessor.preparse_string] *) val preparse_string : - ?href_action:Wiki_syntax_types.link_action - -> ?link_action:Wiki_syntax_types.link_action - -> wiki_preprocessor - -> Wiki_types.wikibox - -> string - -> string + ?href_action:Wiki_syntax_types.link_action -> + ?link_action:Wiki_syntax_types.link_action -> + wiki_preprocessor -> + Wiki_types.wikibox -> + string -> + string +(** See [Wiki_syntax_types.Preprocessor.preparse_string] *) -(** See [Wiki_syntax_types.Preprocessor.desugar_string] *) val desugar_string : - ?href_action:Wiki_syntax_types.link_action - -> ?link_action:Wiki_syntax_types.link_action - -> wiki_preprocessor - -> Wiki_syntax_types.desugar_param - -> string - -> string + ?href_action:Wiki_syntax_types.link_action -> + ?link_action:Wiki_syntax_types.link_action -> + wiki_preprocessor -> + Wiki_syntax_types.desugar_param -> + string -> + string +(** See [Wiki_syntax_types.Preprocessor.desugar_string] *) type +'res wiki_parser = Wiki_widgets_interface.box_info -> string -> 'res diff --git a/src/ohow/wiki_syntax.ml b/src/ohow/wiki_syntax.ml index 4a5319a..9f31bdd 100644 --- a/src/ohow/wiki_syntax.ml +++ b/src/ohow/wiki_syntax.ml @@ -32,14 +32,10 @@ let class_wikibox wb = Printf.sprintf "wikiboxcontent%s" (string_of_wikibox wb) let string_of_extension name args content = "<<" ^ name ^ " " ^ String.concat " " (List.map (fun (n, v) -> n ^ "=\"" ^ v ^ "\"") args) - ^ (match content with - | None -> "" - | Some content -> "|" ^ content) + ^ (match content with None -> "" | Some content -> "|" ^ content) ^ ">>" -let opt_of_list = function - | [] -> None - | _ :: _ as l -> Some l +let opt_of_list = function [] -> None | _ :: _ as l -> Some l (***) @@ -49,9 +45,7 @@ let rec filter_raw = function | None :: xs -> filter_raw xs | Some x :: xs -> x :: filter_raw xs -let unopt ~def = function - | None -> def - | Some x -> x +let unopt ~def = function None -> def | Some x -> x let parse_common_attribs ?classes attribs = let at1 = @@ -71,8 +65,8 @@ let parse_common_attribs ?classes attribs = List.fold_left (fun l (n, v) -> try - if String.sub n 0 5 = "data-" - then Html.a_user_data (String.sub n 5 (String.length n - 5)) v :: l + if String.sub n 0 5 = "data-" then + Html.a_user_data (String.sub n 5 (String.length n - 5)) v :: l else l with Invalid_argument _ -> l) [] attribs @@ -112,15 +106,15 @@ let list_builder xs = match xs with | [] -> (Html.li [], []) | x :: xs -> - let y = item_builder x in - let ys = List.map item_builder xs in - (y, ys) + let y = item_builder x in + let ys = List.map item_builder xs in + (y, ys) let ddt_builder (istitle, (d : Html_types.phrasing Html.elt list list), attribs) = let a = opt_of_list (parse_common_attribs attribs) in - if istitle - then Html.dt ?a (List.flatten d :> Html_types.dt_content_fun Html.elt list) + if istitle then + Html.dt ?a (List.flatten d :> Html_types.dt_content_fun Html.elt list) else Html.dd ?a (List.flatten d @@ -175,14 +169,14 @@ let wiki_kind prot page = match Re.Pcre.exec ~rex prot with | exception Not_found -> failwith @@ "ill formed wiki prototype: " ^ prot | groups -> ( - match Re.Pcre.get_substring groups 1 with - | id when is_number id -> failwith "ids not supported anymore" - | wiki -> - let wiki = extract_wiki_name wiki in - let file = Global.current_file () in - let root = Global.root () in - Absolute - Paths.(rewind root file +/+ !Global.root_to_site +/+ wiki +/+ page)) + match Re.Pcre.get_substring groups 1 with + | id when is_number id -> failwith "ids not supported anymore" + | wiki -> + let wiki = extract_wiki_name wiki in + let file = Global.current_file () in + let root = Global.root () in + Absolute + Paths.(rewind root file +/+ !Global.root_to_site +/+ wiki +/+ page)) let this_wiki_kind _prot page = let file = Global.current_file () in @@ -192,54 +186,54 @@ let this_wiki_kind _prot page = let link_kind _bi addr = match deabbrev_address addr |> String.split_on_char ':' with | p :: rest -> ( - let page = String.concat ":" rest in - (* the page may contain ':' *) - match p with - | "href" -> - let menu_page = - Global.using_menu_file (fun mf -> - let open Operators in - let { Global.root; manual; api; _ } = Global.options () in - let file = Global.current_file () in - let is_manual = - manual - <$> (fun m -> Paths.(is_inside_dir (root +/+ m) file)) - |? false - in - let is_api = - api - <$> (fun a -> Paths.(is_inside_dir (root +/+ a) file)) - |? false - in - let manual, api = (manual |? "", api |? "") in - match mf with - | Manual _ when is_manual -> page - | Api _ when is_api -> Paths.(rewind root file +/+ api +/+ page) - | Manual _ when is_api -> - Paths.(rewind root file +/+ manual +/+ page) - | _ (* api when is_manual *) -> - Paths.(rewind root file +/+ api +/+ page)) - in - Absolute - (let open Operators in - menu_page |? page) - | "site" -> - let file = Global.current_file () in - let root = Global.root () in - Absolute - Paths.( - rewind root file +/+ !Global.root_to_site - +/+ String.remove_leading '/' page) - | p when starts_with "wiki(" p -> wiki_kind p page - | p when starts_with "wiki" p -> this_wiki_kind p page - | _ -> failwith @@ "unknown prototype: '" ^ p ^ "'") + let page = String.concat ":" rest in + (* the page may contain ':' *) + match p with + | "href" -> + let menu_page = + Global.using_menu_file (fun mf -> + let open Operators in + let { Global.root; manual; api; _ } = Global.options () in + let file = Global.current_file () in + let is_manual = + manual + <$> (fun m -> Paths.(is_inside_dir (root +/+ m) file)) + |? false + in + let is_api = + api + <$> (fun a -> Paths.(is_inside_dir (root +/+ a) file)) + |? false + in + let manual, api = (manual |? "", api |? "") in + match mf with + | Manual _ when is_manual -> page + | Api _ when is_api -> Paths.(rewind root file +/+ api +/+ page) + | Manual _ when is_api -> + Paths.(rewind root file +/+ manual +/+ page) + | _ (* api when is_manual *) -> + Paths.(rewind root file +/+ api +/+ page)) + in + Absolute + (let open Operators in + menu_page |? page) + | "site" -> + let file = Global.current_file () in + let root = Global.root () in + Absolute + Paths.( + rewind root file +/+ !Global.root_to_site + +/+ String.remove_leading '/' page) + | p when starts_with "wiki(" p -> wiki_kind p page + | p when starts_with "wiki" p -> this_wiki_kind p page + | _ -> failwith @@ "unknown prototype: '" ^ p ^ "'") | _ -> failwith @@ "ill formed link: '" ^ addr ^ "'" let href_of_link_kind bi addr fragment = match link_kind bi addr with | Absolute a as h -> - let open Operators in - fragment <$> (fun f -> Absolute Paths.(a +/+ ("#" ^ f))) |? h + let open Operators in + fragment <$> (fun f -> Absolute Paths.(a +/+ ("#" ^ f))) |? h | _ -> assert false (** **) @@ -256,9 +250,7 @@ open Wiki_syntax_types.ExtParser let cast_wp (type a b c) wp = let module P = (val wp - : ExtParser - with type res = a - and type res_without_interactive = b + : ExtParser with type res = a and type res_without_interactive = b and type link_content = c) in (module P : Parser with type res = a) @@ -267,9 +259,7 @@ let cast_wp (type a b c) wp = let cast_niwp (type a b c) wp = let module P = (val wp - : ExtParser - with type res = a - and type res_without_interactive = b + : ExtParser with type res = a and type res_without_interactive = b and type link_content = c) in (module struct @@ -284,9 +274,7 @@ let cast_niwp (type a b c) wp = let get_plugin_resolver (type a b c) wp = let module P = (val wp - : ExtParser - with type res = a - and type res_without_interactive = b + : ExtParser with type res = a and type res_without_interactive = b and type link_content = c) in P.plugin_resolver @@ -294,9 +282,7 @@ let get_plugin_resolver (type a b c) wp = let preparse_string (type a b c) wp = let module P = (val wp - : ExtParser - with type res = a - and type res_without_interactive = b + : ExtParser with type res = a and type res_without_interactive = b and type link_content = c) in P.preparse_string @@ -304,9 +290,7 @@ let preparse_string (type a b c) wp = let desugar_string (type a b c) wp = let module P = (val wp - : ExtParser - with type res = a - and type res_without_interactive = b + : ExtParser with type res = a and type res_without_interactive = b and type link_content = c) in P.desugar_string @@ -343,35 +327,35 @@ module type RawParser = sig and type uo_list = list_item Html.elt list val ignore_a_elem_phrasing : - Wikicreole.attribs - -> href - -> link_content Html.elt list list - -> link_content Html.elt list + Wikicreole.attribs -> + href -> + link_content Html.elt list list -> + link_content Html.elt list val ignore_a_elem_flow : - Wikicreole.attribs - -> href - -> res_without_interactive Html.elt list list - -> res_without_interactive Html.elt list + Wikicreole.attribs -> + href -> + res_without_interactive Html.elt list list -> + res_without_interactive Html.elt list val default_extension : - name:string - -> Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> string option - -> link_content Html.elt list + name:string -> + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + string option -> + link_content Html.elt list val default_ni_extension : - name:string - -> Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> string option - -> link_content Html.elt list + name:string -> + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + string option -> + link_content Html.elt list end -type (+'flow - , +'flow_without_interactive - , +'phrasing_without_interactive) +type (+'flow, + +'flow_without_interactive, + +'phrasing_without_interactive) plugin_content = [ `Flow5_link of href * Wikicreole.attribs * 'flow_without_interactive Html.elt list @@ -381,21 +365,20 @@ type (+'flow | `Phrasing_without_interactive of 'phrasing_without_interactive Html.elt list ] -type (+'flow_without_interactive - , +'phrasing_without_interactive) +type (+'flow_without_interactive, + +'phrasing_without_interactive) ni_plugin_content = [ `Flow5 of 'flow_without_interactive Html.elt list | `Phrasing_without_interactive of 'phrasing_without_interactive Html.elt list ] -type (+'flow_without_interactive - , +'phrasing_without_interactive) +type (+'flow_without_interactive, + +'phrasing_without_interactive) link_plugin_content = [ `Flow5_link of href * Wikicreole.attribs * 'flow_without_interactive Html.elt list | `Phrasing_link of - href * Wikicreole.attribs * 'phrasing_without_interactive Html.elt list - ] + href * Wikicreole.attribs * 'phrasing_without_interactive Html.elt list ] module MakeParser (B : RawParser) : ExtParser @@ -413,34 +396,34 @@ module MakeParser (B : RawParser) : (res, res_without_interactive, link_content) plugin_content type simple_plugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> string option - -> (res, res_without_interactive, link_content) plugin_content + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + string option -> + (res, res_without_interactive, link_content) plugin_content type simple_ni_plugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> string option - -> (res_without_interactive, link_content) ni_plugin_content + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + string option -> + (res_without_interactive, link_content) ni_plugin_content type 'a wiki_plugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> 'a Html.elt list option - -> (res, res_without_interactive, link_content) plugin_content + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + 'a Html.elt list option -> + (res, res_without_interactive, link_content) plugin_content type 'a wiki_ni_plugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> 'a Html.elt list option - -> (res_without_interactive, link_content) ni_plugin_content + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + 'a Html.elt list option -> + (res_without_interactive, link_content) ni_plugin_content type 'a link_plugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> 'a Html.elt list option - -> (res_without_interactive, link_content) link_plugin_content + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + 'a Html.elt list option -> + (res_without_interactive, link_content) link_plugin_content (* Module to encode existential type parameter of the recursive wikiparser. Could be replaced by a GADT with Ocaml 3.13. *) @@ -450,15 +433,15 @@ module MakeParser (B : RawParser) : type rec_link_content val wikiparser : - ( rec_res - , rec_res_without_interactive - , rec_link_content ) + ( rec_res, + rec_res_without_interactive, + rec_link_content ) ExtParser.ext_wikicreole_parser val update_context : - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> Wiki_widgets_interface.box_info + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + Wiki_widgets_interface.box_info val plugin : rec_res wiki_plugin val ni_plugin : rec_res_without_interactive wiki_ni_plugin option @@ -470,15 +453,15 @@ module MakeParser (B : RawParser) : type rec_link_content val wikiparser : - ( rec_res - , rec_res_without_interactive - , rec_link_content ) + ( rec_res, + rec_res_without_interactive, + rec_link_content ) ExtParser.ext_wikicreole_parser val update_context : - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> Wiki_widgets_interface.box_info + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + Wiki_widgets_interface.box_info val plugin : rec_res_without_interactive link_plugin end @@ -489,9 +472,9 @@ module MakeParser (B : RawParser) : type rec_link_content val wikiparser : - ( rec_res - , rec_res_without_interactive - , rec_link_content ) + ( rec_res, + rec_res_without_interactive, + rec_link_content ) ExtParser.ext_wikicreole_parser val plugin : rec_res wikicreole_parser -> simple_plugin @@ -519,14 +502,14 @@ module MakeParser (B : RawParser) : match Hashtbl.find plugin_assoc name with | SimplePlugin _, _ -> None | WikiPlugin p, _ -> - let module Plugin = (val p : WikiPlugin) in - Some (get_plugin_resolver Plugin.wikiparser) + let module Plugin = (val p : WikiPlugin) in + Some (get_plugin_resolver Plugin.wikiparser) | LinkPlugin p, _ -> - let module Plugin = (val p : LinkPlugin) in - Some (get_plugin_resolver Plugin.wikiparser) + let module Plugin = (val p : LinkPlugin) in + Some (get_plugin_resolver Plugin.wikiparser) | RawWikiPlugin p, _ -> - let module Plugin = (val p : RawWikiPlugin) in - Some (get_plugin_resolver Plugin.wikiparser) + let module Plugin = (val p : RawWikiPlugin) in + Some (get_plugin_resolver Plugin.wikiparser) with Not_found -> Some plugin_resolver) module InteractiveBuilder = struct @@ -543,39 +526,39 @@ module MakeParser (B : RawParser) : match Hashtbl.find plugin_assoc name with | SimplePlugin (plugin, _), _ -> (None, plugin) | WikiPlugin p, _ -> - let module Plugin = (val p : WikiPlugin) in - ( Some (get_plugin_resolver Plugin.wikiparser) - , fun bi attribs content -> - let bi = Plugin.update_context bi attribs in - let xml = - Option.map - ~f:(xml_of_wiki (cast_wp Plugin.wikiparser) bi) - (Option.map ~f:String.trim content) - in - Plugin.plugin bi attribs xml ) + let module Plugin = (val p : WikiPlugin) in + ( Some (get_plugin_resolver Plugin.wikiparser), + fun bi attribs content -> + let bi = Plugin.update_context bi attribs in + let xml = + Option.map + ~f:(xml_of_wiki (cast_wp Plugin.wikiparser) bi) + (Option.map ~f:String.trim content) + in + Plugin.plugin bi attribs xml ) | LinkPlugin p, _ -> - let module Plugin = (val p : LinkPlugin) in - ( Some (get_plugin_resolver Plugin.wikiparser) - , fun bi attribs content -> - let bi = Plugin.update_context bi attribs in - let xml = - Option.map - ~f:(xml_of_wiki (cast_niwp Plugin.wikiparser) bi) - (Option.map ~f:String.trim content) - in - (Plugin.plugin bi attribs xml - :> ( res - , res_without_interactive - , link_content ) - Wiki_syntax_types.plugin_content) ) + let module Plugin = (val p : LinkPlugin) in + ( Some (get_plugin_resolver Plugin.wikiparser), + fun bi attribs content -> + let bi = Plugin.update_context bi attribs in + let xml = + Option.map + ~f:(xml_of_wiki (cast_niwp Plugin.wikiparser) bi) + (Option.map ~f:String.trim content) + in + (Plugin.plugin bi attribs xml + :> ( res, + res_without_interactive, + link_content ) + Wiki_syntax_types.plugin_content) ) | RawWikiPlugin p, _ -> - let module Plugin = (val p : RawWikiPlugin) in - ( Some (get_plugin_resolver Plugin.wikiparser) - , fun bi attribs content -> - Plugin.plugin (cast_wp Plugin.wikiparser) bi attribs content ) + let module Plugin = (val p : RawWikiPlugin) in + ( Some (get_plugin_resolver Plugin.wikiparser), + fun bi attribs content -> + Plugin.plugin (cast_wp Plugin.wikiparser) bi attribs content ) with Not_found -> - ( Some plugin_resolver - , fun bi attribs content -> + ( Some plugin_resolver, + fun bi attribs content -> `Phrasing_without_interactive (B.default_extension ~name bi attribs content) ) @@ -651,8 +634,7 @@ module MakeParser (B : RawParser) : | `Phrasing_link of href * Wikicreole.attribs * phrasing_without_interactive | `Flow5 of flow_without_interactive - | `Phrasing_without_interactive of phrasing_without_interactive - ] + | `Phrasing_without_interactive of phrasing_without_interactive ] let default_ni_plugin ~name bi attribs content = `Phrasing_without_interactive @@ -666,28 +648,29 @@ module MakeParser (B : RawParser) : | SimplePlugin (_, Some ni_plugin), _ -> (None, ni_plugin) | SimplePlugin (_, None), _ -> (None, default_ni_plugin ~name) | WikiPlugin p, _ -> ( - let module Plugin = (val p : WikiPlugin) in - ( Some (get_plugin_resolver Plugin.wikiparser) - , fun bi attribs content -> - let bi = Plugin.update_context bi attribs in - let xml = - Option.map - ~f:(xml_of_wiki (cast_niwp Plugin.wikiparser) bi) - (Option.map ~f:String.trim content) - in - match Plugin.ni_plugin with - | Some f -> f bi attribs xml - | None -> default_ni_plugin ~name bi attribs content )) + let module Plugin = (val p : WikiPlugin) in + ( Some (get_plugin_resolver Plugin.wikiparser), + fun bi attribs content -> + let bi = Plugin.update_context bi attribs in + let xml = + Option.map + ~f:(xml_of_wiki (cast_niwp Plugin.wikiparser) bi) + (Option.map ~f:String.trim content) + in + match Plugin.ni_plugin with + | Some f -> f bi attribs xml + | None -> default_ni_plugin ~name bi attribs content )) | LinkPlugin p, _ -> - let module Plugin = (val p : LinkPlugin) in - (Some (get_plugin_resolver Plugin.wikiparser), default_ni_plugin ~name) + let module Plugin = (val p : LinkPlugin) in + ( Some (get_plugin_resolver Plugin.wikiparser), + default_ni_plugin ~name ) | RawWikiPlugin p, _ -> ( - let module Plugin = (val p : RawWikiPlugin) in - ( Some (get_plugin_resolver Plugin.wikiparser) - , fun bi attribs content -> - match Plugin.ni_plugin with - | Some f -> f (cast_niwp Plugin.wikiparser) bi attribs content - | None -> default_ni_plugin ~name bi attribs content )) + let module Plugin = (val p : RawWikiPlugin) in + ( Some (get_plugin_resolver Plugin.wikiparser), + fun bi attribs content -> + match Plugin.ni_plugin with + | Some f -> f (cast_niwp Plugin.wikiparser) bi attribs content + | None -> default_ni_plugin ~name bi attribs content )) with Not_found -> (Some plugin_resolver, default_ni_plugin ~name) let plugin = (plugin :> _ -> _ * (_ -> _ -> _ -> plugin_content)) @@ -751,9 +734,7 @@ module MakeParser (B : RawParser) : let error = nothing1 let make_href _ a fragment = - match fragment with - | None -> a - | Some f -> a ^ "#" ^ f + match fragment with None -> a | Some f -> a ^ "#" ^ f let string_of_href x = x @@ -762,8 +743,7 @@ module MakeParser (B : RawParser) : | `Phrasing_link of href * Wikicreole.attribs * phrasing_without_interactive | `Flow5 of flow_without_interactive - | `Phrasing_without_interactive of phrasing_without_interactive - ] + | `Phrasing_without_interactive of phrasing_without_interactive ] let plugin_resolver = plugin_resolver @@ -774,11 +754,11 @@ module MakeParser (B : RawParser) : | SimplePlugin _, _ -> None | RawWikiPlugin _, _ -> Some plugin_resolver | WikiPlugin p, _ -> - let module WikiPlugin = (val p : WikiPlugin) in - Some (get_plugin_resolver WikiPlugin.wikiparser) + let module WikiPlugin = (val p : WikiPlugin) in + Some (get_plugin_resolver WikiPlugin.wikiparser) | LinkPlugin p, _ -> - let module LinkPlugin = (val p : LinkPlugin) in - Some (get_plugin_resolver LinkPlugin.wikiparser) + let module LinkPlugin = (val p : LinkPlugin) in + Some (get_plugin_resolver LinkPlugin.wikiparser) with Not_found -> Some plugin_resolver in (wiki_content, fun _ _ _ -> `Phrasing_without_interactive ()) @@ -805,33 +785,39 @@ module MakeParser (B : RawParser) : match plugin with | SimplePlugin _ -> content | WikiPlugin p -> ( - let module Plugin = (val p : WikiPlugin) in - match content with - | None -> None - | Some content -> - let content = preparse_string Plugin.wikiparser wb content in - Some content) + let module Plugin = (val p : WikiPlugin) in + match content with + | None -> None + | Some content -> + let content = + preparse_string Plugin.wikiparser wb content + in + Some content) | LinkPlugin p -> ( - let module Plugin = (val p : LinkPlugin) in - match content with - | None -> None - | Some content -> - let content = preparse_string Plugin.wikiparser wb content in - Some content) + let module Plugin = (val p : LinkPlugin) in + match content with + | None -> None + | Some content -> + let content = + preparse_string Plugin.wikiparser wb content + in + Some content) | RawWikiPlugin p -> ( - let module Plugin = (val p : RawWikiPlugin) in - match content with - | None -> None - | Some content -> - let content = preparse_string Plugin.wikiparser wb content in - Some content) + let module Plugin = (val p : RawWikiPlugin) in + match content with + | None -> None + | Some content -> + let content = + preparse_string Plugin.wikiparser wb content + in + Some content) in match preparser with | None -> ( - match (content, content') with - | None, None -> None - | Some content, Some content' when content' == content -> None - | _, _ -> Some (string_of_extension name attribs content')) + match (content, content') with + | None, None -> None + | Some content, Some content' when content' == content -> None + | _, _ -> Some (string_of_extension name attribs content')) | Some preparser -> preparser wb attribs content' in subst := (start, end_, content') :: !subst @@ -839,16 +825,16 @@ module MakeParser (B : RawParser) : let link_action addr fragment attribs (start, end_) (subst, params) = subst := - ( start - , end_ - , try !link_action_ref addr fragment attribs params with _ -> None ) + ( start, + end_, + try !link_action_ref addr fragment attribs params with _ -> None ) :: !subst let href_action addr fragment attribs (start, end_) (subst, params) = subst := - ( start - , end_ - , try !href_action_ref addr fragment attribs params with _ -> None ) + ( start, + end_, + try !href_action_ref addr fragment attribs params with _ -> None ) :: !subst end in (module Preparser : Wikicreole.Builder @@ -870,33 +856,33 @@ module MakeParser (B : RawParser) : let attribs' = let f = function | "item", it -> - let it' = - let link, text = - match String.cut '|' it with - | Some x -> x - | None -> (it, it) + let it' = + let link, text = + match String.cut '|' it with + | Some x -> x + | None -> (it, it) + in + match !normalize_href_ref (0, 0) link None wb with + | Some link' -> link' ^ "|" ^ text + | None -> it in - match !normalize_href_ref (0, 0) link None wb with - | Some link' -> link' ^ "|" ^ text - | None -> it - in - ("item", it') + ("item", it') | x -> x in List.map f attribs in - if attribs' <> attribs - then Some (string_of_extension name attribs' content) + if attribs' <> attribs then + Some (string_of_extension name attribs' content) else None in let desugar_content desugar_string_with_parser = match content with | None -> None | Some content -> - let content' = desugar_string_with_parser wb content in - if content' <> content - then Some (string_of_extension name attribs (Some content')) - else None + let content' = desugar_string_with_parser wb content in + if content' <> content then + Some (string_of_extension name attribs (Some content')) + else None in try let plugin, _ = Hashtbl.find plugin_assoc name in @@ -904,17 +890,17 @@ module MakeParser (B : RawParser) : match plugin with | SimplePlugin _ -> desugar_attributes () | WikiPlugin p -> - desugar_content - (let module Plugin = (val p : WikiPlugin) in - fun a b -> (desugar_string Plugin.wikiparser) a b) + desugar_content + (let module Plugin = (val p : WikiPlugin) in + fun a b -> (desugar_string Plugin.wikiparser) a b) | LinkPlugin p -> - desugar_content - (let module Plugin = (val p : LinkPlugin) in - fun a b -> (desugar_string Plugin.wikiparser) a b) + desugar_content + (let module Plugin = (val p : LinkPlugin) in + fun a b -> (desugar_string Plugin.wikiparser) a b) | RawWikiPlugin p -> - desugar_content - (let module Plugin = (val p : RawWikiPlugin) in - fun a b -> (desugar_string Plugin.wikiparser) a b) + desugar_content + (let module Plugin = (val p : RawWikiPlugin) in + fun a b -> (desugar_string Plugin.wikiparser) a b) in subst := (start, end_, content') :: !subst with _ (* was Not_found *) -> () @@ -927,9 +913,9 @@ module MakeParser (B : RawParser) : string -> string option -> _ -> int * int -> param -> unit = fun addr fragment _ ((start, end_) as pos) (subst, wikipage) -> subst := - ( start - , end_ - , try !normalize_href_ref pos addr fragment wikipage with _ -> None ) + ( start, + end_, + try !normalize_href_ref pos addr fragment wikipage with _ -> None ) :: !subst end in (module Desugarer : Wikicreole.Builder @@ -944,13 +930,13 @@ module MakeParser (B : RawParser) : match replacement with | None -> pos | Some replacement -> - Buffer.add_substring buf content pos (start - pos); - Buffer.add_string buf replacement; - end_) + Buffer.add_substring buf content pos (start - pos); + Buffer.add_string buf replacement; + end_) 0 subst in - if pos < String.length content - then Buffer.add_substring buf content pos (String.length content - pos); + if pos < String.length content then + Buffer.add_substring buf content pos (String.length content - pos); Buffer.contents buf let with_actions ?href_action ?link_action f = @@ -958,12 +944,8 @@ module MakeParser (B : RawParser) : reference take place before the call to [apply_subst] *) let old_link_action = !link_action_ref in let old_href_action = !href_action_ref in - (match link_action with - | Some f -> link_action_ref := f - | None -> ()); - (match href_action with - | Some f -> href_action_ref := f - | None -> ()); + (match link_action with Some f -> link_action_ref := f | None -> ()); + (match href_action with Some f -> href_action_ref := f | None -> ()); let res = f () in link_action_ref := old_link_action; href_action_ref := old_href_action; @@ -994,12 +976,7 @@ module FlowTypes = struct type res_without_interactive = Html_types.flow5_without_interactive type text = Html_types.phrasing type link_content = Html_types.phrasing_without_interactive - - type list_item = - [ `Ol - | `Ul - | `Em - ] + type list_item = [ `Ol | `Ul | `Em ] end module FlowWithoutHeaderFooterTypes = struct @@ -1010,12 +987,7 @@ module FlowWithoutHeaderFooterTypes = struct type text = Html_types.phrasing type link_content = Html_types.phrasing_without_interactive - - type list_item = - [ `Ol - | `Ul - | `Em - ] + type list_item = [ `Ol | `Ul | `Em ] end module PhrasingTypes = struct @@ -1027,62 +999,19 @@ module PhrasingTypes = struct end module MenuTypes = struct - type res = - [ `H1 - | `H2 - | `H3 - | `H4 - | `H5 - | `H6 - ] - - type res_without_interactive = - [ `H1 - | `H2 - | `H3 - | `H4 - | `H5 - | `H6 - ] - + type res = [ `H1 | `H2 | `H3 | `H4 | `H5 | `H6 ] + type res_without_interactive = [ `H1 | `H2 | `H3 | `H4 | `H5 | `H6 ] type text = Html_types.phrasing type link_content = Html_types.phrasing_without_interactive - - type list_item = - [ `H1 - | `H2 - | `H3 - | `H4 - | `H5 - | `H6 - ] + type list_item = [ `H1 | `H2 | `H3 | `H4 | `H5 | `H6 ] end module ButtonTypes = struct - type res = - [ Html_types.button_content - | `PCDATA - ] - - type res_without_interactive = - [ Html_types.button_content - | `PCDATA - ] - - type text = - [ Html_types.button_content - | `PCDATA - ] - - type link_content = - [ Html_types.button_content - | `PCDATA - ] - - type list_item = - [ Html_types.button_content - | `PCDATA - ] + type res = [ Html_types.button_content | `PCDATA ] + type res_without_interactive = [ Html_types.button_content | `PCDATA ] + type text = [ Html_types.button_content | `PCDATA ] + type link_content = [ Html_types.button_content | `PCDATA ] + type list_item = [ Html_types.button_content | `PCDATA ] end (********************************) @@ -1138,14 +1067,15 @@ module FlowBuilder = struct | Absolute a when uri_absolute a -> (Some a, None) | Absolute a when ends_with "/" a -> (Some a, None) | Absolute a -> ( - match String.cut '#' a with - | Some ("", hash) -> (Some ("#" ^ hash), None) - | Some (a, hash) -> (Some (a ^ Global.suffix () ^ "#" ^ hash), None) - | None -> (Some (a ^ Global.suffix ()), None)) + match String.cut '#' a with + | Some ("", hash) -> (Some ("#" ^ hash), None) + | Some (a, hash) -> (Some (a ^ Global.suffix () ^ "#" ^ hash), None) + | None -> (Some (a ^ Global.suffix ()), None)) | _ -> assert false in let c = List.flatten c in - [ (Html.a + [ + (Html.a ~a: ( (let open Operators in (* NOTE address is always Some x for now but one could add another @@ -1156,7 +1086,7 @@ module FlowBuilder = struct |> fun x -> x :: a ) (let open Operators in text >>= (fun t -> Some [ Html.txt t ]) |? c) - :> Html_types.phrasing Html.elt) + :> Html_types.phrasing Html.elt); ] let a_elem_flow attribs addr c = @@ -1173,7 +1103,10 @@ module FlowBuilder = struct let img_elem attribs href alt = let a = opt_of_list (parse_common_attribs attribs) in - let src = uri_of_href href (* CCC https ? *) in + let src = + uri_of_href href + (* CCC https ? *) + in [ (Html.img ~src ~alt ?a () : [> `Img ] Html.elt) ] let tt_elem attribs content = @@ -1192,7 +1125,8 @@ module FlowBuilder = struct let pre_elem attribs content = let a = opt_of_list (parse_common_attribs attribs) in - [ (Html.pre ?a [ Html.txt (String.concat "" content) ] : [> `Pre ] Html.elt) + [ + (Html.pre ?a [ Html.txt (String.concat "" content) ] : [> `Pre ] Html.elt); ] let add_backref attribs r = @@ -1200,8 +1134,9 @@ module FlowBuilder = struct let id = List.assoc "id" attribs in let open Html in r - @ [ txt " " - ; a ~a:[ a_class [ "backref" ]; a_href ("#" ^ id) ] [ entity "#182" ] + @ [ + txt " "; + a ~a:[ a_class [ "backref" ]; a_href ("#" ^ id) ] [ entity "#182" ]; ] with Not_found -> r @@ -1238,8 +1173,9 @@ module FlowBuilder = struct let section_elem attribs content = let a = opt_of_list (parse_common_attribs attribs) in let r = List.flatten content in - [ (Html.section ?a (r :> Html_types.section_content_fun Html.elt list) - : [> `Section ] Html.elt) + [ + (Html.section ?a (r :> Html_types.section_content_fun Html.elt list) + : [> `Section ] Html.elt); ] let ul_elem attribs content = @@ -1263,8 +1199,7 @@ module FlowBuilder = struct let tdh_builder (h, attribs, (c : Html_types.phrasing Html.elt list list)) = let a = opt_of_list (parse_table_cell_attribs attribs) in let r = List.flatten c in - if h - then + if h then Html.th ?a (r : Html_types.phrasing Html.elt list @@ -1284,11 +1219,11 @@ module FlowBuilder = struct match row with | [] -> Html.tr [ Html.td [] ] | x :: xs -> - let a = opt_of_list (parse_common_attribs attribs) in - (*let a = opt_of_list (parse_table_row_attribs attribs) in*) - let y = tdh_builder x in - let ys = List.map tdh_builder xs in - Html.tr ?a (y :: ys) + let a = opt_of_list (parse_common_attribs attribs) in + (*let a = opt_of_list (parse_table_row_attribs attribs) in*) + let y = tdh_builder x in + let ys = List.map tdh_builder xs in + Html.tr ?a (y :: ys) let table_elem attribs l = let a = opt_of_list (parse_common_attribs attribs) in @@ -1299,8 +1234,8 @@ module FlowBuilder = struct match l with | [] -> [ Html.table ?a ?caption [ Html.tr [ Html.td [] ] ] ] | rows -> - let rows = List.map tr_builder rows in - [ (Html.table ?a ?caption rows : [> `Table ] Html.elt) ] + let rows = List.map tr_builder rows in + [ (Html.table ?a ?caption rows : [> `Table ] Html.elt) ] let error (s : string) = [ (Html.strong [ Html.txt s ] : [> `Strong ] Html.elt) ] @@ -1416,8 +1351,9 @@ module ButtonBuilder = struct include FlowBuilder let forbid0 s = - [ (Html.em [ Html.txt (s ^ " not enabled in buttons") ] - : [ Html_types.button_content | `PCDATA ] Html.elt) + [ + (Html.em [ Html.txt (s ^ " not enabled in buttons") ] + : [ Html_types.button_content | `PCDATA ] Html.elt); ] let forbid1 s _ = forbid0 s @@ -1701,37 +1637,35 @@ let reduced_wikicreole_parser_button_content = (*************************) (** Registering extension *) -type (+'flow_without_interactive - , +'phrasing_without_interactive) +type (+'flow_without_interactive, + +'phrasing_without_interactive) non_interactive_simple_plugin = - ( Wiki_widgets_interface.box_info - , ('flow_without_interactive, 'phrasing_without_interactive) ni_plugin_content + ( Wiki_widgets_interface.box_info, + ('flow_without_interactive, 'phrasing_without_interactive) ni_plugin_content ) Wikicreole.plugin -type (+'flow - , +'flow_without_interactive - , +'phrasing_without_interactive) +type (+'flow, + +'flow_without_interactive, + +'phrasing_without_interactive) interactive_simple_plugin = - ( Wiki_widgets_interface.box_info - , ( 'flow - , 'flow_without_interactive - , 'phrasing_without_interactive ) + ( Wiki_widgets_interface.box_info, + ( 'flow, + 'flow_without_interactive, + 'phrasing_without_interactive ) plugin_content ) Wikicreole.plugin type +'without_interactive link_simple_plugin = - ( Wiki_widgets_interface.box_info - , href * Wikicreole.attribs * 'without_interactive Html.elt list ) + ( Wiki_widgets_interface.box_info, + href * Wikicreole.attribs * 'without_interactive Html.elt list ) Wikicreole.plugin let register_simple_extension (type a b c) ~(wp : (a, b, c) ext_wikicreole_parser) ~name ?preparser ?ni_plugin plugin = let module Parser = (val wp - : ExtParser - with type res = a - and type res_without_interactive = b + : ExtParser with type res = a and type res_without_interactive = b and type link_content = c) in let open Parser in @@ -1741,8 +1675,8 @@ let register_simple_extension (type a b c) let register_simple_flow_extension ~name ?(reduced = true) ?preparser (plugin : - ( [< Html_types.flow5_without_interactive_header_footer ] - , [< Html_types.phrasing_without_interactive ] ) + ( [< Html_types.flow5_without_interactive_header_footer ], + [< Html_types.phrasing_without_interactive ] ) non_interactive_simple_plugin) = register_simple_extension ~name ?preparser ~wp:wikicreole_parser ~ni_plugin:(plugin :> WikicreoleParser.simple_ni_plugin) @@ -1751,8 +1685,7 @@ let register_simple_flow_extension ~name ?(reduced = true) ?preparser ~wp:wikicreole_parser_without_header_footer ~ni_plugin:(plugin :> WikicreoleParserWithoutHeaderFooter.simple_ni_plugin) (plugin :> WikicreoleParserWithoutHeaderFooter.simple_plugin); - if reduced - then ( + if reduced then ( register_simple_extension ~name ?preparser ~wp:reduced_wikicreole_parser0 ~ni_plugin:(plugin :> ReducedWikicreoleParser0.simple_ni_plugin) (plugin :> ReducedWikicreoleParser0.simple_plugin); @@ -1766,22 +1699,21 @@ let register_simple_flow_extension ~name ?(reduced = true) ?preparser let register_interactive_simple_flow_extension ~name ?(reduced = true) ?preparser (plugin : - ( Html_types.flow5_without_header_footer - , Html_types.flow5_without_interactive_header_footer - , Html_types.phrasing_without_interactive ) + ( Html_types.flow5_without_header_footer, + Html_types.flow5_without_interactive_header_footer, + Html_types.phrasing_without_interactive ) interactive_simple_plugin) = register_simple_extension ~name ?preparser ~wp:wikicreole_parser (plugin :> WikicreoleParser.simple_plugin); register_simple_extension ~name ?preparser ~wp:wikicreole_parser_without_header_footer (plugin :> WikicreoleParserWithoutHeaderFooter.simple_plugin); - if reduced - then ( + if reduced then ( register_simple_extension ~name ?preparser ~wp:reduced_wikicreole_parser0 (plugin - : ( Html_types.flow5_without_header_footer - , Html_types.flow5_without_interactive_header_footer - , Html_types.phrasing_without_interactive ) + : ( Html_types.flow5_without_header_footer, + Html_types.flow5_without_interactive_header_footer, + Html_types.phrasing_without_interactive ) interactive_simple_plugin :> ReducedWikicreoleParser0.simple_plugin); register_simple_extension ~name ?preparser ~wp:reduced_wikicreole_parser1 @@ -1791,22 +1723,22 @@ let register_interactive_simple_flow_extension ~name ?(reduced = true) let register_interactive_simple_flow_extension = (register_interactive_simple_flow_extension - : name:_ - -> ?reduced:_ - -> ?preparser:_ - -> ( Html_types.flow5_without_header_footer - , Html_types.flow5_without_interactive_header_footer - , Html_types.phrasing_without_interactive ) - interactive_simple_plugin - -> unit - :> name:_ - -> ?reduced:_ - -> ?preparser:_ - -> ( [< Html_types.flow5_without_header_footer ] - , [< Html_types.flow5_without_interactive_header_footer ] - , [< Html_types.phrasing_without_interactive ] ) - interactive_simple_plugin - -> unit) + : name:_ -> + ?reduced:_ -> + ?preparser:_ -> + ( Html_types.flow5_without_header_footer, + Html_types.flow5_without_interactive_header_footer, + Html_types.phrasing_without_interactive ) + interactive_simple_plugin -> + unit + :> name:_ -> + ?reduced:_ -> + ?preparser:_ -> + ( [< Html_types.flow5_without_header_footer ], + [< Html_types.flow5_without_interactive_header_footer ], + [< Html_types.phrasing_without_interactive ] ) + interactive_simple_plugin -> + unit) let register_link_simple_flow_extension ~name ?reduced ?preparser plugin = let plugin wb attribs c = `Flow5_link (plugin wb attribs c) in @@ -1814,13 +1746,13 @@ let register_link_simple_flow_extension ~name ?reduced ?preparser plugin = let register_simple_phrasing_extension ~name ?reduced ?preparser (plugin : - ( Html_types.phrasing_without_interactive - , Html_types.phrasing_without_interactive ) + ( Html_types.phrasing_without_interactive, + Html_types.phrasing_without_interactive ) non_interactive_simple_plugin) = register_simple_flow_extension ~name ?reduced ?preparser (plugin - :> ( Html_types.flow5_without_interactive_header_footer - , Html_types.phrasing_without_interactive ) + :> ( Html_types.flow5_without_interactive_header_footer, + Html_types.phrasing_without_interactive ) non_interactive_simple_plugin); register_simple_extension ~name ?preparser ~wp:phrasing_wikicreole_parser ~ni_plugin:(plugin :> PhrasingWikicreoleParser.simple_ni_plugin) @@ -1828,54 +1760,54 @@ let register_simple_phrasing_extension ~name ?reduced ?preparser let register_simple_phrasing_extension = (register_simple_phrasing_extension - : name:_ - -> ?reduced:_ - -> ?preparser:_ - -> ( Html_types.phrasing_without_interactive - , Html_types.phrasing_without_interactive ) - non_interactive_simple_plugin - -> unit - :> name:_ - -> ?reduced:_ - -> ?preparser:_ - -> ( [< Html_types.phrasing_without_interactive ] - , [< Html_types.phrasing_without_interactive ] ) - non_interactive_simple_plugin - -> unit) + : name:_ -> + ?reduced:_ -> + ?preparser:_ -> + ( Html_types.phrasing_without_interactive, + Html_types.phrasing_without_interactive ) + non_interactive_simple_plugin -> + unit + :> name:_ -> + ?reduced:_ -> + ?preparser:_ -> + ( [< Html_types.phrasing_without_interactive ], + [< Html_types.phrasing_without_interactive ] ) + non_interactive_simple_plugin -> + unit) let register_interactive_simple_phrasing_extension ~name ?reduced ?preparser (plugin : - ( Html_types.phrasing - , Html_types.phrasing_without_interactive - , Html_types.phrasing_without_interactive ) + ( Html_types.phrasing, + Html_types.phrasing_without_interactive, + Html_types.phrasing_without_interactive ) interactive_simple_plugin) = register_interactive_simple_flow_extension ~name ?reduced ?preparser (plugin - :> ( Html_types.flow5_without_header_footer - , Html_types.flow5_without_interactive_header_footer - , Html_types.phrasing_without_interactive ) + :> ( Html_types.flow5_without_header_footer, + Html_types.flow5_without_interactive_header_footer, + Html_types.phrasing_without_interactive ) interactive_simple_plugin); register_simple_extension ~name ?preparser ~wp:phrasing_wikicreole_parser (plugin :> PhrasingWikicreoleParser.simple_plugin) let register_interactive_simple_phrasing_extension = (register_interactive_simple_phrasing_extension - : name:_ - -> ?reduced:_ - -> ?preparser:_ - -> ( Html_types.phrasing - , Html_types.phrasing_without_interactive - , Html_types.phrasing_without_interactive ) - interactive_simple_plugin - -> unit - :> name:_ - -> ?reduced:_ - -> ?preparser:_ - -> ( [< Html_types.phrasing ] - , [< Html_types.phrasing_without_interactive ] - , [< Html_types.phrasing_without_interactive ] ) - interactive_simple_plugin - -> unit) + : name:_ -> + ?reduced:_ -> + ?preparser:_ -> + ( Html_types.phrasing, + Html_types.phrasing_without_interactive, + Html_types.phrasing_without_interactive ) + interactive_simple_plugin -> + unit + :> name:_ -> + ?reduced:_ -> + ?preparser:_ -> + ( [< Html_types.phrasing ], + [< Html_types.phrasing_without_interactive ], + [< Html_types.phrasing_without_interactive ] ) + interactive_simple_plugin -> + unit) let register_link_simple_phrasing_extension ~name ?reduced ?preparser plugin = let plugin wb attribs c = `Phrasing_link (plugin wb attribs c) in @@ -1883,25 +1815,21 @@ let register_link_simple_phrasing_extension ~name ?reduced ?preparser plugin = (**** *) -type (-'content - , +'flow_without_interactive - , +'phrasing_without_interactive) +type (-'content, + +'flow_without_interactive, + +'phrasing_without_interactive) wiki_plugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> 'content Html.elt list option - -> ( 'flow_without_interactive - , 'phrasing_without_interactive ) - ni_plugin_content + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + 'content Html.elt list option -> + ('flow_without_interactive, 'phrasing_without_interactive) ni_plugin_content let register_wiki_extension (type a b c a' b' c') ~wp ~name ~wp_rec ?preparser ?(context = fun bi _ -> bi) ?(ni_plugin : (_, _, _) wiki_plugin option) (plugin : (_, _, _) wiki_plugin) = let module Parser = (val wp - : ExtParser - with type res = a - and type res_without_interactive = b + : ExtParser with type res = a and type res_without_interactive = b and type link_content = c) in let module Plugin = struct @@ -1920,24 +1848,20 @@ let register_wiki_extension (type a b c a' b' c') ~wp ~name ~wp_rec ?preparser Parser.register_extension ~name ?preparser (WikiPlugin (module Plugin : WikiPlugin)) -type (-'content - , +'flow_without_interactive - , +'phrasing_without_interactive) +type (-'content, + +'flow_without_interactive, + +'phrasing_without_interactive) link_plugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> 'content Html.elt list option - -> ( 'flow_without_interactive - , 'phrasing_without_interactive ) - link_plugin_content + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + 'content Html.elt list option -> + ('flow_without_interactive, 'phrasing_without_interactive) link_plugin_content let register_link_extension (type a b c a' b' c') ~wp ~name ~wp_rec ?preparser ?(context = fun bi _ -> bi) (plugin : (_, _, _) link_plugin) = let module Parser = (val wp - : ExtParser - with type res = a - and type res_without_interactive = b + : ExtParser with type res = a and type res_without_interactive = b and type link_content = c) in let module Plugin = struct @@ -1956,9 +1880,7 @@ let register_raw_wiki_extension (type a b c a' b' c') ~wp ~name ~wp_rec ?preparser ?ni_plugin plugin = let module Parser = (val wp - : ExtParser - with type res = a - and type res_without_interactive = b + : ExtParser with type res = a and type res_without_interactive = b and type link_content = c) in let open Parser in @@ -1974,24 +1896,23 @@ let register_raw_wiki_extension (type a b c a' b' c') ~wp ~name ~wp_rec register_extension ~name ?preparser (RawWikiPlugin (module Plugin : RawWikiPlugin)) -type wiki_flow_pplugin = - { fpp : - 'flow. - ( 'flow - Html_types.between_flow5_and_flow5_without_interactive_header_footer - , 'flow - , Html_types.phrasing_without_interactive ) - wiki_plugin - } +type wiki_flow_pplugin = { + fpp : + 'flow. + ( 'flow Html_types.between_flow5_and_flow5_without_interactive_header_footer, + 'flow, + Html_types.phrasing_without_interactive ) + wiki_plugin; +} let register_wiki_flow_extension ~name ?(reduced = true) ?preparser plugin = let register wp = register_wiki_extension ~name ~wp ~wp_rec:wp ?preparser ~ni_plugin: (plugin.fpp - :> ( FlowTypes.res_without_interactive - , FlowTypes.res_without_interactive - , _ ) + :> ( FlowTypes.res_without_interactive, + FlowTypes.res_without_interactive, + _ ) wiki_plugin) (plugin.fpp :> (FlowTypes.res, FlowTypes.res, _) wiki_plugin) in @@ -2000,31 +1921,30 @@ let register_wiki_flow_extension ~name ?(reduced = true) ?preparser plugin = ~wp_rec:wikicreole_parser_without_header_footer ?preparser ~ni_plugin: (plugin.fpp - :> ( FlowWithoutHeaderFooterTypes.res_without_interactive - , FlowWithoutHeaderFooterTypes.res_without_interactive - , _ ) + :> ( FlowWithoutHeaderFooterTypes.res_without_interactive, + FlowWithoutHeaderFooterTypes.res_without_interactive, + _ ) wiki_plugin) (plugin.fpp - :> ( FlowWithoutHeaderFooterTypes.res - , FlowWithoutHeaderFooterTypes.res - , _ ) + :> ( FlowWithoutHeaderFooterTypes.res, + FlowWithoutHeaderFooterTypes.res, + _ ) wiki_plugin); - if reduced - then ( + if reduced then ( register reduced_wikicreole_parser0; register reduced_wikicreole_parser1; register reduced_wikicreole_parser2) -type interactive_wiki_flow_pplugin = - { ifpp : - 'flow 'flow_without_interactive. - ( ( 'flow - , 'flow_without_interactive ) - Html_types.between_flow5_and_flow5_without_header_footer - , 'flow - , Html_types.phrasing_without_interactive ) - wiki_plugin - } +type interactive_wiki_flow_pplugin = { + ifpp : + 'flow 'flow_without_interactive. + ( ( 'flow, + 'flow_without_interactive ) + Html_types.between_flow5_and_flow5_without_header_footer, + 'flow, + Html_types.phrasing_without_interactive ) + wiki_plugin; +} let register_interactive_wiki_flow_extension ~name ?(reduced = true) ?preparser plugin = @@ -2036,29 +1956,28 @@ let register_interactive_wiki_flow_extension ~name ?(reduced = true) ?preparser register_wiki_extension ~name ~wp:wikicreole_parser_without_header_footer ~wp_rec:wikicreole_parser_without_header_footer ?preparser (plugin.ifpp - :> ( FlowWithoutHeaderFooterTypes.res - , FlowWithoutHeaderFooterTypes.res - , _ ) + :> ( FlowWithoutHeaderFooterTypes.res, + FlowWithoutHeaderFooterTypes.res, + _ ) wiki_plugin); - if reduced - then ( + if reduced then ( register reduced_wikicreole_parser0; register reduced_wikicreole_parser1; register reduced_wikicreole_parser2) -type link_wiki_flow_pplugin = - { lfpp : - 'flow_without_interactive. - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> ([> Html_types.flow5_without_interactive_header_footer ] - as - 'flow_without_interactive) - Html.elt - list - option - -> href * Wikicreole.attribs * 'flow_without_interactive Html.elt list - } +type link_wiki_flow_pplugin = { + lfpp : + 'flow_without_interactive. + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + ([> Html_types.flow5_without_interactive_header_footer ] + as + 'flow_without_interactive) + Html.elt + list + option -> + href * Wikicreole.attribs * 'flow_without_interactive Html.elt list; +} let register_link_flow_extension ~name ?(reduced = true) ?preparser plugin = let plugin wb attribs c = `Flow5_link (plugin.lfpp wb attribs c) in @@ -2067,22 +1986,21 @@ let register_link_flow_extension ~name ?(reduced = true) ?preparser plugin = in register wikicreole_parser; register wikicreole_parser_without_header_footer; - if reduced - then ( + if reduced then ( register reduced_wikicreole_parser0; register reduced_wikicreole_parser1; register reduced_wikicreole_parser2) -type wiki_phrasing_pplugin = - { ppp : - 'phrasing 'phrasing_without_interactive. - ( ( 'phrasing - , 'phrasing_without_interactive ) - Html_types.between_phrasing_and_phrasing_without_interactive - , 'phrasing - , Html_types.phrasing_without_interactive ) - wiki_plugin - } +type wiki_phrasing_pplugin = { + ppp : + 'phrasing 'phrasing_without_interactive. + ( ( 'phrasing, + 'phrasing_without_interactive ) + Html_types.between_phrasing_and_phrasing_without_interactive, + 'phrasing, + Html_types.phrasing_without_interactive ) + wiki_plugin; +} let register_wiki_phrasing_extension ~name ?(reduced = true) ?preparser plugin = let wp_rec = phrasing_wikicreole_parser in @@ -2091,9 +2009,9 @@ let register_wiki_phrasing_extension ~name ?(reduced = true) ?preparser plugin = ~ni_plugin: (plugin.ppp : (FlowTypes.link_content, FlowTypes.link_content, _) wiki_plugin - :> ( FlowTypes.link_content - , FlowTypes.res_without_interactive - , _ ) + :> ( FlowTypes.link_content, + FlowTypes.res_without_interactive, + _ ) wiki_plugin) (plugin.ppp : (FlowTypes.text, FlowTypes.text, _) wiki_plugin @@ -2105,15 +2023,14 @@ let register_wiki_phrasing_extension ~name ?(reduced = true) ?preparser plugin = ~ni_plugin: (plugin.ppp : (FlowTypes.link_content, FlowTypes.link_content, _) wiki_plugin - :> ( _ - , FlowWithoutHeaderFooterTypes.res_without_interactive - , _ ) + :> ( _, + FlowWithoutHeaderFooterTypes.res_without_interactive, + _ ) wiki_plugin) (plugin.ppp : (FlowTypes.text, FlowTypes.text, _) wiki_plugin :> (_, FlowWithoutHeaderFooterTypes.res, _) wiki_plugin); - if reduced - then ( + if reduced then ( register reduced_wikicreole_parser0; register reduced_wikicreole_parser1; register reduced_wikicreole_parser2); @@ -2135,8 +2052,7 @@ let register_interactive_wiki_phrasing_extension ~name ?(reduced = true) (plugin.ppp : (FlowTypes.text, FlowTypes.text, _) wiki_plugin :> (_, FlowWithoutHeaderFooterTypes.res, _) wiki_plugin); - if reduced - then ( + if reduced then ( register reduced_wikicreole_parser0; register reduced_wikicreole_parser1; register reduced_wikicreole_parser2); @@ -2144,12 +2060,12 @@ let register_interactive_wiki_phrasing_extension ~name ?(reduced = true) ~wp:phrasing_wikicreole_parser plugin.ppp type link_wiki_phrasing_pplugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> Html_types.phrasing_without_interactive Html.elt list option - -> href - * Wikicreole.attribs - * Html_types.phrasing_without_interactive Html.elt list + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + Html_types.phrasing_without_interactive Html.elt list option -> + href + * Wikicreole.attribs + * Html_types.phrasing_without_interactive Html.elt list let register_link_phrasing_extension ~name ?(reduced = true) ?preparser (plugin : link_wiki_phrasing_pplugin) = @@ -2160,8 +2076,7 @@ let register_link_phrasing_extension ~name ?(reduced = true) ?preparser in register wikicreole_parser; register wikicreole_parser_without_header_footer; - if reduced - then ( + if reduced then ( register reduced_wikicreole_parser0; register reduced_wikicreole_parser1; register reduced_wikicreole_parser2); @@ -2175,8 +2090,8 @@ let f_block make _ args content = match content with | None -> [ make ?a [] ] | Some content -> - let content = content in - [ make ?a content ]) + let content = content in + [ make ?a content ]) let () = let add_divs wp wp_rec = @@ -2185,11 +2100,12 @@ let () = (* FIXME it won't type without duplicating the 'make' argument... *) register_wiki_extension ~wp ~name ~wp_rec ~ni_plugin:(f_block make') (f_block make)) - [ ("div", Html.div, Html.div) - ; ("aside", Html.aside, Html.aside) - ; ("article", Html.article, Html.article) - ; ("nav", Html.nav, Html.nav) - ; ("section", Html.section, Html.section) + [ + ("div", Html.div, Html.div); + ("aside", Html.aside, Html.aside); + ("article", Html.article, Html.article); + ("nav", Html.nav, Html.nav); + ("section", Html.section, Html.section); ] in add_divs wikicreole_parser wikicreole_parser; @@ -2206,8 +2122,8 @@ let () = ~context:(fun bi _ -> { bi with bi_sectioning = false }) ~wp_rec:wikicreole_parser_without_header_footer ~ni_plugin:(f_block make') (f_block make)) - [ ("header", Html.header, Html.header) - ; ("footer", Html.footer, Html.footer) + [ + ("header", Html.header, Html.header); ("footer", Html.footer, Html.footer); ] (* pre *) @@ -2270,11 +2186,12 @@ let compile_with_content content_text text = let par = cast_wp wikicreole_parser in let bi_with_content c = Wiki_widgets_interface. - { bi_page = Site "" - ; bi_sectioning = false - ; bi_add_link = ignore - ; bi_content = c - ; bi_title = "" + { + bi_page = Site ""; + bi_sectioning = false; + bi_add_link = ignore; + bi_content = c; + bi_title = ""; } in let c = xml_of_wiki par (bi_with_content @@ []) content_text in @@ -2287,21 +2204,22 @@ let () = let file = match (List.assoc_opt "wiki" args, List.assoc_opt "template" args) with | None, None -> - failwith "include: required attribute \"wiki\" or \"template\" missing" + failwith + "include: required attribute \"wiki\" or \"template\" missing" | Some _, Some _ -> - failwith - "include: conflicting attributes \"wiki\" and \"template\" both \ - provided" + failwith + "include: conflicting attributes \"wiki\" and \"template\" both \ + provided" | None, Some wiki -> ( - match (Global.options ()).template with - | Some template -> - let template_dir = Filename.dirname template in - Operators.(template_dir +/+ wiki) - | None -> - failwith "include: extension requires --template to be provided") + match (Global.options ()).template with + | Some template -> + let template_dir = Filename.dirname template in + Operators.(template_dir +/+ wiki) + | None -> + failwith "include: extension requires --template to be provided") | Some wiki, None -> - let current_dir = Global.current_file () |> Filename.dirname in - Operators.(current_dir +/+ wiki) + let current_dir = Global.current_file () |> Filename.dirname in + Operators.(current_dir +/+ wiki) in file |> read_file |> compile |> fun c -> `Flow5 c in diff --git a/src/ohow/wiki_syntax.mli b/src/ohow/wiki_syntax.mli index b8f8f9b..1e61d27 100644 --- a/src/ohow/wiki_syntax.mli +++ b/src/ohow/wiki_syntax.mli @@ -23,21 +23,21 @@ open Tyxml open Wiki_types +type 'res wikicreole_parser (** The abstract type of the objects able to parse wiki creole syntax, possibly with extensions. Those objects are passed as arguments to all displaying functions *) -type 'res wikicreole_parser +type ('res, 'res_without_interactive, 'content_link) ext_wikicreole_parser (** The abstract type for extensible parser. See [register_simple_extension] and [register_wiki_extension].*) -type ('res, 'res_without_interactive, 'content_link) ext_wikicreole_parser -(** Cast an extensible parser to a raw parser to be used with [xml_of_wiki]. *) val cast_wp : ('a, 'b, 'c) ext_wikicreole_parser -> 'a wikicreole_parser +(** Cast an extensible parser to a raw parser to be used with [xml_of_wiki]. *) +val cast_niwp : ('a, 'b, 'c) ext_wikicreole_parser -> 'b wikicreole_parser (** Cast an extensible parser to the associated non_interactive parser to be used with [xml_of_wiki]. *) -val cast_niwp : ('a, 'b, 'c) ext_wikicreole_parser -> 'b wikicreole_parser type href = Wiki_syntax_types.href @@ -45,9 +45,9 @@ val uri_of_href : href -> Html.uri (** Add a syntax extension to an existing parser. *) -type (+'flow - , +'flow_without_interactive - , +'phrasing_without_interactive) +type (+'flow, + +'flow_without_interactive, + +'phrasing_without_interactive) plugin_content = [ `Flow5_link of href * Wikicreole.attribs * 'flow_without_interactive Html.elt list @@ -57,308 +57,296 @@ type (+'flow | `Phrasing_without_interactive of 'phrasing_without_interactive Html.elt list ] -type (+'flow_without_interactive - , +'phrasing_without_interactive) +type (+'flow_without_interactive, + +'phrasing_without_interactive) ni_plugin_content = [ `Flow5 of 'flow_without_interactive Html.elt list | `Phrasing_without_interactive of 'phrasing_without_interactive Html.elt list ] -type (+'flow_without_interactive - , +'phrasing_without_interactive) +type (+'flow_without_interactive, + +'phrasing_without_interactive) link_plugin_content = [ `Flow5_link of href * Wikicreole.attribs * 'flow_without_interactive Html.elt list | `Phrasing_link of - href * Wikicreole.attribs * 'phrasing_without_interactive Html.elt list - ] + href * Wikicreole.attribs * 'phrasing_without_interactive Html.elt list ] -(** The type of extension that can be registred into both the interactive and - non_interactive variant and of a parser. *) -type (+'flow - , +'flow_without_interactive - , +'phrasing_without_interactive) +type (+'flow, + +'flow_without_interactive, + +'phrasing_without_interactive) interactive_simple_plugin = - ( Wiki_widgets_interface.box_info - , ( 'flow - , 'flow_without_interactive - , 'phrasing_without_interactive ) + ( Wiki_widgets_interface.box_info, + ( 'flow, + 'flow_without_interactive, + 'phrasing_without_interactive ) plugin_content ) Wikicreole.plugin +(** The type of extension that can be registred into both the interactive and + non_interactive variant and of a parser. *) -(** The type of extension that can be registred into the interactive variant of - a parser. *) -type (+'flow_without_interactive - , +'phrasing_without_interactive) +type (+'flow_without_interactive, + +'phrasing_without_interactive) non_interactive_simple_plugin = - ( Wiki_widgets_interface.box_info - , ('flow_without_interactive, 'phrasing_without_interactive) ni_plugin_content + ( Wiki_widgets_interface.box_info, + ('flow_without_interactive, 'phrasing_without_interactive) ni_plugin_content ) Wikicreole.plugin +(** The type of extension that can be registred into the interactive variant of + a parser. *) type preparser = Wiki_types.wikibox -> Wikicreole.attribs -> string option -> string option (* Register an extension whose content does not follow the wiki syntax. *) val register_simple_extension : - wp: - ( 'res - , 'flow_without_interactive - , 'phrasing_without_interactive ) - ext_wikicreole_parser - -> name:string - -> ?preparser:preparser - -> ?ni_plugin: - ( 'flow_without_interactive - , 'phrasing_without_interactive ) - non_interactive_simple_plugin - -> ( 'res - , 'flow_without_interactive - , 'phrasing_without_interactive ) - interactive_simple_plugin - -> unit - -type (-'content - , +'flow_without_interactive - , +'phrasing_without_interactive) + wp: + ( 'res, + 'flow_without_interactive, + 'phrasing_without_interactive ) + ext_wikicreole_parser -> + name:string -> + ?preparser:preparser -> + ?ni_plugin: + ( 'flow_without_interactive, + 'phrasing_without_interactive ) + non_interactive_simple_plugin -> + ( 'res, + 'flow_without_interactive, + 'phrasing_without_interactive ) + interactive_simple_plugin -> + unit + +type (-'content, + +'flow_without_interactive, + +'phrasing_without_interactive) wiki_plugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> 'content Html.elt list option - -> ( 'flow_without_interactive - , 'phrasing_without_interactive ) - ni_plugin_content + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + 'content Html.elt list option -> + ('flow_without_interactive, 'phrasing_without_interactive) ni_plugin_content (* Register an extension whose content follow the wiki syntax. *) val register_wiki_extension : - wp: - ( 'res - , 'flow_without_interactive - , 'phrasing_without_interactive ) - ext_wikicreole_parser - -> name:string - -> wp_rec:('a, 'b, 'c) ext_wikicreole_parser - -> ?preparser:preparser - -> ?context: - ( Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> Wiki_widgets_interface.box_info) - -> ?ni_plugin: - ( 'b - , 'flow_without_interactive - , 'phrasing_without_interactive ) - wiki_plugin - -> ('a, 'res, 'phrasing_without_interactive) wiki_plugin - -> unit - -type (-'content - , +'flow_without_interactive - , +'phrasing_without_interactive) + wp: + ( 'res, + 'flow_without_interactive, + 'phrasing_without_interactive ) + ext_wikicreole_parser -> + name:string -> + wp_rec:('a, 'b, 'c) ext_wikicreole_parser -> + ?preparser:preparser -> + ?context: + (Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + Wiki_widgets_interface.box_info) -> + ?ni_plugin: + ('b, 'flow_without_interactive, 'phrasing_without_interactive) wiki_plugin -> + ('a, 'res, 'phrasing_without_interactive) wiki_plugin -> + unit + +type (-'content, + +'flow_without_interactive, + +'phrasing_without_interactive) link_plugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> 'content Html.elt list option - -> ( 'flow_without_interactive - , 'phrasing_without_interactive ) - link_plugin_content + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + 'content Html.elt list option -> + ('flow_without_interactive, 'phrasing_without_interactive) link_plugin_content (* Register an extension whose content follow the wiki syntax. The content is parsed with the non interactive variant of [wp_rec]. *) val register_link_extension : - wp: - ( 'res - , 'flow_without_interactive - , 'phrasing_without_interactive ) - ext_wikicreole_parser - -> name:string - -> wp_rec:('a, 'b, 'c) ext_wikicreole_parser - -> ?preparser: - ( Wiki_types.wikibox - -> Wikicreole.attribs - -> string option - -> string option) - -> ?context: - ( Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> Wiki_widgets_interface.box_info) - -> ('b, 'flow_without_interactive, 'phrasing_without_interactive) link_plugin - -> unit + wp: + ( 'res, + 'flow_without_interactive, + 'phrasing_without_interactive ) + ext_wikicreole_parser -> + name:string -> + wp_rec:('a, 'b, 'c) ext_wikicreole_parser -> + ?preparser: + (Wiki_types.wikibox -> Wikicreole.attribs -> string option -> string option) -> + ?context: + (Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + Wiki_widgets_interface.box_info) -> + ('b, 'flow_without_interactive, 'phrasing_without_interactive) link_plugin -> + unit val register_raw_wiki_extension : - wp:('a, 'b, 'c) ext_wikicreole_parser - -> name:string - -> wp_rec:('d, 'e, 'f) ext_wikicreole_parser - -> ?preparser:preparser - -> ?ni_plugin: - ( 'e wikicreole_parser - -> Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> string option - -> ('b, 'c) ni_plugin_content) - -> ( 'd wikicreole_parser - -> Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> string option - -> ('a, 'b, 'c) plugin_content) - -> unit + wp:('a, 'b, 'c) ext_wikicreole_parser -> + name:string -> + wp_rec:('d, 'e, 'f) ext_wikicreole_parser -> + ?preparser:preparser -> + ?ni_plugin: + ('e wikicreole_parser -> + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + string option -> + ('b, 'c) ni_plugin_content) -> + ('d wikicreole_parser -> + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + string option -> + ('a, 'b, 'c) plugin_content) -> + unit (* Add a "flow" syntax extension to all predefined parser (that accept flow !) *) val register_simple_flow_extension : - name:string - -> ?reduced:bool - -> ?preparser:preparser - -> ( [< Html_types.flow5_without_interactive_header_footer ] - , [< Html_types.phrasing_without_interactive ] ) - non_interactive_simple_plugin - -> unit + name:string -> + ?reduced:bool -> + ?preparser:preparser -> + ( [< Html_types.flow5_without_interactive_header_footer ], + [< Html_types.phrasing_without_interactive ] ) + non_interactive_simple_plugin -> + unit val register_interactive_simple_flow_extension : - name:string - -> ?reduced:bool - -> ?preparser:preparser - -> ( [< Html_types.flow5_without_header_footer ] - , [< Html_types.flow5_without_interactive_header_footer ] - , [< Html_types.phrasing_without_interactive ] ) - interactive_simple_plugin - -> unit + name:string -> + ?reduced:bool -> + ?preparser:preparser -> + ( [< Html_types.flow5_without_header_footer ], + [< Html_types.flow5_without_interactive_header_footer ], + [< Html_types.phrasing_without_interactive ] ) + interactive_simple_plugin -> + unit type +'without_interactive link_simple_plugin = - ( Wiki_widgets_interface.box_info - , href * Wikicreole.attribs * 'without_interactive Html.elt list ) + ( Wiki_widgets_interface.box_info, + href * Wikicreole.attribs * 'without_interactive Html.elt list ) Wikicreole.plugin val register_link_simple_flow_extension : - name:string - -> ?reduced:bool - -> ?preparser:preparser - -> [< Html_types.flow5_without_interactive_header_footer ] link_simple_plugin - -> unit - -type wiki_flow_pplugin = - { fpp : - 'flow. - ( 'flow - Html_types.between_flow5_and_flow5_without_interactive_header_footer - , 'flow - , Html_types.phrasing_without_interactive ) - wiki_plugin - } + name:string -> + ?reduced:bool -> + ?preparser:preparser -> + [< Html_types.flow5_without_interactive_header_footer ] link_simple_plugin -> + unit + +type wiki_flow_pplugin = { + fpp : + 'flow. + ( 'flow Html_types.between_flow5_and_flow5_without_interactive_header_footer, + 'flow, + Html_types.phrasing_without_interactive ) + wiki_plugin; +} val register_wiki_flow_extension : - name:string - -> ?reduced:bool - -> ?preparser:preparser - -> wiki_flow_pplugin - -> unit - -type interactive_wiki_flow_pplugin = - { ifpp : - 'flow 'flow_without_interactive. - ( ( 'flow - , 'flow_without_interactive ) - Html_types.between_flow5_and_flow5_without_header_footer - , 'flow - , Html_types.phrasing_without_interactive ) - wiki_plugin - } + name:string -> + ?reduced:bool -> + ?preparser:preparser -> + wiki_flow_pplugin -> + unit + +type interactive_wiki_flow_pplugin = { + ifpp : + 'flow 'flow_without_interactive. + ( ( 'flow, + 'flow_without_interactive ) + Html_types.between_flow5_and_flow5_without_header_footer, + 'flow, + Html_types.phrasing_without_interactive ) + wiki_plugin; +} val register_interactive_wiki_flow_extension : - name:string - -> ?reduced:bool - -> ?preparser:preparser - -> interactive_wiki_flow_pplugin - -> unit - -type link_wiki_flow_pplugin = - { lfpp : - 'flow_without_interactive. - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> ([> Html_types.flow5_without_interactive_header_footer ] - as - 'flow_without_interactive) - Html.elt - list - option - -> href * Wikicreole.attribs * 'flow_without_interactive Html.elt list - } + name:string -> + ?reduced:bool -> + ?preparser:preparser -> + interactive_wiki_flow_pplugin -> + unit + +type link_wiki_flow_pplugin = { + lfpp : + 'flow_without_interactive. + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + ([> Html_types.flow5_without_interactive_header_footer ] + as + 'flow_without_interactive) + Html.elt + list + option -> + href * Wikicreole.attribs * 'flow_without_interactive Html.elt list; +} val register_link_flow_extension : - name:string - -> ?reduced:bool - -> ?preparser:preparser - -> link_wiki_flow_pplugin - -> unit + name:string -> + ?reduced:bool -> + ?preparser:preparser -> + link_wiki_flow_pplugin -> + unit (* Add a "phrasing" syntax extension to all predefined parser *) val register_simple_phrasing_extension : - name:string - -> ?reduced:bool - -> ?preparser:preparser - -> ( [< Html_types.phrasing_without_interactive ] - , [< Html_types.phrasing_without_interactive ] ) - non_interactive_simple_plugin - -> unit + name:string -> + ?reduced:bool -> + ?preparser:preparser -> + ( [< Html_types.phrasing_without_interactive ], + [< Html_types.phrasing_without_interactive ] ) + non_interactive_simple_plugin -> + unit val register_interactive_simple_phrasing_extension : - name:string - -> ?reduced:bool - -> ?preparser:preparser - -> ( Html_types.phrasing - , Html_types.phrasing_without_interactive - , Html_types.phrasing_without_interactive ) - interactive_simple_plugin - -> unit + name:string -> + ?reduced:bool -> + ?preparser:preparser -> + ( Html_types.phrasing, + Html_types.phrasing_without_interactive, + Html_types.phrasing_without_interactive ) + interactive_simple_plugin -> + unit val register_link_simple_phrasing_extension : - name:string - -> ?reduced:bool - -> ?preparser:preparser - -> [< Html_types.phrasing_without_interactive ] link_simple_plugin - -> unit - -type wiki_phrasing_pplugin = - { ppp : - 'phrasing 'phrasing_without_interactive. - ( ( 'phrasing - , 'phrasing_without_interactive ) - Html_types.between_phrasing_and_phrasing_without_interactive - , 'phrasing - , Html_types.phrasing_without_interactive ) - wiki_plugin - } + name:string -> + ?reduced:bool -> + ?preparser:preparser -> + [< Html_types.phrasing_without_interactive ] link_simple_plugin -> + unit + +type wiki_phrasing_pplugin = { + ppp : + 'phrasing 'phrasing_without_interactive. + ( ( 'phrasing, + 'phrasing_without_interactive ) + Html_types.between_phrasing_and_phrasing_without_interactive, + 'phrasing, + Html_types.phrasing_without_interactive ) + wiki_plugin; +} val register_wiki_phrasing_extension : - name:string - -> ?reduced:bool - -> ?preparser:preparser - -> wiki_phrasing_pplugin - -> unit + name:string -> + ?reduced:bool -> + ?preparser:preparser -> + wiki_phrasing_pplugin -> + unit val register_interactive_wiki_phrasing_extension : - name:string - -> ?reduced:bool - -> ?preparser:preparser - -> wiki_phrasing_pplugin - -> unit + name:string -> + ?reduced:bool -> + ?preparser:preparser -> + wiki_phrasing_pplugin -> + unit type link_wiki_phrasing_pplugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> Html_types.phrasing_without_interactive Html.elt list option - -> href - * Wikicreole.attribs - * Html_types.phrasing_without_interactive Html.elt list + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + Html_types.phrasing_without_interactive Html.elt list option -> + href + * Wikicreole.attribs + * Html_types.phrasing_without_interactive Html.elt list val register_link_phrasing_extension : - name:string - -> ?reduced:bool - -> ?preparser:preparser - -> link_wiki_phrasing_pplugin - -> unit + name:string -> + ?reduced:bool -> + ?preparser:preparser -> + link_wiki_phrasing_pplugin -> + unit (******) @@ -367,93 +355,93 @@ val register_link_phrasing_extension : parser. *) val wikicreole_parser : - ( Html_types.flow5 - , Html_types.flow5_without_interactive - , Html_types.phrasing_without_interactive ) + ( Html_types.flow5, + Html_types.flow5_without_interactive, + Html_types.phrasing_without_interactive ) ext_wikicreole_parser -(** The same parser as [wikicreole_parser] but with a more precise type. *) val wikicreole_parser_without_header_footer : - ( Html_types.flow5_without_header_footer - , Html_types.flow5_without_interactive_header_footer - , Html_types.phrasing_without_interactive ) + ( Html_types.flow5_without_header_footer, + Html_types.flow5_without_interactive_header_footer, + Html_types.phrasing_without_interactive ) ext_wikicreole_parser +(** The same parser as [wikicreole_parser] but with a more precise type. *) -(** The same, without subwikiboxes and containers (content). Used for example - for forum messages. *) val reduced_wikicreole_parser0 : - ( Html_types.flow5 - , Html_types.flow5_without_interactive - , Html_types.phrasing_without_interactive ) + ( Html_types.flow5, + Html_types.flow5_without_interactive, + Html_types.phrasing_without_interactive ) ext_wikicreole_parser +(** The same, without subwikiboxes and containers (content). Used for example + for forum messages. *) -(** The same, without images, objects, subwikiboxes and containers (content). - Used for example for forum messages with restricted features. *) val reduced_wikicreole_parser1 : - ( Html_types.flow5 - , Html_types.flow5_without_interactive - , Html_types.phrasing_without_interactive ) + ( Html_types.flow5, + Html_types.flow5_without_interactive, + Html_types.phrasing_without_interactive ) ext_wikicreole_parser +(** The same, without images, objects, subwikiboxes and containers (content). + Used for example for forum messages with restricted features. *) -(** The same, without images, objects, titles, tables, lists, subwikiboxes and - containers (content). *) val reduced_wikicreole_parser2 : - ( Html_types.flow5 - , Html_types.flow5_without_interactive - , Html_types.phrasing_without_interactive ) + ( Html_types.flow5, + Html_types.flow5_without_interactive, + Html_types.phrasing_without_interactive ) ext_wikicreole_parser +(** The same, without images, objects, titles, tables, lists, subwikiboxes and + containers (content). *) -(** For button content. *) val reduced_wikicreole_parser_button_content : - ( Html_types.button_content - , Html_types.button_content - , Html_types.button_content ) + ( Html_types.button_content, + Html_types.button_content, + Html_types.button_content ) ext_wikicreole_parser +(** For button content. *) -(** Parser for phrasing wikicreole. *) val phrasing_wikicreole_parser : - ( Html_types.phrasing - , Html_types.phrasing_without_interactive - , Html_types.phrasing_without_interactive ) + ( Html_types.phrasing, + Html_types.phrasing_without_interactive, + Html_types.phrasing_without_interactive ) ext_wikicreole_parser +(** Parser for phrasing wikicreole. *) -(** Parser for menu *) val menu_parser : - ( [ `H1 | `H2 | `H3 | `H4 | `H5 | `H6 ] - , [ `H1 | `H2 | `H3 | `H4 | `H5 | `H6 ] - , Html_types.phrasing_without_interactive ) + ( [ `H1 | `H2 | `H3 | `H4 | `H5 | `H6 ], + [ `H1 | `H2 | `H3 | `H4 | `H5 | `H6 ], + Html_types.phrasing_without_interactive ) ext_wikicreole_parser +(** Parser for menu *) val preprocess_extension : 'res wikicreole_parser -> Wiki_models.wiki_preprocessor -(** Returns the HTML5 corresponding to a wiki page *) val xml_of_wiki : - 'res wikicreole_parser - -> Wiki_widgets_interface.box_info - -> string - -> 'res Html.elt list + 'res wikicreole_parser -> + Wiki_widgets_interface.box_info -> + string -> + 'res Html.elt list +(** Returns the HTML5 corresponding to a wiki page *) -(** Returns the wiki syntax for an extension box from its name, arguments and - content. *) val string_of_extension : string -> (string * string) list -> string option -> string +(** Returns the wiki syntax for an extension box from its name, arguments and + content. *) -(** parses common attributes ([class], [id], [style]) *) val parse_common_attribs : - ?classes:Html_types.nmtokens - -> Wikicreole.attribs - -> [> Html_types.common ] Html.attrib list + ?classes:Html_types.nmtokens -> + Wikicreole.attribs -> + [> Html_types.common ] Html.attrib list +(** parses common attributes ([class], [id], [style]) *) +val class_wikibox : wikibox -> string (** The class to use to denote the fact that the content comes from the specified wikibox *) -val class_wikibox : wikibox -> string -(** Compiles a wikicreole string and returns its Tyxml structure. *) val compile : string -> Html_types.flow5 Tyxml.Html.elt list +(** Compiles a wikicreole string and returns its Tyxml structure. *) +val compile_with_content : + string -> string -> Html_types.flow5 Tyxml.Html.elt list (** [compile_with_content content wiki] first compiles [content] and then compiles [wiki] with the result of [content]'s compilation to be used by the [<>] extension. *) -val compile_with_content : - string -> string -> Html_types.flow5 Tyxml.Html.elt list diff --git a/src/ohow/wiki_syntax_types.mli b/src/ohow/wiki_syntax_types.mli index 8f20119..9e2c02c 100644 --- a/src/ohow/wiki_syntax_types.mli +++ b/src/ohow/wiki_syntax_types.mli @@ -2,82 +2,80 @@ open Tyxml type href = | Absolute of string - | Document of - { document : Document.t - ; fragment : string option - } + | Document of { document : Document.t; fragment : string option } -type desugar_param = - { dc_page_wiki : Wiki_types.wiki - ; dc_page_path : string list option - ; mutable dc_warnings : ((int * int) * string) list - } +type desugar_param = { + dc_page_wiki : Wiki_types.wiki; + dc_page_path : string list option; + mutable dc_warnings : ((int * int) * string) list; +} +type link_action = + string -> + string option -> + Wikicreole.attribs -> + Wiki_types.wikibox -> + string option (** Type of an action executed on a link in a [Preprocessor.preparse_string]. If it returns [Some address] (in LWT), the original address of the link is replaced by [address]. The address of the link is kept when the [link_action] return [None.] *) -type link_action = - string - -> string option - -> Wikicreole.attribs - -> Wiki_types.wikibox - -> string option module type Preprocessor = sig + val desugar_string : + ?href_action:link_action -> + ?link_action:link_action -> + desugar_param -> + string -> + string (** [desugar_string dc content] does some possible syntactical desugaring in [content]. It should be safe to call this, i.e. there shall be no side effects in it. *) - val desugar_string : - ?href_action:link_action - -> ?link_action:link_action - -> desugar_param - -> string - -> string + val preparse_string : + ?href_action:link_action -> + ?link_action:link_action -> + Wiki_types.wikibox -> + string -> + string (** [preparse_string wb content] does possibly some replacements in [content] and may have arbitrary side effects in the process (e.g. creating wikiboxes etc.). *) - val preparse_string : - ?href_action:link_action - -> ?link_action:link_action - -> Wiki_types.wikibox - -> string - -> string end -(** Module type for representing wikicreole parser whose return type id [ret]. *) +(** Module type for representing wikicreole parser whose return type id [ret]. +*) module type Parser = sig include Preprocessor type res val from_string : - sectioning:bool - -> Wiki_widgets_interface.box_info - -> string - -> res Html.elt list list + sectioning:bool -> + Wiki_widgets_interface.box_info -> + string -> + res Html.elt list list end +type 'a wikicreole_parser = (module Parser with type res = 'a) (** A wikicreole_parser is essentially a [Wikicreole.builder] object but easily extensible. That is, the fields [plugin] and [plugin_action] of [Wikicreole.builder], which are supposed to be functions, are here represented as association tables. Thus, it becomes easy (and, more importantly, not costly) to add extensions. *) -type 'a wikicreole_parser = (module Parser with type res = 'a) +type preparser = + Wiki_types.wikibox -> Wikicreole.attribs -> string option -> string option (** Preparser are actually used to rewrite contents of wiki extension when storing a wikipage on the database. This is currently used only for creating wikibox. *) -type preparser = - Wiki_types.wikibox -> Wikicreole.attribs -> string option -> string option type desugarer = desugar_param -> Wikicreole.attribs -> string option -> string option -type (+'flow - , +'flow_without_interactive - , +'phrasing_without_interactive) +type (+'flow, + +'flow_without_interactive, + +'phrasing_without_interactive) plugin_content = [ `Flow5_link of href * Wikicreole.attribs * 'flow_without_interactive Html.elt list @@ -87,21 +85,20 @@ type (+'flow | `Phrasing_without_interactive of 'phrasing_without_interactive Html.elt list ] -type (+'flow_without_interactive - , +'phrasing_without_interactive) +type (+'flow_without_interactive, + +'phrasing_without_interactive) ni_plugin_content = [ `Flow5 of 'flow_without_interactive Html.elt list | `Phrasing_without_interactive of 'phrasing_without_interactive Html.elt list ] -type (+'flow_without_interactive - , +'phrasing_without_interactive) +type (+'flow_without_interactive, + +'phrasing_without_interactive) link_plugin_content = [ `Flow5_link of href * Wikicreole.attribs * 'flow_without_interactive Html.elt list | `Phrasing_link of - href * Wikicreole.attribs * 'phrasing_without_interactive Html.elt list - ] + href * Wikicreole.attribs * 'phrasing_without_interactive Html.elt list ] (** Module type for representing extensible wikicreole parser on which we can register wiki extension. *) @@ -113,46 +110,46 @@ module rec ExtParser : sig type link_content type wikiparser = - ( res - , res_without_interactive - , link_content ) + ( res, + res_without_interactive, + link_content ) ExtParser.ext_wikicreole_parser val from_string_without_interactive : - sectioning:bool - -> Wiki_widgets_interface.box_info - -> string - -> res_without_interactive Html.elt list list + sectioning:bool -> + Wiki_widgets_interface.box_info -> + string -> + res_without_interactive Html.elt list list type simple_plugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> string option - -> (res, res_without_interactive, link_content) plugin_content + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + string option -> + (res, res_without_interactive, link_content) plugin_content type simple_ni_plugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> string option - -> (res_without_interactive, link_content) ni_plugin_content + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + string option -> + (res_without_interactive, link_content) ni_plugin_content type 'a wiki_plugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> 'a Html.elt list option - -> (res, res_without_interactive, link_content) plugin_content + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + 'a Html.elt list option -> + (res, res_without_interactive, link_content) plugin_content type 'a wiki_ni_plugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> 'a Html.elt list option - -> (res_without_interactive, link_content) ni_plugin_content + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + 'a Html.elt list option -> + (res_without_interactive, link_content) ni_plugin_content type 'a link_plugin = - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> 'a Html.elt list option - -> (res_without_interactive, link_content) link_plugin_content + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + 'a Html.elt list option -> + (res_without_interactive, link_content) link_plugin_content (* Module to encode existential type parameter of the recursive wikiparser. Could be replaced by a GADT with Ocaml 3.13. *) @@ -162,15 +159,15 @@ module rec ExtParser : sig type rec_link_content val wikiparser : - ( rec_res - , rec_res_without_interactive - , rec_link_content ) + ( rec_res, + rec_res_without_interactive, + rec_link_content ) ExtParser.ext_wikicreole_parser val update_context : - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> Wiki_widgets_interface.box_info + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + Wiki_widgets_interface.box_info val plugin : rec_res wiki_plugin val ni_plugin : rec_res_without_interactive wiki_ni_plugin option @@ -182,15 +179,15 @@ module rec ExtParser : sig type rec_link_content val wikiparser : - ( rec_res - , rec_res_without_interactive - , rec_link_content ) + ( rec_res, + rec_res_without_interactive, + rec_link_content ) ExtParser.ext_wikicreole_parser val update_context : - Wiki_widgets_interface.box_info - -> Wikicreole.attribs - -> Wiki_widgets_interface.box_info + Wiki_widgets_interface.box_info -> + Wikicreole.attribs -> + Wiki_widgets_interface.box_info val plugin : rec_res_without_interactive link_plugin end @@ -201,9 +198,9 @@ module rec ExtParser : sig type rec_link_content val wikiparser : - ( rec_res - , rec_res_without_interactive - , rec_link_content ) + ( rec_res, + rec_res_without_interactive, + rec_link_content ) ExtParser.ext_wikicreole_parser val plugin : rec_res wikicreole_parser -> simple_plugin diff --git a/src/ohow/wiki_widgets_interface.ml b/src/ohow/wiki_widgets_interface.ml index 70c6631..c843970 100644 --- a/src/ohow/wiki_widgets_interface.ml +++ b/src/ohow/wiki_widgets_interface.ml @@ -1,9 +1,9 @@ open Tyxml -type box_info = - { bi_page : Document.t - ; bi_sectioning : bool - ; bi_add_link : Document.t -> unit - ; bi_content : Html_types.flow5 Html.elt list - ; bi_title : string - } +type box_info = { + bi_page : Document.t; + bi_sectioning : bool; + bi_add_link : Document.t -> unit; + bi_content : Html_types.flow5 Html.elt list; + bi_title : string; +} diff --git a/src/ohow/wikicreole.mli b/src/ohow/wikicreole.mli deleted file mode 100644 index 26fadbd..0000000 --- a/src/ohow/wikicreole.mli +++ /dev/null @@ -1,129 +0,0 @@ -(* Ocsimore - * Copyright (C) 2008 - * Laboratoire PPS - Universit� Paris Diderot - CNRS - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *) -(** Parser for Wikicreole - - @author Jerome Vouillon - @author Vincent Balat - @author Boris Yakobowski *) - -(** Xml-like attributes for the extension (eg val='foo') *) -type attribs = (string * string) list - -module type RawBuilder = sig - type href - type param - type phrasing_without_interactive - type phrasing - type flow - type flow_without_interactive - type uo_list - - val chars : string -> phrasing_without_interactive - val strong_elem : attribs -> phrasing list -> phrasing_without_interactive - val em_elem : attribs -> phrasing list -> phrasing_without_interactive - val br_elem : attribs -> phrasing_without_interactive - val img_elem : attribs -> href -> string -> phrasing_without_interactive - val tt_elem : attribs -> phrasing list -> phrasing_without_interactive - val monospace_elem : attribs -> phrasing list -> phrasing_without_interactive - val underlined_elem : attribs -> phrasing list -> phrasing_without_interactive - - val linethrough_elem : - attribs -> phrasing list -> phrasing_without_interactive - - val subscripted_elem : - attribs -> phrasing list -> phrasing_without_interactive - - val superscripted_elem : - attribs -> phrasing list -> phrasing_without_interactive - - val nbsp : phrasing_without_interactive - val endash : phrasing_without_interactive - val emdash : phrasing_without_interactive - - val a_elem_phrasing : - attribs -> href -> phrasing_without_interactive list -> phrasing - - val a_elem_flow : attribs -> href -> flow_without_interactive list -> flow - val make_href : param -> string -> string option -> href - - (* the string option is the fragment part of the URL (#...)*) - - val string_of_href : href -> string - val p_elem : attribs -> phrasing list -> flow_without_interactive - val pre_elem : attribs -> string list -> flow_without_interactive - val h1_elem : attribs -> phrasing list -> flow_without_interactive - val h2_elem : attribs -> phrasing list -> flow_without_interactive - val h3_elem : attribs -> phrasing list -> flow_without_interactive - val h4_elem : attribs -> phrasing list -> flow_without_interactive - val h5_elem : attribs -> phrasing list -> flow_without_interactive - val h6_elem : attribs -> phrasing list -> flow_without_interactive - val section_elem : attribs -> flow list -> flow_without_interactive - - val ul_elem : - attribs -> (phrasing list * uo_list option * attribs) list -> uo_list - - val ol_elem : - attribs -> (phrasing list * uo_list option * attribs) list -> uo_list - - val dl_elem : - attribs -> (bool * phrasing list * attribs) list -> flow_without_interactive - - val hr_elem : attribs -> flow_without_interactive - - val table_elem : - attribs - -> ((bool * attribs * phrasing list) list * attribs) list - -> flow_without_interactive - - val phrasing : phrasing_without_interactive -> phrasing - val flow : flow_without_interactive -> flow - val list : uo_list -> flow_without_interactive - val error : string -> phrasing_without_interactive -end - -(** *) -type (-'param, +'res) plugin = 'param -> attribs -> string option -> 'res - -type plugin_resolver = Resolver of (string -> plugin_resolver option) - -module type Builder = sig - include RawBuilder - - type plugin_content = - [ `Flow5_link of href * attribs * flow_without_interactive - | `Phrasing_link of href * attribs * phrasing_without_interactive - | `Flow5 of flow - | `Phrasing_without_interactive of phrasing_without_interactive - ] - - val plugin : string -> plugin_resolver option * (param, plugin_content) plugin - val plugin_action : string -> int -> int -> (param, unit) plugin - - val link_action : - string -> string option -> attribs -> int * int -> param -> unit - - val href_action : - string -> string option -> attribs -> int * int -> param -> unit -end - -type ('param, 'res) builder = - (module Builder with type param = 'param and type flow = 'res) - -val from_string : - ?sectioning:bool -> 'param -> ('param, 'res) builder -> string -> 'res list diff --git a/src/wit/dune b/src/wit/dune index 9c02af9..e6c807e 100644 --- a/src/wit/dune +++ b/src/wit/dune @@ -1,5 +1,5 @@ -(executables - (names wit) - (public_names wit) +(executable + (name wit) + (public_name wit) (package html_of_wiki) (libraries cmdliner re)) diff --git a/src/wit/wit.ml b/src/wit/wit.ml index 5bb42ce..ada3f5e 100644 --- a/src/wit/wit.ml +++ b/src/wit/wit.ml @@ -29,8 +29,8 @@ let main template = match replace_content_tag tmpl wiki with | Some replacement -> print_string replacement | None -> - Printf.fprintf stderr "no <> tag found in template\n"; - exit 1 + Printf.fprintf stderr "no <> tag found in template\n"; + exit 1 let tmpl_cmd = let doc = "The template to put the wiki into." in @@ -43,16 +43,17 @@ let info_cmd = "Inlines a wikicreole file into another one with a <> tag." in let man = - [ `S Manpage.s_description - ; `P + [ + `S Manpage.s_description; + `P "$(tname) reads wikicreole content from stdin and inserts it inside \ the given template file $(b,TMPL) in place of the first <> \ - tag found and outputs the result on stdout." - ; `P "The $(b,TMPL) file is never modified." - ; `S Manpage.s_bugs - ; `P + tag found and outputs the result on stdout."; + `P "The $(b,TMPL) file is never modified."; + `S Manpage.s_bugs; + `P "Escaping <> tags has no effect, the tag is still \ - recognized." + recognized."; ] in Cmd.info "wit" ~version:"v0.0.0" ~doc ~man) diff --git a/wit-help.txt b/wit-help.txt index 242bec7..2c92bff 100644 --- a/wit-help.txt +++ b/wit-help.txt @@ -26,7 +26,7 @@ COMMON OPTIONS Show version information. EXIT STATUS - wit exits with the following status: + wit exits with: 0 on success.