mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-07-01 20:37:08 -03:00
Compare commits
5 Commits
image_writ
...
v0.9.1
Author | SHA1 | Date | |
---|---|---|---|
92a97490f1 | |||
22decedf3a | |||
8b34a1659d | |||
3bf8172b89 | |||
4432da2893 |
23
CHANGELOG.md
23
CHANGELOG.md
@ -2,6 +2,29 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file.
|
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
|
||||||
|
|
||||||
|
- PNG writer based on Stumpy libs
|
||||||
|
|
||||||
|
### ⚙️ Miscellaneous Tasks
|
||||||
|
|
||||||
|
- Clean
|
||||||
|
- Detect version bump in release script
|
||||||
|
- Improve changelog handling
|
||||||
|
|
||||||
## [0.8.0] - 2024-09-21
|
## [0.8.0] - 2024-09-21
|
||||||
|
|
||||||
### 🚀 Features
|
### 🚀 Features
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name: tartrazine
|
name: tartrazine
|
||||||
version: 0.8.0
|
version: 0.9.1
|
||||||
|
|
||||||
authors:
|
authors:
|
||||||
- Roberto Alsina <roberto.alsina@gmail.com>
|
- Roberto Alsina <roberto.alsina@gmail.com>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
require "./spec_helper"
|
require "./spec_helper"
|
||||||
|
require "digest/sha1"
|
||||||
|
|
||||||
# These are the testcases from Pygments
|
# These are the testcases from Pygments
|
||||||
testcases = Dir.glob("#{__DIR__}/tests/**/*txt").sort
|
testcases = Dir.glob("#{__DIR__}/tests/**/*txt").sort
|
||||||
@ -103,6 +104,7 @@ describe Tartrazine do
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "to_ansi" do
|
describe "to_ansi" do
|
||||||
it "should do basic highlighting" do
|
it "should do basic highlighting" do
|
||||||
ansi = Tartrazine.to_ansi("puts 'Hello, World!'", "ruby")
|
ansi = Tartrazine.to_ansi("puts 'Hello, World!'", "ruby")
|
||||||
@ -114,11 +116,29 @@ describe Tartrazine do
|
|||||||
)
|
)
|
||||||
else
|
else
|
||||||
ansi.should eq(
|
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
|
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
|
end
|
||||||
|
|
||||||
# Helper that creates lexer and tokenizes
|
# Helper that creates lexer and tokenizes
|
||||||
|
@ -34,8 +34,6 @@ module Tartrazine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def colorize(text : String, token : String) : String
|
def colorize(text : String, token : String) : String
|
||||||
style = theme.styles.fetch(token, nil)
|
|
||||||
return text if style.nil?
|
|
||||||
if theme.styles.has_key?(token)
|
if theme.styles.has_key?(token)
|
||||||
s = theme.styles[token]
|
s = theme.styles[token]
|
||||||
else
|
else
|
||||||
|
@ -1,16 +1,20 @@
|
|||||||
require "../formatter"
|
require "../formatter"
|
||||||
|
require "compress/gzip"
|
||||||
|
require "digest/sha1"
|
||||||
require "stumpy_png"
|
require "stumpy_png"
|
||||||
require "stumpy_utils"
|
require "stumpy_utils"
|
||||||
require "compress/gzip"
|
|
||||||
|
|
||||||
module Tartrazine
|
module Tartrazine
|
||||||
def self.to_png(text : String, language : String,
|
def self.to_png(text : String, language : String,
|
||||||
theme : String = "default-dark",
|
theme : String = "default-dark",
|
||||||
line_numbers : Bool = false) : String
|
line_numbers : Bool = false) : String
|
||||||
|
buf = IO::Memory.new
|
||||||
|
|
||||||
Tartrazine::Png.new(
|
Tartrazine::Png.new(
|
||||||
theme: Tartrazine.theme(theme),
|
theme: Tartrazine.theme(theme),
|
||||||
line_numbers: line_numbers
|
line_numbers: line_numbers
|
||||||
).format(text, Tartrazine.lexer(name: language))
|
).format(text, Tartrazine.lexer(name: language), buf)
|
||||||
|
buf.to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
class FontFiles
|
class FontFiles
|
||||||
|
Reference in New Issue
Block a user