Slightly smarter, much faster convert line breaks

If you are using my convert line breaks hack to stop MT from adding <p> and </p> around block-level elements like tables and lists, you will want to update your hack to the newly posted version: Ben glanced at it and pointed out that it would be far faster with a slightly more sensible regex. There’s definately a reason why he writes the program, and I just poke around the edges.

11 Comments

Comment by Dorothea Salo #
2002-10-31 06:10:16

My day for stupid questions. The ”newly posted version” is where exactly?

 
Comment by Phil Ringnalda #
2002-10-31 08:23:04

That wasn’t very clear, was it? What I meant was ”the newly edited and changed version which is now in the old entry.” Quarter till two in the morning isn’t my most eloquent time, I’m afraid.

 
Comment by Joshua Kaufman #
2002-10-31 13:04:19

Hi Phil,

The updated hack isn’t working for me. I’m getting the following error when I try to run MT:

”Got an error: syntax error at lib/MT/Util.pm line 185, near ”$p ” syntax error at lib/MT/Util.pm line 189, near ”}” BEGIN failed–compilation aborted at lib/MT/App/CMS.pm line 12.”

Any ideas? Thanks!

 
Comment by Phil Ringnalda #
2002-10-31 13:36:35

Did I mention that it was quarter till two in the morning? I didn’t notice that there was a stray return in the code I posted, which was screwing it up completely. This time, it should be right: I copied my working code out of my Util.pm, pasted it into the entry, then copied it out of the entry and pasted it in my Util.pm, and it worked.

Sorry about that.

 
Comment by Anonymous #
2002-10-31 15:53:25

This blogger stuff is cool. Just thought I’d check to see how easy it is to ad to the conversation. Now… if I only had somthing to say on the subject.

 
Comment by Joshua Kaufman #
2003-02-05 19:10:18

Phil, how can I add this hack to comments too?

 
Comment by Phil Ringnalda #
2003-02-05 21:16:53

As long as you have convert line breaks on for comments (in Blog Config -> Preferences -> Comment Configuration), it should already be added: comments call the same routine in Util.pm that posts do.

 
Comment by Joshua Kaufman #
2003-02-06 06:02:28

I have convert line breaks on for comments, but it doesn’t seem to be working the same way as it does in my posts. See this entry. The OL and LI tags are followed by line breaks. But when I create ordered lists in my posts, they’re not followed by line breaks. Any ideas?

 
Comment by Joshua Kaufman #
2003-02-06 07:59:01

Hmm, but your recent comment on my site that used an OL didn’t contain line breaks. Ah ha! It has to do with spacing. If you don’t leave a space after paragraphs then it think the whole thing is one big paragraph and will add line breaks where appropriate, but if you add a space then it works fine. i.e. It works when posts/comments are left like this:

This is a paragraph.

  1. List item
  2. List item

This is another pargraph.

But it won’t work if you do this:

This is a paragraph.
<ol>
<li>List item</li>
<li>List item</li>
</ol>
This is another pargraph.

I could have probably figured that out if I looked hard enough! Thanks for your help though.

 
Comment by Phil Ringnalda #
2003-02-06 07:59:23

Looks to me from the source and from my comment there that Nate just didn’t do a double new line before the start of the list:

Text
<ol>

rather than:

Text

<ol>

If it was ”Much smarter” rather than just ”Slightly smarter”, then the part that adds break tags would recognize that it was adding a break after a blocklevel element, and would instead go back and close the open paragraph before the tag. It’s not nearly that smart.

If I manage to remember, I’ll take a look at the plugin that does this same sort of thing (I think the name is something hard to wrap your tongue around like Validable), and see if it’s that smart.

 
Comment by Phil Ringnalda #
2003-02-06 08:03:56

Damn, beat me to it: that’ll teach me not to use preview to see previous comments.

 
Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <del datetime="" cite=""> <dd> <dl> <dt> <em> <i> <ins datetime="" cite=""> <kbd> <li> <ol> <p> <pre> <q cite=""> <samp> <strong> <sub> <sup> <ul> in your comment.