Merge pull request #837 from ZogStriP/fix-pinned-topic-excerpt-is-not-properly-truncated
FIX: pinned topic excerpt is not properly truncated
This commit is contained in:
commit
ac36b591e9
|
@ -247,13 +247,9 @@ module PrettyText
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_excerpt(html, length, options)
|
def self.get_excerpt(html, length, options)
|
||||||
|
|
||||||
me = self.new(length,options)
|
me = self.new(length,options)
|
||||||
parser = Nokogiri::HTML::SAX::Parser.new(me)
|
parser = Nokogiri::HTML::SAX::Parser.new(me)
|
||||||
begin
|
begin
|
||||||
copy = "<div>"
|
|
||||||
copy << html unless html.nil?
|
|
||||||
copy << "</div>"
|
|
||||||
parser.parse(html) unless html.nil?
|
parser.parse(html) unless html.nil?
|
||||||
rescue DoneException
|
rescue DoneException
|
||||||
# we are done
|
# we are done
|
||||||
|
@ -302,8 +298,9 @@ module PrettyText
|
||||||
def characters(string, truncate = true, count_it = true, encode = true)
|
def characters(string, truncate = true, count_it = true, encode = true)
|
||||||
return if @in_quote
|
return if @in_quote
|
||||||
encode = encode ? lambda{|s| ERB::Util.html_escape(s)} : lambda {|s| s}
|
encode = encode ? lambda{|s| ERB::Util.html_escape(s)} : lambda {|s| s}
|
||||||
if @current_length + string.length > @length && count_it
|
if count_it && @current_length + string.length > @length
|
||||||
@excerpt << encode.call(string[0..(@length-@current_length)-1]) if truncate
|
length = [0, @length - @current_length - 1].max
|
||||||
|
@excerpt << encode.call(string[0..length]) if truncate
|
||||||
@excerpt << "…"
|
@excerpt << "…"
|
||||||
@excerpt << "</a>" if @in_a
|
@excerpt << "</a>" if @in_a
|
||||||
raise DoneException.new
|
raise DoneException.new
|
||||||
|
@ -318,4 +315,3 @@ module PrettyText
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -131,6 +131,7 @@ test
|
||||||
|
|
||||||
it "should truncate stuff properly" do
|
it "should truncate stuff properly" do
|
||||||
PrettyText.excerpt("hello world",5).should == "hello…"
|
PrettyText.excerpt("hello world",5).should == "hello…"
|
||||||
|
PrettyText.excerpt("<p>hello</p><p>world</p>",6).should == "hello w…"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should insert a space between to Ps" do
|
it "should insert a space between to Ps" do
|
||||||
|
@ -168,6 +169,7 @@ test
|
||||||
it "should handle nil" do
|
it "should handle nil" do
|
||||||
PrettyText.excerpt(nil,100).should == ''
|
PrettyText.excerpt(nil,100).should == ''
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue