diff options
| author | Dan Allen <dan.j.allen@gmail.com> | 2015-05-27 01:01:44 -0600 |
|---|---|---|
| committer | Dan Allen <dan.j.allen@gmail.com> | 2015-05-27 01:01:44 -0600 |
| commit | 79cbab1a791107d32a49bf0bb0e3c0cd67a5dc01 (patch) | |
| tree | b3bbd4d22de4fb7a9e588008ac40a6cc12e807c2 /lib | |
| parent | 9bfa13d869efb1524bf77675857199a6ec0e1190 (diff) | |
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
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/asciidoctor-pdf/theme_loader.rb | 5 |
1 files changed, 3 insertions, 2 deletions
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: (?<quote>"|'|)#?(?<value>[A-Za-z0-9]{3,6})\k<quote>$/ 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<value>\'') }.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 |
