Skip to content

Commit

Permalink
allow some more chars like qm etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
hewo committed Apr 2, 2013
1 parent 99f10e6 commit 31de1e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/truncate_html/html_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module TruncateHtml
class HtmlString < String

UNPAIRED_TAGS = %w(br hr img).freeze
REGEX = /(?:<script.*>.*<\/script>)+|<\/?[^>]+>|[[[:alpha:]][0-9]\|`~!@#\$%^&*\(\)\-_\+=\[\]{}:;'",\.\/?]+|\s+|[[:punct:]]/.freeze
REGEX = /(?:<script.*>.*<\/script>)+|<\/?[^>]+>|[[[:alpha:]][0-9]\|`~!@#\$%^&*\(\)\-_\+=\[\]{}:;'²³§",\.\/?]+|\s+|[[:punct:]]/.freeze

def initialize(original_html)
super(original_html)
Expand Down
6 changes: 4 additions & 2 deletions spec/truncate_html/html_string_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#encoding: utf-8
require File.join(File.dirname(__FILE__), '..', 'spec_helper')

describe TruncateHtml::HtmlString do
Expand All @@ -8,8 +9,9 @@ def html_string(original_string)

describe '#html_tokens' do
it 'returns each token in the string as an array element removing any consecutive whitespace from the string' do
html = '<h1>Hi there</h1> <p>This is sweet!</p>'
html_string(html).html_tokens.should == ['<h1>', 'Hi', ' ', 'there', '</h1>', ' ', '<p>', 'This', ' ', 'is', ' ', 'sweet!', '</p>']
html = '<h1>Hi there</h1> <p>This is sweet!</p> <p> squaremeter m² </p>'
html_string(html).html_tokens.should == ['<h1>', 'Hi', ' ', 'there', '</h1>', ' ', '<p>', 'This', ' ', 'is', ' ', 'sweet!', '</p>',
' ', '<p>', ' ', 'squaremeter', ' ', 'm²', ' ', '</p>']
end
end

Expand Down

0 comments on commit 31de1e8

Please sign in to comment.