Proposal: use XHTML friendlier HTML

Proposal: use XHTML friendlier HTML

by Jaime Villate -
Number of replies: 2
Hi,
On making a Portuguese translation for Moodle,
I've made some small changes that may prove to be useful in the future: wrote HTML in a form that is more XHTML compliant so XML parsers can be used on HTML pages generated by Moodle (and if some day HTML is finally abandoned in favor of XHTML, the required changes will be minimal).

Here are a few tips to write friendlier HTML code:

1- Use only lower case for any tags and attributes:
<h2 aling="center">, rather than <H2 ALIGN=CENTER>

2- Always close all tags which have some content. Namely, all content (anything different from a tag) should be enclosed within matching and

For instance, instead of:
First<P>Second<UL><LI>Item</UL>
please write:
<p>First</p><p>Second</p><ul><li>Item</li></ul>

It is more verbose, but it will ease the job of parsers.

3- Enclose the value of every attribute within quotes:
<img src="a.png" border="0">
rather than
<img src=a.png border=0>
You can also use single quotes; for instance, I have found in lang/en/moodle.php that if you
write:

$string['name']="image: <img src=\"a.png\"> ";

which is correct PHP, then lib/moodlelib.php fails to "eval" this, in line 947. You can use:

$string['name']="image: <img src='a.png'> ";

4- Avoid using tags and attributes which are not in the Standard DTD. We should decide on a common DTD to use and avoid Netscape and IE extensions.

Regards,
Jaime
Average of ratings: -
In reply to Jaime Villate

Re: Proposal: use XHTML friendlier HTML

by Martin Dougiamas -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers
XHTML is a bit of sore point. smile Yes, I'm fully aware of it's advantages - the reason Moodle isn't XHTML-compliant yet is partly because it was started several years ago, partly because I'm too old-school and partly because there have just been many other things to do lately. The current HTML works OK at present so it's not been urgent. However there are plans for a complete interface overhaul in Moodle 2.0 using XML with XSLT to produce XHTML, which should satisfy everyone. smile

And you'll find that you CAN use double quotes if you edit language files using the web-based editor rather than directly by hand (the script should do all the escaping properly).

Cheers,
Martin
In reply to Jaime Villate

Re: Proposal: use XHTML friendlier HTML

by Greg Barnett -
In general I like your suggestions, and agree with Martin that these issues aren't critical.

What I'd like to see (and am certainly willing to help out with) is a set of milestones created for getting Moodle to version 2.0 and beyond. I think these suggestions should get put into that roadmap for Moodle.

item 1: I agree completely, but for a different reason. I DO NOT LIKE ALL CAPS.

item 2: I agree with this as well.

item 3: I agree, but think sticking with double quotes in the HTML is the way to go. Double quotes seem to be the standard, and are likely to cause fewer problems with iffy parsers.

I disagree with how you want to set the value. My recommendation (not tested, would probably require changes in the moodle page that edits strings) is to use single quotes to enclose the string. This allows the unrestricted use of double quotes within the string, and should be slightly faster as PHP won't try to evaluate the string for variables.

$string['name'] = 'image: <img src="a.png">';

item 4: I'd love to have Moodle match a DTD, primarily for testing purposes. It would be wonderful to run the w3 validator against Moodle, and know that if a page doesn't validate, that it means there is a bug somewhere in Moodle that can be then found and fixed.