Skip to content

Commit

Permalink
Merge pull request #281 from mojavelinux/issue-280
Browse files Browse the repository at this point in the history
resolves #280 use proper precedence when resolving style for token
  • Loading branch information
jneen committed Sep 10, 2015
2 parents 76c96e8 + e100e86 commit fc0fafd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/rouge/theme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def style(*tokens)
end

def get_own_style(token)
token.token_chain.each do |anc|
token.token_chain.reverse_each do |anc|
return styles[anc] if styles[anc]
end

Expand Down
17 changes: 11 additions & 6 deletions spec/theme_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def squish(str)
end

class MyTheme < Rouge::CSSTheme
style Literal::String, :bold => true
style Literal::String::Backtick, :italic => true
style Literal::String, :fg => '#003366', :bold => true
style Literal::String::Backtick, :fg => '#555555', :italic => true
end

let(:theme) { MyTheme.new }
Expand Down Expand Up @@ -35,12 +35,17 @@ class MyTheme < Rouge::CSSTheme
end

it 'fetches a style for a token' do
bold = theme.style_for(Token['Literal.String'])
assert { bold == { :bold => true } }
style = theme.style_for(Rouge::Token['Literal.String'])
assert { style == { :fg => '#003366', :bold => true } }
end

it 'fetches a the closest style for a token' do
bold = theme.style_for(Token['Literal.String.Double'])
assert { bold == { :bold => true } }
style = theme.style_for(Rouge::Token['Literal.String.Backtick'])
assert { style == { :fg => '#555555', :italic => true } }
end

it 'fetches style from ancestor token when no style is defined' do
style = theme.style_for(Rouge::Token['Literal.String.Char'])
assert { style == { :fg => '#003366', :bold => true } }
end
end

0 comments on commit fc0fafd

Please sign in to comment.