File tree Expand file tree Collapse file tree 2 files changed +33
-5
lines changed Expand file tree Collapse file tree 2 files changed +33
-5
lines changed Original file line number Diff line number Diff line change @@ -583,11 +583,17 @@ and bad_markup_recovery start_offset input = parse
583
583
(Parse_error. bad_markup (" {" ^ rest) ~suggestion );
584
584
emit input (`Code_span text) ~start_offset }
585
585
586
- (* The second field of the metadata *)
586
+ (* The second field of the metadata.
587
+ This rule keeps whitespaces and newlines in the 'metadata' field except the
588
+ ones just before the '['. *)
587
589
and code_block_metadata_tail input = parse
588
- | ((newline | horizontal_space)+ as prefix) (([^ '[' ])+ as meta) '['
590
+ | (space_char+ as prefix)
591
+ ((space_char* (_ # space_char # ['[' ])+ )+ as meta)
592
+ ((space_char* '[' ) as suffix)
589
593
{
590
- let meta = with_location_adjustments ~adjust_start_by: prefix ~adjust_end_by: " [" (fun _ -> Loc. at) input meta in
594
+ let meta =
595
+ with_location_adjustments ~adjust_start_by: prefix ~adjust_end_by: suffix (fun _ -> Loc. at) input meta
596
+ in
591
597
`Ok (Some meta)
592
598
}
593
599
| (newline | horizontal_space)* '['
Original file line number Diff line number Diff line change @@ -2597,7 +2597,7 @@ let%expect_test _ =
2597
2597
(((f.ml (1 0) (1 46))
2598
2598
(code_block
2599
2599
(((f.ml (1 2) (1 7)) ocaml)
2600
- (((f.ml (1 8) (1 29 )) "env=f1 version>=4.06 ")))
2600
+ (((f.ml (1 8) (1 28 )) "env=f1 version>=4.06")))
2601
2601
((f.ml (1 30) (1 44)) "code goes here")))))
2602
2602
(warnings ())) |}]
2603
2603
@@ -2654,10 +2654,32 @@ let%expect_test _ =
2654
2654
((output
2655
2655
(((f.ml (1 0) (2 9))
2656
2656
(code_block
2657
- (((f.ml (1 2) (1 7)) ocaml) (((f.ml (1 8) (2 0 )) " kind=toplevel\n" )))
2657
+ (((f.ml (1 2) (1 7)) ocaml) (((f.ml (1 8) (1 21 )) kind=toplevel)))
2658
2658
((f.ml (2 1) (2 7)) "code ")))))
2659
2659
(warnings ())) |}]
2660
2660
2661
+ let spaces_after_meta =
2662
+ test "{@ocaml kind=toplevel [ code ]}";
2663
+ [%expect
2664
+ {|
2665
+ ((output
2666
+ (((f.ml (1 0) (1 31))
2667
+ (code_block
2668
+ (((f.ml (1 2) (1 7)) ocaml) (((f.ml (1 8) (1 21)) kind=toplevel)))
2669
+ ((f.ml (1 23) (1 29)) "code ")))))
2670
+ (warnings ())) |}]
2671
+
2672
+ let spaces_and_newline_after_meta =
2673
+ test "{@ocaml kind=toplevel \n [ code ]}";
2674
+ [%expect
2675
+ {|
2676
+ ((output
2677
+ (((f.ml (1 0) (2 11))
2678
+ (code_block
2679
+ (((f.ml (1 2) (1 7)) ocaml) (((f.ml (1 8) (1 21)) kind=toplevel)))
2680
+ ((f.ml (2 3) (2 9)) "code ")))))
2681
+ (warnings ())) |}]
2682
+
2661
2683
let newlines_inside_meta =
2662
2684
test "{@ocaml kind=toplevel\nenv=e1[ code ]}";
2663
2685
[%expect
You can’t perform that action at this time.
0 commit comments