Sha256: 435bb1e9a29fa3a281b977e9598f5e53ed0294ad98b5af25e7ef25e5507a6c87
Contents?: true
Size: 1.08 KB
Versions: 7
Compression:
Stored size: 1.08 KB
Contents
# frozen_string_literal: true require 'pygments.rb' module Pygments module Ext module BlockStyles BlockSelectorRx = /^\.highlight *\{([^}]+?)\}/ HighlightBackgroundColorRx = /^\.highlight +\.hll +{ *background(?:-color)?: *#([a-fA-F0-9]{6})/ HexColorRx = /^#[a-fA-F0-9]{6}$/ @cache = ::Hash.new do |cache, key| styles = {} if BlockSelectorRx =~ (css = ::Pygments.css '.highlight', style: key) ($1.strip.split ';').each do |style| pname, pval = (style.split ':', 2).map(&:strip) if pname == 'background' || pname == 'background-color' styles[:background_color] = pval.slice 1, pval.length if HexColorRx.match? pval elsif pname == 'color' styles[:font_color] = pval.slice 1, pval.length if HexColorRx.match? pval end end end styles[:highlight_background_color] = $1 if HighlightBackgroundColorRx =~ css @cache = cache.merge key => styles styles end def self.for style @cache[style] end end end end
Version data entries
7 entries across 7 versions & 1 rubygems