mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-07-01 12:27:08 -03:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
92a97490f1 | |||
22decedf3a | |||
8b34a1659d | |||
3bf8172b89 |
11
CHANGELOG.md
11
CHANGELOG.md
@ -2,6 +2,17 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [0.9.1] - 2024-09-22
|
||||
|
||||
### 🐛 Bug Fixes
|
||||
|
||||
- Terminal formatter was skipping things that it could highlight
|
||||
- Bug in high-level API for png formatter
|
||||
|
||||
### 🧪 Testing
|
||||
|
||||
- Added minimal tests for svg and png formatters
|
||||
|
||||
## [0.9.0] - 2024-09-21
|
||||
|
||||
### 🚀 Features
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: tartrazine
|
||||
version: 0.9.0
|
||||
version: 0.9.1
|
||||
|
||||
authors:
|
||||
- Roberto Alsina <roberto.alsina@gmail.com>
|
||||
|
@ -1,4 +1,5 @@
|
||||
require "./spec_helper"
|
||||
require "digest/sha1"
|
||||
|
||||
# These are the testcases from Pygments
|
||||
testcases = Dir.glob("#{__DIR__}/tests/**/*txt").sort
|
||||
@ -103,6 +104,7 @@ describe Tartrazine do
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "to_ansi" do
|
||||
it "should do basic highlighting" do
|
||||
ansi = Tartrazine.to_ansi("puts 'Hello, World!'", "ruby")
|
||||
@ -114,11 +116,29 @@ describe Tartrazine do
|
||||
)
|
||||
else
|
||||
ansi.should eq(
|
||||
"\e[38;2;171;70;66mputs\e[0m\e[38;2;216;216;216m \e[0m'Hello, World!'"
|
||||
"\e[38;2;171;70;66mputs\e[0m\e[38;2;216;216;216m \e[0m\e[38;2;161;181;108m'Hello, World!'\e[0m"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "to_svg" do
|
||||
it "should do basic highlighting" do
|
||||
svg = Tartrazine.to_svg("puts 'Hello, World!'", "ruby", standalone: false)
|
||||
svg.should eq(
|
||||
"<text x=\"0\" y=\"19\" xml:space=\"preserve\"><tspan fill=\"#ab4642\">puts</tspan><tspan fill=\"#d8d8d8\"> </tspan><tspan fill=\"#a1b56c\">'Hello, World!'</tspan></text>"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "to_png" do
|
||||
it "should do basic highlighting" do
|
||||
png = Digest::SHA1.hexdigest(Tartrazine.to_png("puts 'Hello, World!'", "ruby"))
|
||||
png.should eq(
|
||||
"62d419dcd263fffffc265a0f04c156dc2530c362"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Helper that creates lexer and tokenizes
|
||||
|
@ -34,8 +34,6 @@ module Tartrazine
|
||||
end
|
||||
|
||||
def colorize(text : String, token : String) : String
|
||||
style = theme.styles.fetch(token, nil)
|
||||
return text if style.nil?
|
||||
if theme.styles.has_key?(token)
|
||||
s = theme.styles[token]
|
||||
else
|
||||
|
@ -1,16 +1,20 @@
|
||||
require "../formatter"
|
||||
require "compress/gzip"
|
||||
require "digest/sha1"
|
||||
require "stumpy_png"
|
||||
require "stumpy_utils"
|
||||
require "compress/gzip"
|
||||
|
||||
module Tartrazine
|
||||
def self.to_png(text : String, language : String,
|
||||
theme : String = "default-dark",
|
||||
line_numbers : Bool = false) : String
|
||||
buf = IO::Memory.new
|
||||
|
||||
Tartrazine::Png.new(
|
||||
theme: Tartrazine.theme(theme),
|
||||
line_numbers: line_numbers
|
||||
).format(text, Tartrazine.lexer(name: language))
|
||||
).format(text, Tartrazine.lexer(name: language), buf)
|
||||
buf.to_s
|
||||
end
|
||||
|
||||
class FontFiles
|
||||
|
Reference in New Issue
Block a user