HTML formatter option: surrounding_pre

This commit is contained in:
Roberto Alsina 2024-08-09 15:59:49 -03:00
parent 86a5894429
commit 6b44bcb5ad
2 changed files with 6 additions and 5 deletions

View File

@ -36,9 +36,7 @@ It has 332 themes (64 from Chroma, the rest are base16 themes via
## Installation ## Installation
This will have a CLI tool that can be installed, but it's not This has a CLI but it's not generally usable.
there yet.
## Usage ## Usage

View File

@ -10,7 +10,7 @@ module Tartrazine
# property with_classes : Bool = true # property with_classes : Bool = true
property tab_width = 8 property tab_width = 8
# property surrounding_pre : Bool = true property? surrounding_pre : Bool = true
# property wrap_long_lines : Bool = false # property wrap_long_lines : Bool = false
property? line_numbers : Bool = false property? line_numbers : Bool = false
property line_number_start : Int32 = 1 property line_number_start : Int32 = 1
@ -43,7 +43,10 @@ module Tartrazine
def format_text(text : String, lexer : Lexer, theme : Theme) : String def format_text(text : String, lexer : Lexer, theme : Theme) : String
lines = group_tokens_in_lines(lexer.tokenize(text)) lines = group_tokens_in_lines(lexer.tokenize(text))
output = String.build do |outp| output = String.build do |outp|
outp << "<pre class=\"#{get_css_class("Background", theme)}\"><code class=\"#{get_css_class("Background", theme)}\">" if surrounding_pre?
outp << "<pre class=\"#{get_css_class("Background", theme)}\">"
end
"<code class=\"#{get_css_class("Background", theme)}\">"
lines.each_with_index(offset: line_number_start - 1) do |line, i| lines.each_with_index(offset: line_number_start - 1) do |line, i|
line_label = line_numbers? ? "#{i + 1}".rjust(4).ljust(5) : "" line_label = line_numbers? ? "#{i + 1}".rjust(4).ljust(5) : ""
line_class = highlighted?(i + 1) ? "class=\"#{get_css_class("LineHighlight", theme)}\"" : "" line_class = highlighted?(i + 1) ? "class=\"#{get_css_class("LineHighlight", theme)}\"" : ""