« show your revision history | Main | conquering the 'convert line breaks' validation problems »

a tool for validation

If you're interested in making your blog look good in as many browsers as possible and in having it be accessible to people with disabilities, validation is a useful tool. The validator checks your code against a set of web standards (the default templates in MT are set to validate against XHTML 1.0 Transitional, which is a good choice for forwards compatability). It reports on any errors that it finds. This can often be a helpful tool in solving template problems; you may have an unclosed <div> in your template that's wrecking the entire layout. You can try to look for it yourself until your eyes cross or you can let a computer check for you. The validator will also let you know if you're using deprecated elements or attributes that will become obsolete in the future.

The default MT templates should already validate and if you've created your own, you can eventually get the template structure itself to validate. There are two additional problems you may face that I think are particularly common in blogs. The first is that many bloggers like to add scripts and code from external sources to their blog templates, from blogrolls to hit counters to webrings and much more besides. A lot of this code is so bad that it's a surprise that it even works. In most cases you can edit the code right in your template and fix the problems but in some cases an external script generates the code that you might not have access to or that you can't understand how to edit because the code is constructed step by step in Perl or PHP1.

The second problem is invalid code in your entries. There are three main reasons this happens. First, you may have been using deprecated elements or attributes when you typed HTML into your entries. You can go back and edit the entries to replace the invalid code. You might also want to look into some of the text filter plugins that allow you to use simplified formatting that is turned into valid code whenever the entry is displayed. Second, the convert breaks setting often plays havoc with your code if you have multiple paragraphs in your entry wrapped in your tags (e.g., a blockquote or a styled div, or italics) or if you write HTML lists putting each list item on a separate line instead of running it all together. An example is:

<p><i>This is some text</p>

<p>This is the second paragraph.</i></p>

When you typed it in, you had the <i> tags at the beginning of the first paragraph and the end of the second paragraph but when the convert line breaks function adds the <p> tags it does so at the beginning and end of each line, so that the first line has an opening <i> without a closing one and the second vice versa. Browsers handle this OK but the validator considers the tags to be improperly nested.

Solving this problem would require re-editing your entries to modify your code to work around the convert breaks problem.

The third issue that you're likely to see when validating is HTML entities in URLs, particularly ampersands. The validator doesn't like & by itself but wants it written out as &amp;. Ampersands appear in a great many URLs including links to search engine results, many news stories, forum threads, and almost anything that is dynamically generated and passes multiple values through the URL (in fact, you will have to watch out for this when constructing links to your trackbacks pop-ups and to the MT search engine for your templates). Considering that links are the heart of the web and that ampersands are so common in URLs, it seems unfortunate that they invalidate your page.

However, this is where the SafeHref plugin comes in. It gives you a new global attribute you can add to your tags:

<$MTEntryBody safe_urls="1"$>

When the template is built, MT searches the content of the tag for invalid characters in URLs and replaces them with HTML entities. This can clear up a lot of errors you get while validating. Incidentally, the MT-Revision plugin generates ampersands in its URLs so I'm using SafeHref on it to fix it.

Right now I've got the Al-Muhajabah's Islamic Blogs main index page, the index page of this Tips blog, The Niqabi Paralegal, and my vanity blog to validate as well as the A Quranic Journal page. I've gotten The Clipboard and veiled4allah to the point where it's only the convert breaks problem that prevents validation. Muslims For Kucinich has that problem as well as a problem with the show/hide javascript and also some invalid entities from copying and pasting campaign email messages into blog entries.

1 I was able to hack the Topicon plugin to make it generate valid code, but haven't yet figured out how to modify lazyman's smilies to include alt tags, though I'm sure this is do-able. The show/hide javascript also seems to be causing the validator to choke

TrackBack

Listed below are links to weblogs that reference a tool for validation:

» Safe Href? from Blogula Rasa
Need to verify if I have Save Href installed per Al-Muhajabah's Movable Type Tips' recommendation. I quote a LOT of URLs that have ampersands, and although I tried to set up something to fix it, it doesn't seem to be... [Read More]

Comments

Hey =) I modified the lazyman smilies to have an alt tag, i only have the one modified for my edit_entry.tmp but you can download it here and compare it to yours. Just make sure not to change the form information on yours!

But, basically, you're looking for the first line that starts self.opener.window.document - go the end of that line and end alt='smily' I don't remember if it has the self close tag either...Obviously make sure your sanitize isn't stripping out alts. =)

You can find an updated version of the show/hide javascript here which fixed validation as well as some other issues (including being able to scroll with the mousewheel after you click the link to expand the content)

hope that helps....

Wow, thanks! I was pretty sure that I could figure out the smilies eventually but the PHP was confusing me. I'll also take a look at the new and improved show/hide javascript. I've had the older code around for quite awhile, lol.

About This Blog

  • Disclaimer: This is a personal site and is not connected with Six Apart, Ltd, the makers of Movable Type
  • Contact me:
  • Readme: What this blog is and is not
  • Reference: Templates for Al-Muhajabah's Islamic Blogs

August 2008

Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            

Tips by Type

Tips by Area

Other ways to read this blog

Feed Subscribe to this blog's feed
(default is RSS 2.0, I also have RSS 1.0 and Atom)

Text-only version
Powered by
Movable Type 3.2