10000 Speed up HTML encoder for 1.2 by korny · Pull Request #153 · rubychan/coderay · GitHub
[go: up one dir, main page]

Skip to content

Speed up HTML encoder for 1.2 #153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
don't break old API
  • Loading branch information
korny committed Oct 3, 2013
commit 0023deede4144b4d7e8aa90a6557a3df00b88edc
25 changes: 13 additions & 12 deletions lib/coderay/encoders/html/css.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ module Encoders

class HTML
class CSS # :nodoc:
def initialize style = :default
@style = style
def initialize style_name = :default
@style_name = style_name
end
def stylesheet
@stylesheet ||= CodeRay::Styles[@style]

def style
@style ||= CodeRay::Styles[@style_name]
end

def css
[
stylesheet::CSS_MAIN_STYLES,
stylesheet::TOKEN_COLORS.gsub(/^(?!$)/, '.CodeRay ')
@css ||= [
style::CSS_MAIN_STYLES,
style::TOKEN_COLORS.gsub(/^(?!$)/, '.CodeRay ')
].join("\n")
end

alias stylesheet css

def get_style_for_css_classes css_classes
cl = styles[css_classes.first]
return '' unless cl
Expand All @@ -29,7 +30,7 @@ def get_style_for_css_classes css_classes
return style
end

private
private

CSS_CLASS_PATTERN = /
( # $1 = selectors
Expand All @@ -46,7 +47,7 @@ def get_style_for_css_classes css_classes
/mx
def styles
@styles ||= Hash.new.tap do |styles|
stylesheet::TOKEN_COLORS.scan CSS_CLASS_PATTERN do |selectors, style, error|
style::TOKEN_COLORS.scan CSS_CLASS_PATTERN do |selectors, style, error|
raise "CSS parse error: '#{error.inspect}' not recognized" if error
for selector in selectors.split(',')
classes = selector.scan(/[-\w]+/)
Expand Down
0