Skip to content

Commit 404e83c

Browse files
authored
box_debug: Highlight whitespaces (#2614)
This avoids whitespaces from being removed by the HTML parser and highlights strings that contain whitespaces to make them easy to see.
1 parent 4c5c7b5 commit 404e83c

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/Fmt.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ let utf8_length s =
143143
let str_as n s =
144144
let stack = Box_debug.get_stack () in
145145
with_pp (fun fs ->
146-
Box_debug.start_str fs ;
146+
Box_debug.start_str fs s ;
147147
Format_.pp_print_as fs n s ;
148148
Box_debug.end_str ~stack fs )
149149

lib/box_debug.ml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ let css =
4242
.fits_or_breaks {
4343
background-color: red;
4444
}
45+
.string_with_whitespaces {
46+
background-color: yellow;
47+
white-space: pre;
48+
}
49+
4550
.tooltiptext {
4651
visibility: hidden;
4752
width: min-content;
@@ -132,7 +137,15 @@ let force_newline ?stack fs =
132137
debugf fs "<div class=\"break force_newline\">force_newline%a</div>"
133138
stack_tooltip stack
134139

135-
let start_str fs = debugf fs "<span class='string'>"
140+
let start_str fs s =
141+
let extra_class =
142+
match String.lfindi s ~f:(fun _ c -> Char.is_whitespace c) with
143+
| Some _ ->
144+
(* String contains whitespaces, color it *)
145+
" string_with_whitespaces"
146+
| None -> ""
147+
in
148+
debugf fs "<span class='string%s'>" extra_class
136149

137150
let end_str ?stack fs = debugf fs "%a</span>" stack_tooltip stack
138151

0 commit comments

Comments
 (0)