diff --git a/lib/truncate_html/html_string.rb b/lib/truncate_html/html_string.rb index 76d82e9..8b04e89 100644 --- a/lib/truncate_html/html_string.rb +++ b/lib/truncate_html/html_string.rb @@ -13,9 +13,7 @@ def html_tokens scan(REGEX).map do |token| HtmlString.new( token.gsub( - /\n/,' ' #replace newline characters with a whitespace - ).gsub( - /\s+/, ' ' #clean out extra consecutive whitespace + / +/, ' ' # Clean out extra consecutive whitespace ) ) end @@ -34,7 +32,7 @@ def html_comment? end def matching_close_tag - gsub(/<(\w+)\s?.*>/, '\1>').strip + gsub(/<(\w+)\s?.*>/m, '\1>').strip end end diff --git a/lib/truncate_html/html_truncator.rb b/lib/truncate_html/html_truncator.rb index 52b707f..d01be86 100644 --- a/lib/truncate_html/html_truncator.rb +++ b/lib/truncate_html/html_truncator.rb @@ -38,7 +38,7 @@ def word_boundary def build_output out = @truncated_html.join if word_boundary - term_regexp = Regexp.new("^.*#{word_boundary.source}") + term_regexp = Regexp.new("^.*#{word_boundary.source}", Regexp::MULTILINE) match = out.match(term_regexp) if match && match[0] != out out = match[0] + @closing_tags.join diff --git a/spec/truncate_html/html_truncator_spec.rb b/spec/truncate_html/html_truncator_spec.rb index 0da14d6..aa3d039 100644 --- a/spec/truncate_html/html_truncator_spec.rb +++ b/spec/truncate_html/html_truncator_spec.rb @@ -101,15 +101,19 @@ def truncate(html, opts = {}) truncate(html, :length => html.length).should == html end - #unusual, but just covering my ass + # Unusual, but just covering my ass it 'recognizes the multiline html properly' do html = <<-END_HTML -