HTML formatter option: class_prefix

This commit is contained in:
Roberto Alsina 2024-08-09 12:21:02 -03:00
parent fd5af6ba3b
commit 4ced996f90
3 changed files with 5 additions and 4 deletions

View File

@ -26,7 +26,7 @@ module Tartrazine
}]
end
colorized = text.colorize
s.color.try { |c| colorized = colorized.fore(c.colorize) }
s.color.try { |col| colorized = colorized.fore(col.colorize) }
# Intentionally not setting background color
colorized.mode(:bold) if s.bold
colorized.mode(:italic) if s.italic

View File

@ -5,8 +5,8 @@ module Tartrazine
# Not all of these options are implemented
property? standalone : Bool = false
property class_prefix : String = ""
# property class_prefix : String = ""
# property with_classes : Bool = true
# property tab_width = 8
# property surrounding_pre : Bool = true
@ -76,13 +76,13 @@ module Tartrazine
# Given a token type, return the CSS class to use.
def get_css_class(token, theme)
return Abbreviations[token] if theme.styles.has_key?(token)
return class_prefix + Abbreviations[token] if theme.styles.has_key?(token)
# Themes don't contain information for each specific
# token type. However, they may contain information
# for a parent style. Worst case, we go to the root
# (Background) style.
Abbreviations[theme.style_parents(token).reverse.find { |parent|
class_prefix + Abbreviations[theme.style_parents(token).reverse.find { |parent|
theme.styles.has_key?(parent)
}]
end

View File

@ -4,4 +4,5 @@ lexer = Tartrazine.lexer("crystal")
theme = Tartrazine.theme(ARGV[1])
formatter = Tartrazine::Html.new
formatter.standalone = true
formatter.class_prefix = "tartrazine-"
puts formatter.format(File.read(ARGV[0]), lexer, theme)