From 79cbab1a791107d32a49bf0bb0e3c0cd67a5dc01 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Wed, 27 May 2015 01:01:44 -0600 Subject: resolves #158 preprocess theme data to properly support hex colors before passing theme data to YAML.load: - remove leading # from hex colors - quote hex colors --- lib/asciidoctor-pdf/theme_loader.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/asciidoctor-pdf/theme_loader.rb b/lib/asciidoctor-pdf/theme_loader.rb index 42f63d10..3c4b0e32 100644 --- a/lib/asciidoctor-pdf/theme_loader.rb +++ b/lib/asciidoctor-pdf/theme_loader.rb @@ -8,6 +8,7 @@ class ThemeLoader DataDir = ::File.expand_path ::File.join(::File.dirname(__FILE__), '..', '..', 'data') ThemesDir = ::File.join DataDir, 'themes' FontsDir = ::File.join DataDir, 'fonts' + HexColorValueRx = /_color: (?"|'|)#?(?[A-Za-z0-9]{3,6})\k$/ def self.resolve_theme_file theme_name = nil, theme_path = nil theme_name ||= 'default' @@ -31,7 +32,8 @@ class ThemeLoader end def self.load_file filename - self.new.load (::SafeYAML.load_file filename) + data = ::IO.read(filename).each_line.map {|l| l.sub(HexColorValueRx, '_color: \'\k\'') }.join + self.new.load(::SafeYAML.load(data)) end def load hash @@ -112,7 +114,6 @@ class ThemeLoader def to_hex value str = value.to_s return str if str == 'transparent' - str = str[1..-1] if str.start_with? '#' hex = case str.size when 6 str -- cgit v1.2.3