mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-06-08 12:40:25 -03:00
Compare commits
4 Commits
84ee7e6934
...
bc34f93cc5
Author | SHA1 | Date | |
---|---|---|---|
bc34f93cc5 | |||
f64c91801e | |||
8e29500fcf | |||
f2e638ce3b |
@ -39,7 +39,7 @@ module Tartrazine
|
|||||||
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|
|
||||||
if surrounding_pre?
|
if surrounding_pre?
|
||||||
pre_style= wrap_long_lines? ? "style=\"white-space: pre-wrap; word-break: break-word;\"" : ""
|
pre_style = wrap_long_lines? ? "style=\"white-space: pre-wrap; word-break: break-word;\"" : ""
|
||||||
outp << "<pre class=\"#{get_css_class("Background", theme)}\" #{pre_style}>"
|
outp << "<pre class=\"#{get_css_class("Background", theme)}\" #{pre_style}>"
|
||||||
end
|
end
|
||||||
"<code class=\"#{get_css_class("Background", theme)}\">"
|
"<code class=\"#{get_css_class("Background", theme)}\">"
|
||||||
@ -47,7 +47,7 @@ module Tartrazine
|
|||||||
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)}\"" : ""
|
||||||
line_id = linkable_line_numbers? ? "id=\"#{line_number_id_prefix}#{i + 1}\"" : ""
|
line_id = linkable_line_numbers? ? "id=\"#{line_number_id_prefix}#{i + 1}\"" : ""
|
||||||
outp << "<span #{line_id} #{line_class}>#{line_label}</span>"
|
outp << "<span #{line_id} #{line_class} style=\"user-select: none;\">#{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>"
|
||||||
outp << fragment
|
outp << fragment
|
||||||
|
17
src/main.cr
17
src/main.cr
@ -23,12 +23,13 @@ HELP
|
|||||||
|
|
||||||
lexer = Tartrazine.lexer("crystal")
|
lexer = Tartrazine.lexer("crystal")
|
||||||
theme = Tartrazine.theme(ARGV[1])
|
theme = Tartrazine.theme(ARGV[1])
|
||||||
formatter = Tartrazine::Json.new
|
# formatter = Tartrazine::Json.new
|
||||||
# formatter.standalone = true
|
formatter = Tartrazine::Html.new
|
||||||
# formatter.class_prefix = "hl-"
|
formatter.standalone = true
|
||||||
# formatter.line_number_id_prefix = "ln-"
|
formatter.class_prefix = "hl-"
|
||||||
# formatter.line_numbers = true
|
formatter.line_number_id_prefix = "ln-"
|
||||||
# formatter.highlight_lines = [3..7, 20..30]
|
formatter.line_numbers = true
|
||||||
# formatter.linkable_line_numbers = false
|
formatter.highlight_lines = [3..7, 20..30]
|
||||||
# formatter.wrap_long_lines = false
|
formatter.linkable_line_numbers = false
|
||||||
|
formatter.wrap_long_lines = false
|
||||||
puts formatter.format(File.read(ARGV[0]), lexer, theme)
|
puts formatter.format(File.read(ARGV[0]), lexer, theme)
|
||||||
|
@ -17,7 +17,7 @@ module Tartrazine
|
|||||||
raise ex unless ex.message.try &.includes? "Theme not found"
|
raise ex unless ex.message.try &.includes? "Theme not found"
|
||||||
end
|
end
|
||||||
begin
|
begin
|
||||||
return Theme.from_xml(ThemeFiles.get("/#{name}.xml").gets_to_end)
|
Theme.from_xml(ThemeFiles.get("/#{name}.xml").gets_to_end)
|
||||||
rescue
|
rescue
|
||||||
raise Exception.new("Theme #{name} not found")
|
raise Exception.new("Theme #{name} not found")
|
||||||
end
|
end
|
||||||
@ -111,7 +111,7 @@ module Tartrazine
|
|||||||
# The color assignments are adapted from
|
# The color assignments are adapted from
|
||||||
# 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"], bold: true)
|
||||||
theme.styles["LineHighlight"] = 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"])
|
||||||
@ -175,27 +175,22 @@ module Tartrazine
|
|||||||
if !theme.styles.has_key?("LineHighlight")
|
if !theme.styles.has_key?("LineHighlight")
|
||||||
theme.styles["LineHighlight"] = Style.new
|
theme.styles["LineHighlight"] = Style.new
|
||||||
theme.styles["LineHighlight"].background = make_highlight_color(theme.styles["Background"].background)
|
theme.styles["LineHighlight"].background = make_highlight_color(theme.styles["Background"].background)
|
||||||
|
theme.styles["LineHighlight"].bold = true
|
||||||
end
|
end
|
||||||
theme
|
theme
|
||||||
end
|
end
|
||||||
|
|
||||||
# If the color is dark, make it brighter and viceversa
|
# If the color is dark, make it brighter and viceversa
|
||||||
def self.make_highlight_color(base_color)
|
def self.make_highlight_color(base_color)
|
||||||
# FIXME: do a proper luminance adjustment in the color class
|
if base_color.nil?
|
||||||
return nil if base_color.nil?
|
# WHo knows
|
||||||
color = Color.new(base_color.hex)
|
return Color.new(127, 127, 127)
|
||||||
if base_color.light?
|
end
|
||||||
color.r = [(base_color.r - 40), 255].min.to_u8
|
if base_color.dark?
|
||||||
color.g = [(base_color.g - 40), 255].min.to_u8
|
base_color.lighter(0.2)
|
||||||
color.b = [(base_color.b - 40), 255].min.to_u8
|
else
|
||||||
else
|
base_color.darker(0.2)
|
||||||
color.r = [(base_color.r + 40), 255].min.to_u8
|
|
||||||
color.g = [(base_color.g + 40), 255].min.to_u8
|
|
||||||
color.b = [(base_color.b + 40), 255].min.to_u8
|
|
||||||
end
|
end
|
||||||
# Bug in color, setting rgb doesn't update hex
|
|
||||||
color.hex = "#{color.r.to_s(16)}#{color.g.to_s(16)}#{color.b.to_s(16)}"
|
|
||||||
color
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user