File tree Expand file tree Collapse file tree 5 files changed +44
-9
lines changed Expand file tree Collapse file tree 5 files changed +44
-9
lines changed Original file line number Diff line number Diff line change @@ -130,15 +130,34 @@ and link_content_of_inline_elements l =
130
130
l |> List. map link_content_of_inline_element |> List. concat
131
131
132
132
let find_zero_heading docs : link_content option =
133
- let rec find_map f = function
134
- | [] -> None
135
- | x :: l -> (
136
- match f x with Some _ as result -> result | None -> find_map f l)
137
- in
138
- find_map
133
+ Odoc_utils.List. find_map
139
134
(fun doc ->
140
135
match doc.Location_. value with
141
136
| `Heading ({ heading_level = `Title ; _ } , _ , h_content ) ->
142
137
Some (link_content_of_inline_elements h_content)
143
138
| _ -> None )
144
139
docs
140
+
141
+ let extract_frontmatter docs : _ =
142
+ let parse_frontmatter s =
143
+ let lines = Astring.String. cuts ~sep: " \n " s in
144
+ Odoc_utils.List. filter_map
145
+ (fun line -> Astring.String. cut ~sep: " :" line)
146
+ lines
147
+ in
148
+ let extracted =
149
+ let rec aux acc = function
150
+ | [] -> None
151
+ | doc :: l -> (
152
+ match doc.Location_. value with
153
+ | `Code_block (Some "frontmatter" , content , None) ->
154
+ Some
155
+ ( parse_frontmatter content.Location_. value,
156
+ List. rev_append acc l )
157
+ | _ -> aux (doc :: acc) l)
158
+ in
159
+ aux [] docs
160
+ in
161
+ match extracted with
162
+ | None -> (None , docs)
163
+ | Some (fm , docs ) -> (Some fm, docs)
Original file line number Diff line number Diff line change 16
16
(backend landmarks --auto))
17
17
(instrumentation
18
18
(backend bisect_ppx))
19
- (libraries result compiler-libs.common odoc-parser))
19
+ (libraries result compiler-libs.common odoc-parser odoc_utils ))
Original file line number Diff line number Diff line change @@ -527,11 +527,16 @@ end =
527
527
module rec Page : sig
528
528
type child = Page_child of string | Module_child of string
529
529
530
+ module Frontmatter : sig
531
+ type t = (string * string ) list
532
+ end
533
+
530
534
type t = {
531
535
name : Identifier.Page .t ;
532
536
root : Root .t ;
533
537
content : Comment .docs ;
534
538
children : child list ;
539
+ frontmatter : Frontmatter .t option ;
535
540
digest : Digest .t ;
536
541
linked : bool ;
537
542
}
Original file line number Diff line number Diff line change @@ -238,12 +238,14 @@ let mld ~parent_id ~parents_children ~output ~children ~warnings_options input =
238
238
>> = fun name ->
239
239
let resolve content =
240
240
let zero_heading = Comment. find_zero_heading content in
241
+ let frontmatter, content = Comment. extract_frontmatter content in
241
242
let root =
242
243
let file = Root.Odoc_file. create_page root_name zero_heading in
243
244
{ Root. id = (name :> Paths.Identifier.OdocId.t ); file; digest }
244
245
in
245
246
let page =
246
- Lang.Page. { name; root; children; content; digest; linked = false }
247
+ Lang.Page.
248
+ { name; root; children; content; digest; linked = false ; frontmatter }
247
249
in
248
250
Odoc_file. save_page output ~warnings: [] page;
249
251
Ok ()
Original file line number Diff line number Diff line change @@ -15,9 +15,18 @@ let from_mld ~xref_base_uri ~resolver ~output ~warnings_options input =
15
15
in
16
16
let to_html content =
17
17
(* This is a mess. *)
18
+ let frontmatter, content = Odoc_model.Comment. extract_frontmatter content in
18
19
let page =
19
20
Odoc_model.Lang.Page.
20
- { name = id; root; content; children = [] ; digest; linked = false }
21
+ {
22
+ name = id;
23
+ root;
24
+ content;
25
+ children = [] ;
26
+ digest;
27
+ linked = false ;
28
+ frontmatter;
29
+ }
21
30
in
22
31
let env = Resolver. build_env_for_page resolver page in
23
32
Odoc_xref2.Link. resolve_page ~filename: input_s env page
You can’t perform that action at this time.
0 commit comments