From 785fac6e42f3b75bc391b9e0e968dc5173f0c49c Mon Sep 17 00:00:00 2001 From: Marc-Antoine Ouimet Date: Thu, 26 May 2022 22:43:35 -0400 Subject: [PATCH] Construct a formatter specifically for printing signature declarations to HTML Replacing the usage of `Format.stdbuf` for pretty-printing to HTML files with a newly constructed buffer ensures that the `Format.stdbuf` is not altered unexpectedly. --- src/core/recsgn.ml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/recsgn.ml b/src/core/recsgn.ml index 356bd3714..01bd7f1cc 100644 --- a/src/core/recsgn.ml +++ b/src/core/recsgn.ml @@ -155,13 +155,15 @@ let sgnDeclToHtml = function | Ext.Sgn.Comment { content; _ } -> Html.appendAsComment content | d -> - let margin = Format.pp_get_margin Format.str_formatter () in Html.printing := true; - (* Format.set_margin 150; *) - Format.pp_set_margin Format.str_formatter 200; - Pretty.Ext.DefaultPrinter.fmt_ppr_sgn_decl Format.str_formatter d; - Html.append (Format.flush_str_formatter ()); - Format.pp_set_margin (Format.str_formatter) margin; + + let html_buffer = Buffer.create 16 in + let html_formatter = Format.formatter_of_buffer html_buffer in + Format.pp_set_margin html_formatter 200; + Format.fprintf html_formatter "%a" Pretty.Ext.DefaultPrinter.fmt_ppr_sgn_decl d; + Format.pp_print_flush html_formatter (); + Html.append (Buffer.contents html_buffer); + Html.printing := false let rec apply_global_pragmas =