class Rouge::CSSTheme
def css_selector(token)
def css_selector(token) inflate_token(token).map do |tok| raise "unknown token: #{tok.inspect}" if tok.shortname.nil? single_css_selector(tok) end.join(', ') end
def inflate_token(tok, &b)
the subtokens, except those which are more specifically
as the given token. Essentially this recursively all of
yield all of the tokens that should be styled the same
def inflate_token(tok, &b) return enum_for(:inflate_token, tok) unless block_given? yield tok tok.sub_tokens.each do |(_, st)| next if styles[st] inflate_token(st, &b) end end
def initialize(opts={})
def initialize(opts={}) @scope = opts[:scope] || '.highlight' end
def render(&b)
def render(&b) return enum_for(:render).to_a.join("\n") unless b # shared styles for tableized line numbers yield "#{@scope} table td { padding: 5px; }" yield "#{@scope} table pre { margin: 0; }" styles.each do |tok, style| style.render(css_selector(tok), &b) end end
def single_css_selector(token)
def single_css_selector(token) return @scope if token == Text "#{@scope} .#{token.shortname}" end
def style_for(tok)
def style_for(tok) self.class.get_style(tok) end