diff --git a/lib/hamlit/concerns/indentable.rb b/lib/hamlit/concerns/indentable.rb index 277b4576..ba114d65 100644 --- a/lib/hamlit/concerns/indentable.rb +++ b/lib/hamlit/concerns/indentable.rb @@ -72,6 +72,17 @@ module Hamlit "#{length} #{label}#{'s' if length > 1}" end + + # Replace hard tabs into 2 spaces + def replace_hard_tabs(template) + lines = [] + template.each_line do |line| + lines << line.gsub(/^\t+/) do |match| + ' ' * (match.length * 2) + end + end + lines.join + end end end end diff --git a/lib/hamlit/parser.rb b/lib/hamlit/parser.rb index 97050041..18cf337f 100644 --- a/lib/hamlit/parser.rb +++ b/lib/hamlit/parser.rb @@ -40,6 +40,7 @@ module Hamlit # Reset the parser state. def reset(template) validate_indentation!(template) + template = replace_hard_tabs(template) template = preprocess_multilines(template) reset_lines(template.split("\n")) diff --git a/spec/hamlit/engine/indent_spec.rb b/spec/hamlit/engine/indent_spec.rb new file mode 100644 index 00000000..49522457 --- /dev/null +++ b/spec/hamlit/engine/indent_spec.rb @@ -0,0 +1,14 @@ +describe Hamlit::Engine do + describe 'tab indent' do + it 'accepts tab indentation' do + assert_render(<<-HAML, <<-HTML) + %p + \t%a + HAML +

+ +

+ HTML + end + end +end