Added test binary, code to read base16 themes

This commit is contained in:
Roberto Alsina 2024-08-06 18:03:05 -03:00
parent a2394a7313
commit 94bc221545
4 changed files with 44 additions and 5 deletions

View File

@ -6,11 +6,13 @@ authors:
targets:
tartrazine:
main: src/tartrazine.cr
main: src/main.cr
dependencies:
base58:
github: crystal-china/base58.cr
sixteen:
github: ralsina/sixteen
crystal: ">= 1.13.0"

View File

@ -66,7 +66,3 @@ module Tartrazine
end
end
end
lexer = Tartrazine.lexer("crystal")
theme = Tartrazine.theme("catppuccin-macchiato")
puts Tartrazine::Html.new.format(File.read(ARGV[0]), lexer, theme)

5
src/main.cr Normal file
View File

@ -0,0 +1,5 @@
require "./**"
lexer = Tartrazine.lexer("crystal")
theme = Tartrazine.theme("catppuccin-macchiato")
puts Tartrazine::Html.new.format(File.read(ARGV[0]), lexer, theme)

View File

@ -1,3 +1,4 @@
require "sixteen"
require "xml"
module Tartrazine
@ -78,6 +79,41 @@ module Tartrazine
parents
end
# Load from a base16 theme name using Sixteen
def self.from_base16(name : String) : Theme
t = Sixteen.theme(name)
# The color assignments are adapted from
# https://github.com/mohd-akram/base16-pygments/
t.styles["Background"] = Style.new(color: t["base05"], background: t["base00"])
t.styles["Text"] = Style.new(color: t["base05"])
t.styles["Error"] = Style.new(color: t["base08"])
t.styles["Comment"] = Style.new(color: t["base03"])
t.styles["CommentPreProc"] = Style.new(color: t["base0f"])
t.styles["CommentPreProcFile"] = Style.new(color: t["base0b"])
t.styles["Keyword"] = Style.new(color: t["base0e"])
t.styles["KeywordType"] = Style.new(color: t["base08"])
t.styles["NameAttribute"] = Style.new(color: t["base0d"])
t.styles["NameBuiltin"] = Style.new(color: t["base08"])
t.styles["NameBuiltinPseudo"] = Style.new(color: t["base08"])
t.styles["NameClass"] = Style.new(color: t["base0d"])
t.styles["NameConstant"] = Style.new(color: t["base09"])
t.styles["NameDecorator"] = Style.new(color: t["base09"])
t.styles["NameFunction"] = Style.new(color: t["base0d"])
t.styles["NameNamespace"] = Style.new(color: t["base0d"])
t.styles["NameTag"] = Style.new(color: t["base0e"])
t.styles["NameVariable"] = Style.new(color: t["base0d"])
t.styles["NameVariableInstance"] = Style.new(color: t["base08"])
t.styles["Number"] = Style.new(color: t["base09"])
t.styles["Operator"] = Style.new(color: t["base0c"])
t.styles["OperatorWord"] = Style.new(color: t["base0e"])
t.styles["Literal"] = Style.new(color: t["base0b"])
t.styles["String"] = Style.new(color: t["base0b"])
t.styles["StringInterpol"] = Style.new(color: t["base0f"])
t.styles["StringRegex"] = Style.new(color: t["base0c"])
t.styles["StringSymbol"] = Style.new(color: t["base09"])
end
# Load from a Chroma XML file
def self.from_xml(xml : String) : Theme
document = XML.parse(xml)