require 'spec_helper' module CiteProc module Ruby describe 'Formats::Html' do it 'can be created with an options hash' do expect(Formats::Html.new(:css_only => true)).to be_css_only end end describe 'Formats::Html#apply' do let(:format) { Format.load 'html' } let(:node) { CSL::Style::Text.new } describe 'text-case formats' do it 'supports lowercase' do node[:'text-case'] = 'lowercase' expect(format.apply('Foo BAR', node)).to eq('foo bar') end end describe 'entity escaping' do it 'escapes entities in the original text' do node[:'text-case'] = 'lowercase' expect(format.apply('Foo & BAR', node)).to eq('foo & bar') end it 'does not not apply casing to escaped entities' do node[:'text-case'] = 'uppercase' expect(format.apply('Foo & BAR', node)).to eq('FOO & BAR') end it 'escapes entities in affixes' do node[:prefix] = '<' node[:suffix] = '>' expect(format.apply('foo', node)).to eq('<foo>') end it 'escapes entities in quotes' do locale = CSL::Locale.new locale.store 'open-quote', '<' locale.store 'close-quote', '>' node[:quotes] = true expect(format.apply('foo', node, locale)).to eq('<foo>') end end describe 'affixes' do it 'are added after text formats have been applied' do node[:prefix] = 'foo' node[:suffix] = 'ooo' node[:'font-style'] = 'italic' expect(format.apply('ooo', node)).to eq('foooooooo') end it 'are added before text formats have been applied for layout nodes' do layout = CSL::Style::Layout.new layout[:prefix] = 'foo' layout[:suffix] = 'ooo' layout[:'font-style'] = 'italic' expect(format.apply('ooo', layout)).to eq('foooooooo') end end describe 'font-style' do it 'supports italic in both modes' do node[:'font-style'] = 'italic' expect(format.apply('foo bar', node)).to eq('foo bar') format.config[:italic] = 'em' expect(format.apply('foo bar', node)).to eq('foo bar') format.config[:css_only] = true expect(format.apply('foo bar', node)).to eq('foo bar') end it 'supports normal and oblique via css' do node[:'font-style'] = 'oblique' expect(format.apply('foo bar', node)).to eq('foo bar') node[:'font-style'] = 'normal' expect(format.apply('foo bar', node)).to eq('foo bar') end end it 'supports font-variant via css' do node[:'font-variant'] = 'small-caps' expect(format.apply('foo bar', node)).to eq('foo bar') end describe 'font-weight' do it 'supports bold in both modes' do node[:'font-weight'] = 'bold' expect(format.apply('foo bar', node)).to eq('foo bar') format.config[:bold] = 'strong' expect(format.apply('foo bar', node)).to eq('foo bar') format.config[:css_only] = true expect(format.apply('foo bar', node)).to eq('foo bar') end it 'supports normal and light via css' do node[:'font-weight'] = 'light' expect(format.apply('foo bar', node)).to eq('foo bar') node[:'font-weight'] = 'normal' expect(format.apply('foo bar', node)).to eq('foo bar') end end it 'supports text-decoration via css' do node[:'text-decoration'] = 'underline' expect(format.apply('foo bar', node)).to eq('foo bar') end it 'supports vertical-align via css' do node[:'vertical-align'] = 'sup' expect(format.apply('foo bar', node)).to eq('foo bar') end describe 'display' do it 'is supported in an outer container' do node[:'display'] = 'block' node[:'text-decoration'] = 'underline' expect(format.apply('foo bar', node)).to eq('