this repo has no description
at main 103 lines 3.0 kB view raw
1module Of_document = struct 2 (** Get plain text doc-comment from a doc comment *) 3 4 let rec source s = 5 let token = function 6 | Odoc_document.Types.Source.Elt e -> inline e 7 | Tag (_, t) -> source t 8 in 9 String.concat "" @@ List.map token s 10 11 and inline i = 12 let one o = 13 match o.Odoc_document.Types.Inline.desc with 14 | Text t -> t 15 | Entity "#45" -> "-" 16 | Entity "gt" -> ">" 17 | Entity e -> "&" ^ e 18 | Linebreak -> "\n" 19 | Styled (_, t) -> inline t 20 | Link { content; _ } -> inline content 21 | Source s -> source s 22 | Math m -> m 23 | Raw_markup _ -> "" 24 in 25 String.concat "" @@ List.map one i 26 27 let rec documented_src d = 28 let one o = 29 match o with 30 | Odoc_document.Types.DocumentedSrc.Code c -> source c 31 | Documented { code; _ } -> inline code 32 | Nested { code; _ } -> documented_src code 33 | Subpage _ -> "" 34 | Alternative (Expansion { summary; _ }) -> source summary 35 in 36 String.concat "" @@ List.map one d 37end 38 39module Of_comments = struct 40 (** Get plain text doc-comment from a doc comment *) 41 42 let get_value x = x.Odoc_model.Location_.value 43 44 let rec string_of_doc (doc : Odoc_model.Comment.elements) = 45 doc |> List.map get_value 46 |> List.map s_of_block_element 47 |> String.concat "\n" 48 49 and s_of_block_element (be : Odoc_model.Comment.block_element) = 50 match be with 51 | `Paragraph is -> inlines is 52 | `Tag _ -> "" 53 | `List (_, ls) -> 54 List.map (fun x -> x |> List.map get_value |> List.map nestable) ls 55 |> List.concat |> String.concat " " 56 | `Heading (_, _, h) -> inlines h 57 | `Modules _ -> "" 58 | `Code_block c -> c.content |> get_value 59 | `Verbatim v -> v 60 | `Math_block m -> m 61 | `Media (_, _, is) -> is 62 | `Table _ -> (* TODO *) "" 63 64 and nestable (n : Odoc_model.Comment.nestable_block_element) = 65 s_of_block_element (n :> Odoc_model.Comment.block_element) 66 67 and inlines is = 68 is |> List.map get_value |> List.map inline |> String.concat "" 69 70 and inline (i : Odoc_model.Comment.inline_element) = 71 match i with 72 | `Code_span s -> s 73 | `Word w -> w 74 | `Math_span m -> m 75 | `Space -> " " 76 | `Reference (_, c) -> link_content c 77 | `Link (_, c) -> link_content c 78 | `Styled (_, b) -> inlines b 79 | `Raw_markup (_, _) -> "" 80 81 and link_content l = 82 l |> List.map get_value 83 |> List.map non_link_inline_element 84 |> String.concat "" 85 86 and non_link_inline_element (n : Odoc_model.Comment.non_link_inline_element) = 87 inline (n :> Odoc_model.Comment.inline_element) 88end 89 90let of_type te = 91 let te_text = Odoc_document.ML.type_expr te in 92 let te_doc = Odoc_document.Codefmt.render te_text in 93 Of_document.source te_doc 94 95let of_doc doc = Of_comments.string_of_doc doc 96 97let of_record fields = 98 let te_text = Odoc_document.ML.record fields in 99 Of_document.documented_src te_text 100 101let of_unboxed_record fields = 102 let te_text = Odoc_document.ML.unboxed_record fields in 103 Of_document.documented_src te_text