mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-10 05:22:23 +00:00
Make formatter a bit more convenient
This commit is contained in:
parent
fa647e898a
commit
9042138053
@ -34,11 +34,13 @@ module Tartrazine
|
|||||||
@weight_of_bold : Int32 = 600)
|
@weight_of_bold : Int32 = 600)
|
||||||
end
|
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
|
pre, post = wrap_standalone
|
||||||
dst << pre if standalone?
|
outp << pre if standalone?
|
||||||
format_text(text, lexer, dst)
|
format_text(text, lexer, outp)
|
||||||
dst << post if standalone?
|
outp << post if standalone?
|
||||||
|
return outp.to_s if io.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Wrap text into a full HTML document, including the CSS for the theme
|
# Wrap text into a full HTML document, including the CSS for the theme
|
||||||
@ -58,8 +60,7 @@ module Tartrazine
|
|||||||
"<span #{line_id} #{line_class} style=\"user-select: none;\">#{line_label} </span>"
|
"<span #{line_id} #{line_class} style=\"user-select: none;\">#{line_label} </span>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_text(text : String, lexer : Lexer, io : IO?) : String?
|
def format_text(text : String, lexer : Lexer, outp : IO)
|
||||||
outp = io.nil? ? String::Builder.new("") : io
|
|
||||||
tokenizer = Tokenizer.new(lexer, text)
|
tokenizer = Tokenizer.new(lexer, text)
|
||||||
i = 0
|
i = 0
|
||||||
if surrounding_pre?
|
if surrounding_pre?
|
||||||
@ -76,7 +77,6 @@ module Tartrazine
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
outp << "</code></pre>"
|
outp << "</code></pre>"
|
||||||
return outp.to_s if io.nil?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# ameba:disable Metrics/CyclomaticComplexity
|
# ameba:disable Metrics/CyclomaticComplexity
|
||||||
|
Loading…
Reference in New Issue
Block a user