Customizing Dreamweaver > Changing default HTML formatting

 

Changing default HTML formatting

The HTML source formatting profile determines how Dreamweaver formats the HTML source code for a document. The profile includes both the Code Format preferences (which you can easily set with Edit > Preferences; see Setting code formatting preferences for details) and additional formatting preferences for individual tags and groups of tags. The only way to change the formatting preferences that aren't shown in Code Format preferences is to edit the SourceFormat.txt file in a text editor. That file can be found in the Configuration folder within the Dreamweaver application folder.

Code Format preferences set with the Edit > Preferences command are saved in SourceFormat.txt when you quit Dreamweaver. You must therefore quit the application before editing the profile; otherwise, your changes may be overwritten when you quit Dreamweaver.

The HTML source formatting profile follows a specific format, which is described in the file. Note the following conventions:

Each section of the profile begins with a tag of the form <?keyword> (such as <?options>, <?elements>, or <?attributes>).
The parameters for each section are defined within HTML comments (<!-- -->) directly above the section.
The omit line in the <?options> section is reserved for future use (it currently does not affect HTML source formatting).
You can mark an individual tag as belonging to an indentation group (igroup) in the <?elements> section. By default, indentation group 1 contains table rows and columns, and indentation group 2 contains framesets and frames. These groupings correspond to the Indent Table Rows and Columns and Indent Framesets and Frames options in HTML Format preferences. You can turn off indentation for the entire group by removing its number from the active attribute in the <?options> section. You can also add other tags to either indentation group so you can control them with the options in HTML Format preferences.

The four numbers given in the break attribute for each tag indicate respectively how many line breaks to use before the opening tag, how many to use immediately after the opening tag (and before the contents of the tag), how many to use immediately before the closing tag, and how many to place after the closing tag.

For example, the default settings for the p tag in SourceFormat.txt are <p break="1,0,0,1" indent>, which produces the following formatting:

<p> A paragraph of text that is indented from the left margin 
	(after the first line) and that has a line break before the 
	opening p tag and after the closing p tag, but no line break 
	after the opening p and none before the closing p.</p>
<p>Next paragraph.</p>

If you change the settings to <p break="1,1,1,2">, the Code view and Code inspector will display text paragraphs in the following way:

<p>
A paragraph of text that is not indented from the left margin 
and that has one line break before and after the opening p tag, 
one line break before the closing p tag, and two line breaks 
after the closing p tag.
</p>

<p>
Next paragraph.
</p>

(Note that the number of line breaks after the closing tag and before the following opening tag is the greater of the two numbers specified—if you specify two line breaks before a tag and three after, the result is three line breaks between the closing tag and the next opening tag.)

Some tag and attribute settings include the term namecase, which specifies that the tag or attribute is to be capitalized in exactly the way that you specify as the value of the namecase attribute. For example, onClick is specified in the SourceFormat.txt file as <onClick namecase="onClick">; therefore, onClick is always displayed using that particular combination of uppercase and lowercase, regardless of user capitalization preferences.

Another term used to specify capitalization is samecase, which specifies that the value of an attribute is to be capitalized the same way that the attribute's name is capitalized. For example, <align samecase> indicates that if Dreamweaver generates an align attribute, the value of the attribute will appear with the same capitalization as the attribute name. It also applies to attribute names that don't have values, so don't remove samecase from any of the attribute formatting specifications where it appears.

The term noformat associated with a tag indicates that the line breaks, indentation, and capitalization of an existing instance of the tag are never changed to use the format specified in SourceFormat.txt. For a tag marked noformat, the format specified in SourceFormat.txt is used only when creating a new instance of the tag using Dreamweaver. For example, <pre break="1,0,0,1" noformat> means that if you create a new pre tag using Dreamweaver's tools, it will use the "1,0,0,1" line break specification when creating it; but if you already have a pre tag that you created by hand whose line breaks don't match this specification, and you edit that tag in the Design view, the line breaks don't change.

Any attribute not specified in the SourceFormat.txt file uses the default formatting settings that you specify in the HTML Format preferences category.