Preserving Code Formats with CodeSweepers

The CodeSweeper feature automates the task of getting your code properly formatted. It can be useful in a number of situations:

Selecting a CodeSweeper

HomeSite includes a number of CodeSweepers, configured for specific types of development. You can also create your own CodeSweepers or edit existing ones.

Macromedia CodeSweepers

There are CodeSweepers tailored to HTML only, HTML/CFML, JSP, Web-XML, and watch. My CodeSweeper is useful for testing and editing, and Macromedia Default HTML Tidy Settings is a pre-configured HTML Tidy for basic code preservation.

For information about formatting your documents to be XHTML-compliant, go to the Macromedia Developer Center for an article called An XHTML-Aware Editor, and read the section entitled An XHTML CodeSweeper.

HTML Tidy

HTML Tidy is an independent open source code utility for verifying and formatting HTML code. Developed by Dave Ragget under the auspices of the W3C, HTML Tidy is installed as an alternative to the Macromedia CodeSweepers. HTML Tidy provides a number of useful features for line wrapping, tag conversions, language support, working in XML, and other features not available in the Macromedia CodeSweepers.

Select Options > Settings > CodeSweeper and expand HTML Tidy CodeSweepers to view and set options.

You can easily update the HTML Tidy engine if new features are added to HTML Tidy between HomeSite releases.

To install a newer version of HTML Tidy:

  1. Click the link at the top of the HTML Tidy Settings pane.
  2. On the HTML Tidy Web site, download the latest version.
  3. Close HomeSite.
  4. Copy the tidy.exe files to your HomeSite root directory.
  5. Restart HomeSite.

Your HTML Tidy configuration is not affected by the update.

Running a CodeSweeper

Select Tools > CodeSweeper, then select a CodeSweeper from the dropdown list.

To set the default CodeSweeper:

  1. Open Options > Settings > CodeSweeper.

  2. Highlight a CodeSweeper entry in the list and click the Set as Default button.
  3. Click Apply.

Managing CodeSweepers

You can create new CodeSweepers, edit existing ones, and remove them as needed.

To add a new CodeSweeper:

  1. Select Options > Settings > CodeSweeper.
  2. Click New Profile.
  3. Enter a name for the CodeSweeper and select its type-either Macromedia CodeSweeper or HTML Tidy CodeSweeper.
  4. Click OK to add it to the list.
  5. Create a custom profile for it, following the steps in the next procedure for editing a CodeSweeper.
  6. When you are done, click Apply.

To edit a CodeSweeper:

  1. Select Options > Settings > CodeSweeper.
  2. Highlight a CodeSweeper in the list and click the Edit Profile button.
  3. Make changes to the General and Tag Specific options as necessary.
  4. When you are done, click Apply.

To delete a CodeSweeper:

  1. Select Options > Settings > CodeSweeper.
  2. Highlight the CodeSweeper to delete and click Remove CodeSweeper.
  3. Click Apply.

Setting Macromedia CodeSweeper options

The options described in this section apply only to Macromedia CodeSweepers. HTML Tidy options are covered in the next section.

To view or edit CodeSweeper options:

General options

Following are the general options you can set:

Macromedia CodeSweepers treat the colon character (:) in tag names as a normal character, allowing the processing of XML namespaces in tags such as <xsl:thistag name="foo"/>.

Tag-specific options

A wide range of options is available for the individual tags contained in a Macromedia CodeSweeper.

These options cover spacing and indenting and allow you to leave the selected tag unchanged when invoking the CodeSweeper. If you encounter problems parsing server-based script code, try enabling the Preserve tag formatting option.

The Strip tag from document option is especially handy for getting rid of superfluous and unwanted tags that are inserted by code generation tools.

To set rules for a tag:

  1. Select Options > Settings > CodeSweeper.
  2. Select a CodeSweeper from the list.
  3. Edit the General Settings tab as needed.
  4. Switch to the Tag Specific Settings tab and highlight a tag name in the list.

    Note that if you select "All Other Tags" in the list, the rules you select on this tab will apply to every tag that is not in the list but is found in a document.

  5. If the tag you need is not in the list, click Add Tag, type the tag name, and click OK.
  6. Edit the options for the tag.
  7. Click Update Tag.
  8. If you are done setting options, click Apply.

To remove a tag:

  1. Select Options > Settings > CodeSweeper.
  2. Highlight the tag to remove and click Remove Tag.
  3. If you are done setting options, click Apply.

Setting HTML Tidy options

Following are brief instructions for adding or editing an HTML Tidy profile. For more information, please see the HTML Tidy Web site at www.w3.org/People/Raggett/tidy/. You can access this Web site from the HTML Tidy Settings pane.

Adding a profile

Creating a custom HTML Tidy profile is much like creating one for a Macromedia CodeSweeper.

To create an HTML Tidy profile:

  1. Select Options > Settings > CodeSweeper.
  2. Click New Profile.
  3. Enter a profile name.
  4. Select HTML Tidy CodeSweeper from the drop-down type list and click OK.

    A set of options is already selected by default.

  5. Highlight the CodeSweeper in the list and click Edit Profile.
  6. Change the options as necessary.
  7. When you are done, click Apply.

Editing a profile

The HTML Tidy CodeSweepers pane gives you access to all the supported options, but you can also edit a profile directly. This can be useful in a couple of situations:

To edit an HTML Tidy profile:

  1. Open the TDY file (a text file) from the \Extensions\Codesweepers directory.
  2. Save a backup copy of the file before making any changes.
  3. Edit the name:value pairs as needed.
  4. Save the file.

The changes are reflected in the HTML Tidy CodeSweeper pane.

To remove an HTML Tidy profile:

Comments