qbd software ltd [UK]
qweb > moth > qbd software
html Format Format the HTML source of a Web Page
Version: 1.0.0
Date: 10 Dec 2001
Page: 10 Dec 2001
 
Links
qWeb Edit
 
Links
Download [7kb]
Contact
Mail Moth

Introduction

The DHTML Edit component includes the ability to preserve the layout and format of the HTML source code (sourcecodepreservation).  In MSHTML Edit this ability has gone and the source code from any element in an HTMLDocument will be returned unformatted like this:

<HTML><HEAD><TITLE>This is the title</TITLE>
</HEAD><BODY>
<TABLE>
<TR>
<TD>Cell One</TD>
</TR>
</TABLE>
</BODY>
</HTML>

This project will format the source code and return a formatted string that looks like this:

<HTML>
  <HEAD>
    <TITLE>This is the title</TITLE>
  </HEAD>
  <BODY>
    <TABLE>
      <TR>
        <TD>
          Cell One
        </TD>
      </TR>
    </TABLE>
  </BODY>
</HTML>

The project also includes a function to Save the formatted HTML.

What is Source Code Preservation?

HTML documents ignore certain characters like Carriage Returns (Ascii 13) and Line Feeds (Ascii 10) the functions of these characters are performed by tags.  Some characters are ignored depending on where they are.  Spaces (Ascii 32) are ignored unless they fall between other text or are designated as 'non breaking spaces' (&nbsp;).

Source Code Preservation retains the 'White Space' and line feed formatting of the document HTML.  This project doesn't preserve the formatting and white space information, it adds it.  This is similar to how FrontPage operates.

qWebFormat

The project contains a example form, the module 'modHTMFormat' and a test page called 'example.htm'.  There are two main functions, one formats the HTML source code, the second saves the formatted HTML.

 
htmFormatSource Function [String]
Parameters sHTMText As String
Optional IndentSize As Integer = 1
Optional IndentDoubleLine As Boolean = False
Optional UseTabIndent As Boolean = False
Description The unformatted HTML is passed to the function in 'sHTMText'.  The function will format the text using the IndentSize value as the increment for each indented block.

If the IndentDoubleLine parameter is set to 'True' a blank line is added before the opening tag of the main tags.

If UseTabIndent is set to True then indents will use Tab characters (Ascii 9) rather than Space characters (Ascii 32).

Details Two string constants are used to determine what action to take for each tag.
Major Tags The first constant determines the major tags and the contents of these are indented.

HTML, HEAD, BODY, STYLE, FRAME, TABLE, TR, TD, TBODY, THEAD, TFOOT, DIV, CENTER, SCRIPT, IFRAME, UL, OL, DL

Minor Tags The second constant indicates minor tags and the opening tag of these always starts a new line.

META, TITLE, LINK, P, LI, DT, DD, <!--

 
htmSaveFormatSource Function [Long]
Parameters sHTMText As String
sFileName As String
Optional IndentSize As Integer = 1
Optional IndentDoubleLine As Boolean = False
Optional UseTabIndent As Boolean = False
Optional WarnOverwrite As Boolean = False
Description Formats the sHTMText in the same way as htmFormatSource and saves the HTML document to the specified file (sFileName).

If WarnOverwirte is set to True the function will display a Warning if the file exists.

The function returns a Long value:
0 : successfully saved
-1: user cancelled overwrite
any other value: error number.

 

©2001-2004 qbd software ltd