Sha256: 25355bfba275b5efe342e7b7445d369373369ef0e6a1077933378e0c2f56fad9

Contents?: true

Size: 1.05 KB

Versions: 43

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Pygments
  module Ext
    module BlockStyles
      BlockSelectorRx = /^\.highlight *\{([^}]+?)\}/
      HighlightBackgroundColorRx = /^\.highlight +\.hll +{ *background(?:-color)?: *#(\h{6})/
      ColorPropertiesRx = /(?:^|;) *(background(?:-color)?|color): *#?(\h{6}) *(?=$|;)/

      @cache = ::Hash.new do |cache, key|
        styles = {}
        if BlockSelectorRx =~ (css = ::Pygments.css '.highlight', style: key)
          $1.scan ColorPropertiesRx do |pname, pval|
            case pname
            when 'background', 'background-color'
              styles[:background_color] = pval
            when 'color'
              styles[:font_color] = pval
            end
          end
        end
        styles[:highlight_background_color] = $1 if HighlightBackgroundColorRx =~ css
        @cache = cache.merge key => styles
        styles
      end

      def self.available? style
        (@available ||= ::Pygments.styles.to_set).include? style
      end

      def self.for style
        @cache[style]
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
asciidoctor-pdf-2.0.0.alpha.3 lib/asciidoctor/pdf/ext/pygments.rb
asciidoctor-pdf-2.0.0.alpha.2 lib/asciidoctor/pdf/ext/pygments.rb
asciidoctor-pdf-2.0.0.alpha.1 lib/asciidoctor/pdf/ext/pygments.rb