@@ -36,6 +36,27 @@ let rec source_contains_text (s : Source.t) =
3636  in 
3737  List. exists check_source s
3838
39+ (* * Split source code at the first [:] or [=]. *) 
40+ let  source_take_until_punctuation  code  = 
41+   let  rec  is_punctuation  s  i  = 
42+     if  i > =  String. length s then  false 
43+     else 
44+       match  s.[i] with 
45+       |  ' '  -> is_punctuation s (i +  1 )
46+       |  ':'  |  '='  -> true 
47+       |  _  -> false 
48+   in 
49+   let  is_punctuation  i  = 
50+     List. exists
51+       (function 
52+         |  { Inline. desc  = Text  s ; _ }  -> is_punctuation s 0  |  _  -> false )
53+       i
54+   in 
55+   Take. until code ~classify: (function 
56+     |  Source. Elt  i  as  t  ->
57+         if  is_punctuation i then  Stop_and_accum  ([ t ], None ) else  Accum  [ t ]
58+     |  Tag  (_ , c ) -> Rec  c)
59+ 
3960let  rec  source_code  (s  : Source.t ) args  = 
4061  match  s with 
4162  |  []  -> noop
@@ -249,7 +270,7 @@ and item (l : Item.t list) args nesting_level =
249270            |  None  -> paragraph title
250271          in 
251272          blocks heading' (continue rest)
252-       |  Declaration  { attr  = _ ; anchor; content; doc }  ->
273+       |  Declaration  { attr  = _ ; anchor; content; doc }  -> ( 
253274          (* 
254275             Declarations render like this: 
255276
@@ -262,18 +283,8 @@ and item (l : Item.t list) args nesting_level =
262283             <doc> 
263284             v} 
264285          *)  
265-           let  doc = 
266-             match  doc with  []  ->  noop |  doc  ->  paragraph (text (acc_text doc))
267-           and  anchor = 
268-             if  args.generate_links then 
269-               let  anchor = 
270-                 match  anchor with  Some  x  ->  x.anchor |  None  ->  " " 
271-               in 
272-               paragraph (anchor' anchor)
273-             else  noop
274-           and  begin_code, content = 
286+           let  take_code_from_declaration  content  = 
275287            match  take_code content with 
276-             |  [] , _  -> assert  false  (*  Content doesn't begin with code ? *) 
277288            |  begin_code, Alternative  (Expansion  e) :: tl
278289              when  should_inline e.url ->
279290                (*  Take the code from inlined expansion. For example, to catch
@@ -282,10 +293,36 @@ and item (l : Item.t list) args nesting_level =
282293                (begin_code @  e_code, e_tl @  tl)
283294            |  begin_code , content  -> (begin_code, content)
284295          in 
285-           anchor
286-           +++  item_heading nesting_level (source_code begin_code args)
287-           +++  documented_src content args nesting_level
288-           +++  doc +++  continue rest
296+           let  render_declaration  ~anchor   ~doc   heading  content  = 
297+             let  doc = 
298+               match  doc with 
299+               |  []  -> noop
300+               |  doc  -> paragraph (text (acc_text doc))
301+             and  anchor = 
302+               if  args.generate_links then 
303+                 let  anchor = 
304+                   match  anchor with  Some  x  ->  x.Url.Anchor. anchor |  None  ->  " " 
305+                 in 
306+                 paragraph (anchor' anchor)
307+               else  noop
308+             in 
309+             anchor
310+             +++  item_heading nesting_level (source_code heading args)
311+             +++  content +++  doc +++  continue rest
312+           in 
313+           match  take_code_from_declaration content with 
314+           |  code , []  ->
315+               (*  Declaration is only code, render formatted code. *) 
316+               let  code, _, content =  source_take_until_punctuation code in 
317+               let  content = 
318+                 if  source_contains_text content then 
319+                   paragraph (source_code content args)
320+                 else  noop
321+               in 
322+               render_declaration ~anchor  ~doc  code content
323+           |  code , content  ->
324+               render_declaration ~anchor  ~doc  code
325+                 (documented_src content args nesting_level))
289326      |  Include  { content  = { summary; status; content } ; _ }  ->
290327          let  inline_subpage  =  function 
291328            |  `Inline  |  `Open  |  `Default  -> true 
0 commit comments