htmlFile( fname, e )

Renders the specified XML element e as an entire HTML document to a file fname, returning a URL object for the written page.

You can supply any MillScript object as the fname, but there are three points to consider:

  1. If the object is a URL object, the XML element e will be rendered to the file it specifies.
  2. If the object is not a URL, one will be created using the fname. If the fname contains a period, anything up to the last one will be considered the filename and anything after will be considered the extension. If the fname doesn't contain a period, the extension "html" will be appended automatically. e.g.
    :-) htmlFile( "sample", <html/> );
    About to render to .../output/sample.html
    There is 1 result
    /sample.html
    :-) htmlFile( "sample.wml", <wml/> );
    About to render to .../output/sample.wml
    There is 1 result
    /sample.wml
              
  3. If the specified fname has already been created in the current MillScript instance, the filename will have an integer appended to it to make it unique. Please see the notes for the newURL function for more details.
:-) folder.addLast( "parent" );
There are 0 results
:-) htmlFile(
:-)   "sample",
:-)   <html>
:-)     <head><title>"Sample page"</title></head>
:-)     <body><h1>"Sample Page"</h1></body>
:-)   </html>
:-) );
About to render to .../output/parent/sample.html
There is 1 result
/parent/sample.html
      
The XML element e will be rendered as HTML, with a few important points:
  • All ampersands in plain text will be written in their escaped form &#38;
  • Any tags which are forbidden to have closing tags will not have them. e.g. meta, link, br
  • Tags which are not part of the HTML specification will still be rendered into the document, with closing tags.
  • Any character which cannot be written in the documents character encoding will be written as a unicode character reference in the form &#D;, where D is the decimal number for the character in unicode.
  • The document will be written with an HTML 4.01 Transitional document type. i.e.
    <!DOCTYPE HTML PUBLIC
    "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
              
Finally, after writing the HTML page, the htmlFile function returns a URL object for the written page. This could then be used for creating links to the page, etc.

Notes

If you use the same URL object multiple times, each successive use will replace the previously written file. See newURL for details.