Doing it Right the First Time

| | Comments (0)

So our design guy tells us that it would be much better if, instead of throwing in double <br> tags for paragraphs, we changed it to <p> tags. Oh, and make sure it works in XHTML in case we want to use that someday, which means we need starting and ending tags.

So, this is sortof a pain, doing it right. I am trying to think of all the potential problems, and there's a bunch. So I put in a paragraph tag for the double-linebreak tag, but where do I put the ending tag? What algorithms do I use to find the right place? Pain.

And then I remembered that all comments get passed through a function I wrote several years ago called balanceTags(). You can basically throw any HTML you want at it, and it will return valid HTML. It will balance unbalanced tags (including paragraph tags), it will make sure blockquote tags include block tags inside them, and so on. If the "xhtml" flag was on, it will even make lone tags like linebreaks and images (and some paragraphs) into proper XHTML tags. So switching to XHTML is as simple as flipping the switch.

Therefore, all I had to do is find out where to put the open paragraph tags, and balanceTags() takes care of the rest. Hooray! So in this case it means putting a paragraph tag at the beginning of each comment (which is something I've wanted to do for awhile anyway), and then another one at each double-linebreak, and we're golden.

I was worrying about doing it right for nothing, since I'd already done it right years ago!

Leave a comment

<pudge/*> (pronounced "PudgeGlob") is thousands of posts over many years by Pudge.

"It is the common fate of the indolent to see their rights become a prey to the active. The condition upon which God hath given liberty to man is eternal vigilance; which condition if he break, servitude is at once the consequence of his crime and the punishment of his guilt."

About this Entry

This page contains a single entry by pudge published on June 5, 2008 4:12 PM.

Stupid Slash Tricks: Auto-Encapsulation of Tasks was the previous entry in this site.

More Fun with Dean Logan is the next entry in this site.

Find recent content on the main index or look in the archives to find all content.