Monday, September 21, 2009

No Hard Breaks

‹prev | My Chain | next›

Aw, for crying out loud.

I again find myself clicking out the beta site only to find a little problem. Today's problem are weird line breaks:



Grrr... Every time I use RedCloth, I get the line breaks (or something) wrong.

Digging through the code, I have to give the maintainers credit—although the :no_breaks option is apparently deprecated, there is still an accessor for this option. But first, a (RSpec) test:
  it "should not have line breaks in paragraphs" do
textile = <<_TEXTILE
paragraph 1 *bold text*
paragraph 2
_TEXTILE

wiki(textile).
should_not have_selector("br")
end
As expected, that fails:
1)
'wiki should not have line breaks in paragraphs' FAILED
expected following output to omit a <br/>:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>paragraph 1 <strong>bold text</strong><br>
paragraph 2</p></body></html>
./spec/eee_helpers_spec.rb:72:
To get that to pass, I use the no_breaks accessor in the wiki helper:
    def wiki(original, convert_textile=true)
text = (original || '').dup
#...
if convert_textile
textile = RedCloth.new(text)
textile.hard_breaks = false
textile.to_html
else
text
end
end
That makes the example pass and fixes the display issues:



In addition to resolving my :hard_breaks RedCloth woes, I also spend a little time to get a link to a Google query working:



We are not trying to lock users into our site—it's just a family cookbook, so we like to include those links.

Up tomorrow, I have some Amazon associate work to do.

No comments:

Post a Comment