mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-10 05:22:23 +00:00
HTML formatter option: surrounding_pre
This commit is contained in:
parent
86a5894429
commit
6b44bcb5ad
@ -36,9 +36,7 @@ It has 332 themes (64 from Chroma, the rest are base16 themes via
|
||||
|
||||
## Installation
|
||||
|
||||
This will have a CLI tool that can be installed, but it's not
|
||||
there yet.
|
||||
|
||||
This has a CLI but it's not generally usable.
|
||||
|
||||
## Usage
|
||||
|
||||
|
@ -10,7 +10,7 @@ module Tartrazine
|
||||
# property with_classes : Bool = true
|
||||
property tab_width = 8
|
||||
|
||||
# property surrounding_pre : Bool = true
|
||||
property? surrounding_pre : Bool = true
|
||||
# property wrap_long_lines : Bool = false
|
||||
property? line_numbers : Bool = false
|
||||
property line_number_start : Int32 = 1
|
||||
@ -43,7 +43,10 @@ module Tartrazine
|
||||
def format_text(text : String, lexer : Lexer, theme : Theme) : String
|
||||
lines = group_tokens_in_lines(lexer.tokenize(text))
|
||||
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|
|
||||
line_label = line_numbers? ? "#{i + 1}".rjust(4).ljust(5) : ""
|
||||
line_class = highlighted?(i + 1) ? "class=\"#{get_css_class("LineHighlight", theme)}\"" : ""
|
||||
|
Loading…
Reference in New Issue
Block a user