mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-10 05:22:23 +00:00
Fix line highlight for non-base16 themes
This commit is contained in:
parent
d1762f477a
commit
96dcb7e15e
@ -1,6 +1,5 @@
|
|||||||
module Tartrazine
|
module Tartrazine
|
||||||
Abbreviations = {
|
Abbreviations = {
|
||||||
"Highlight" => "hl",
|
|
||||||
"NameTag" => "nt",
|
"NameTag" => "nt",
|
||||||
"NameBuiltin" => "nb",
|
"NameBuiltin" => "nb",
|
||||||
"NameVariable" => "nv",
|
"NameVariable" => "nv",
|
||||||
|
@ -46,8 +46,7 @@ module Tartrazine
|
|||||||
outp << "<pre class=\"#{get_css_class("Background", theme)}\"><code class=\"#{get_css_class("Background", theme)}\">"
|
outp << "<pre class=\"#{get_css_class("Background", theme)}\"><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("Highlight", theme)}\"" : ""
|
|
||||||
outp << "<span id=\"#{line_number_id_prefix}#{i + 1}\" #{line_class}>#{line_label}</span>"
|
outp << "<span id=\"#{line_number_id_prefix}#{i + 1}\" #{line_class}>#{line_label}</span>"
|
||||||
line.each do |token|
|
line.each do |token|
|
||||||
fragment = "<span class=\"#{get_css_class(token[:type], theme)}\">#{token[:value]}</span>"
|
fragment = "<span class=\"#{get_css_class(token[:type], theme)}\">#{token[:value]}</span>"
|
||||||
|
@ -104,7 +104,7 @@ module Tartrazine
|
|||||||
# https://github.com/mohd-akram/base16-pygments/
|
# https://github.com/mohd-akram/base16-pygments/
|
||||||
|
|
||||||
theme.styles["Background"] = Style.new(color: t["base05"], background: t["base00"])
|
theme.styles["Background"] = Style.new(color: t["base05"], background: t["base00"])
|
||||||
theme.styles["Highlight"] = Style.new(color: t["base0D"], background: t["base01"])
|
theme.styles["LineHighlight"] = Style.new(color: t["base0D"], background: t["base01"])
|
||||||
theme.styles["Text"] = Style.new(color: t["base05"])
|
theme.styles["Text"] = Style.new(color: t["base05"])
|
||||||
theme.styles["Error"] = Style.new(color: t["base08"])
|
theme.styles["Error"] = Style.new(color: t["base08"])
|
||||||
theme.styles["Comment"] = Style.new(color: t["base03"])
|
theme.styles["Comment"] = Style.new(color: t["base03"])
|
||||||
@ -163,7 +163,29 @@ module Tartrazine
|
|||||||
|
|
||||||
theme.styles[node["type"]] = s
|
theme.styles[node["type"]] = s
|
||||||
end
|
end
|
||||||
|
# We really want a LineHighlight class
|
||||||
|
if !theme.styles.has_key?("LineHighlight")
|
||||||
|
theme.styles["LineHighlight"] = Style.new
|
||||||
|
theme.styles["LineHighlight"].background = make_highlight_color(theme.styles["Background"].background)
|
||||||
|
end
|
||||||
theme
|
theme
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# If the color is dark, make it brighter and viceversa
|
||||||
|
def self.make_highlight_color(base_color)
|
||||||
|
return nil if base_color.nil?
|
||||||
|
color = Color.new(base_color.hex)
|
||||||
|
if base_color.light?
|
||||||
|
color.r = [(base_color.r / 1.2), 255].min.to_u8
|
||||||
|
color.g = [(base_color.g / 1.2), 255].min.to_u8
|
||||||
|
color.b = [(base_color.b / 1.2), 255].min.to_u8
|
||||||
|
else
|
||||||
|
color.r = [(base_color.r * 1.2), 255].min.to_u8
|
||||||
|
color.g = [(base_color.g * 1.2), 255].min.to_u8
|
||||||
|
color.b = [(base_color.b * 1.2), 255].min.to_u8
|
||||||
|
end
|
||||||
|
color.hex = "#{color.r.to_s(16)}#{color.g.to_s(16)}#{color.b.to_s(16)}"
|
||||||
|
color
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user