package forester

  1. Overview
  2. Docs
A tool for tending mathematical forests

Install

Dune Dependency

Authors

Maintainers

Sources

4.2.0.tar.gz
md5=7543fe7acbdfeb2056dc0b774965239f
sha512=2317bf84588692bbbd40e5fa944faab4889474e4a058e336bd1165f6dd8e55e8979affab098248c87354acdc3b6e6927305553ff5ab6b002b6739719814ec080

doc/src/forester.render/Render_json.ml.html

Source file Render_json.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
open Forester_prelude
open Forester_core
open Sem

let render_tree ~root ~trees ~dev (doc : Sem.tree) =
  let addr = doc.fm.addr in
  let title =
    match doc.fm.title with
    | None -> `Null
    | Some title ->
      let title = Render_util.expand_title_with_parents ~trees doc.fm title in
      let title_string =
        String.trim @@
        String_util.sentence_case @@
        Render_text.Printer.contents @@
        Render_text.render ~trees title
      in
      `String title_string
  in
  let
    taxon =
    match doc.fm.taxon with
    | None -> `Null
    | Some taxon -> `String (String_util.sentence_case taxon)
  in
  let tags = `List (List.map (fun t -> `String t) doc.fm.tags) in
  let route = `String (Serialise_xml_tree.route ~root addr) in
  let metas =
    let meta_string meta =
      String.trim @@
      String_util.sentence_case @@
      Render_text.Printer.contents @@
      Render_text.render ~trees meta
    in
    `Assoc
      (List.map (fun (s, meta) -> (s, `String (meta_string meta)))
         doc.fm.metas)
  in
  let
    path =
    if dev then
      match doc.fm.source_path with
      | Some p -> [("sourcePath", `String p)]
      | None -> []
    else []
  in
  match addr with
  | User_addr addr ->
    Some
      (addr,
       `Assoc
         ( path @
           [("title", title);
            ("taxon", taxon);
            ("tags", tags);
            ("route",route);
            ("metas", metas);
           ]))
  | _ -> None

let render_trees ~(dev : bool) ~root (trees : Sem.tree Addr_map.t) : Yojson.Basic.t =
  `Assoc begin
    Addr_map.to_seq trees
    |> Seq.map snd
    |> List.of_seq
    |> Sem.Util.sort_for_index
    |> List.filter_map (render_tree ~root ~trees ~dev)
  end

OCaml

Innovation. Community. Security.