Problem: Dreamweaver 4 falls short in its ability to produce well–formed, standards–compliant markup. Solution: You can easily harness Dreamweaver’s two greatest strengths, its flexibility and its user community, to make it one of the best tools on the market for producing good XHTML. This article will tell you how.
With a few tweaks, hacks and extensions, you’ll be able to produce
sites that validate, and to clean up legacy pages. Set aside an hour or two, follow
these directions, and fall in love with Dreamweaver all over again.
What this article does not do#section1
This article does not show how to tweak Dreamweaver to produce standards–compliant scripting. A future article may do that. Also note that upcoming Dreamweaver 5 is expected to be more standards–compliant than the current version, so some of these tweaks may not be needed with future versions of Dreamweaver.
Finally, remember to validate all your pages. Just because you’ve converted Dreamweaver into a standards–friendly tool doesn’t mean your pages will always be perfect. (We all make mistakes.)
XHTML must be written in lowercase, so set Dreamweaver to write markup accordingly:
- Open Dreamweaver.
- From the dropdown
- In the Preferences dialog box, select code format on the left of the dialog
- Set the “case for tags” and “case for attributes” to lowercase.
Doctype by default#section3
XHTML documents must begin with a namespace and an XHTML Document Type Declaration (including a URI that points to an online Document Type Definition). Unfortunately, the default template in Dreamweaver does none of that:
<html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" c charset=iso-8859-1"> </head><br />
But good little girls and boys use a template that looks like this:
<html xml:lang="en" lang="en"> <head> <title>Untitled Document</title> </head>
It’s easy to make the default template include this or any other Document Type and namespace declaration:
- Find the document called Default.html:
- Make a backup of the file.
- Open Default.html and change the head so it includes the Document Type Declaration and namespace declaration above (or the Doctype and namespace declaration of your choice).
- You may also want to edit the
<body>tag, deleting the body color and text/link color styles that your cascading style sheet should handle.
- While you are there, you can also set up links to style sheets, insert basic
meta tags, and declare your character set.
Closing non–closing elements#section4
XHTML requires you to close non–closing (“empty”) elements including form tags, image tags, horizontal rule tags and break tags. (For more information, see XHTML Guidelines in the NYPL Online Style Guide and W3C’s HTML Compatibility Guidelines for XHTML 1.0.) Closing these pesky elements can be one of the most time–consuming tasks in transitioning to XHTML. But you can modify Dreamweaver to do the work for you:
Closing the LineBreak.htm#section5
Let’s start with the simple line break; we’ll change
First, find the file called LineBreak.htm in ConfigurationObjectsCharacters.
- Create a backup of LineBreak.htm.
- Open LineBreak.htm.
- Edit line 17 so that
- Save and close the file.
- Open a new HTML document in Dreamweaver and insert a line break.
- View Source to be sure it worked.
The process for the Image.js file is similar, but a bit more complicated:
- Go to ConfigurationObjectsCommon.
- Backup Image.js.
- Open the file Image.js and modify line 21 from:
"return ‘’;"to this:
- Again, test your work by opening a new HTML document and inserting an image
Repeat these steps for HR.htm and other non–closing element files in these
Checking your work#section7
After you have modified all of the non–closing elements, create a new document that uses all such elements and perform a little QA testing on it. Preview
the pages in a few browsers on a few platforms, and run the page through the HTML
validator. If you have made an error, you
don’t want to compound it by creating pages with broken markup.
Characters and Styles#section8
Dreamweaver makes it easy to insert special characters such as em–dash or proper quotation marks. Under the Insert drop–down menu, select Special Characters and you will see a list of the most common ones, ready for easy insertion.
But two problems make these options less than desirable. First, the
process of selecting em–dash, for example, takes too many steps. It is
easier to simply type “—”. Second, the character sequence that Dreamweaver
inserts is not valid. So if you use these characters as they are, your site will
Two quick fixes solve both problems:
Editing the Special Character Files#section9
You can edit the the character objects themselves so that they produce Unicode character entities. Let’s work with the em–dash:
- Return to the file ConfigurationObjectsCharacters.
- Open emdash.html.
- Change return “—” to return “—”.
- Save the document, and test it as you did above.
Continue the process for the other files in the Characters directory. To modify
the dropdown Insert>Special Characters>Other menu, edit commandsInsertEnt.htm. Again, backup this file before you edit it.
Caveat: Dreamweaver will not display some Unicode character
sequences in Preview mode. Do not be alarmed when it renders “ (left double quotation mark) as a dot. All will be well when you see it in the browser.
Creating Keyboard Shortcuts#section10
Now you have nicely written Unicode, but it’s still a pain to insert the little buggers. You can create keyboard shortcuts for the character sequences by editing the menus.xml document in your program files (Configuration>Menus>menus.xml.).
You might for example create cmd+shft+h for an em–dash. I created shortcuts for right and left double quotation marks.
Before you do this, close Dreamweaver. Edit menus.xml in another editor like
HomeSite, BBEdit, PageSpinner, or Notepad. Make sure that you do not use a command sequence that is already in use.
The Bold and the Strong#section11
While you are working in the menus.xml file, you might also want to exercise a little more semantic consideration. The
<i> tags will validate, but use of these formatting tags is not really in the spirit
of good markup. They don’t mean anything, they are just for formatting. If you care enough about document structure to want to write XHTML, you should be using the more meaningful tags
There are a few different ways of making Dreamweaver do this, but I found
it easiest to modify menus.xml this way:
I just gave the menu items _Bold the argument for strong, and _Italic the argument
for em. This way, when you select bold from the text dropdown menu—or if you use the bold or italic keyboard commands—these semantically more meaningful tags will appear instead.
Caveat: This does not change the HTML generated
by the properties window.
Update: After this article was published, Francois Jordaan implemented the XHTML modifications discussed here and packaged them in a downloadable file for your convenience. See the section labelled “Help & Praise,” below.
Cleaning up bad pages with extensions#section12
A developer named Jason Dalgarno has been kind enough to made available a Dreamweaver extension that allows you to convert your pages into XHTML. Note this is a zipped file download. When uncompressed, Dreamweaver Extension Manager will open it automatically. The tool will:
- Quote unquoted attribute values.
- Unminimize Boolean attributes.
- Copy name attributes to id attributes.
- Add the pitifully neglected type attribute to
- Set an empty alt attribute to
- Change null links from
- Fill empty table cells.
- Run the command site–wide (be careful with this one).
Remember to make a backup copy of the page (or site) before you work with this new tool.
A bit of fiddling may be required before you get the hang of it. By default, the
extension will run every time you save a document. I found this a bit annoying
and changed my preferences so it runs only when I command it to.
Super HTML–XHTML DTD Dreamweaver Extension#section13
This handy little extension allows you to change the DTD of a page with a single
command. Note that if you are working with Dreamweaver 3 or earlier, you will
also need to download the Macromedia Extension Manager.
Installing the Extension#section14
- Visit the recently moved and reformatted Macromedia Dreamweaver Exchange and search for the Super HTML-XHTML DTD Extension appropriate to your machine.
- Open Dreamweaver.
- From the “Commands” drop–down, select “Manage Extensions.”
- Browse to the Super HTML-XHTML DTD Extension file that you downloaded and
double–click it. The extension should now be installed.
Help & Praise#section15
The modifications discussed in this article have been implemented by Francois Jordaan and are available for downloading from his personal site.