From 9042138053775abddf99fe84e1e09fe2576476d0 Mon Sep 17 00:00:00 2001 From: Roberto Alsina Date: Mon, 19 Aug 2024 11:17:44 -0300 Subject: [PATCH] Make formatter a bit more convenient --- src/formatters/html.cr | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/formatters/html.cr b/src/formatters/html.cr index ac9aa25..ec39e46 100644 --- a/src/formatters/html.cr +++ b/src/formatters/html.cr @@ -34,11 +34,13 @@ module Tartrazine @weight_of_bold : Int32 = 600) end - def format(text : String, lexer : Lexer, dst : IO) : Nil + def format(text : String, lexer : Lexer, io : IO) : Nil + outp = io.nil? ? String::Builder.new("") : io pre, post = wrap_standalone - dst << pre if standalone? - format_text(text, lexer, dst) - dst << post if standalone? + outp << pre if standalone? + format_text(text, lexer, outp) + outp << post if standalone? + return outp.to_s if io.nil? end # Wrap text into a full HTML document, including the CSS for the theme @@ -58,8 +60,7 @@ module Tartrazine "#{line_label} " end - def format_text(text : String, lexer : Lexer, io : IO?) : String? - outp = io.nil? ? String::Builder.new("") : io + def format_text(text : String, lexer : Lexer, outp : IO) tokenizer = Tokenizer.new(lexer, text) i = 0 if surrounding_pre? @@ -76,7 +77,6 @@ module Tartrazine end end outp << "" - return outp.to_s if io.nil? end # ameba:disable Metrics/CyclomaticComplexity