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

should_not have_selector("br")
As expected, that fails:
'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" "">
<html><body><p>paragraph 1 <strong>bold text</strong><br>
paragraph 2</p></body></html>
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 =
textile.hard_breaks = false
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