.. _dojox/html/format: dojox.html.format ================= :Status: Draft :Version: 1.0 :Authors: Jared Jurkiewicz :Developers: Jared Jurkiewicz :Available: since V1.4 .. contents:: :depth: 2 Have you ever wanted to format some HTML that came out of a textarea? Or the dijit.Editor? Or any other markup editor, for that matter, so it can be easily read by people? If so, then this package is for you! **dojox.html.format** package offers additional HTML helper functions for formatting HTML text. ======== Features ======== This package was created as a general purpose helper library for formatting HTML text markup. It currently contains one function, 'prettyPrint', which is intended to take a fragment of HTML text (usually the innerHTML of a document body) and format it so it is human readable. =========== Usage Notes =========== * You should not pass it a complete HTML document (one that includes tags, as the formatter makes use of the browser DOM parser to format the input. The problem with the HTML head and such tags is that most browsers will strip them out if they're included under any subtag, even ones that are not attached to the document. So to get the most consistent behaviors, only provide it document fragments, such as the innerHTML of a tag. * The format function tries to sort attributes and styles in 'alphabetical' order. * Browsers do not always return the same output for input. For example in a style attribute, you may specify something like: 'background-color: #fefefe'. On Firefox, you will get back: 'background-color: rgb(...)' The same value just represented differently. Again, these will all work fine when rendered in other browsers, it's just a point of note to not expect the *exact* same output. * Internet Explorer does not consistently keep comment nodes (). Sometimes they will be in a rendered doc and thus format-able, sometimes not. I wish this were not true, but alas it is. Internet explorer has a tendency to just delete nodes from documents if it thinks they're in the wrong spot, which then makes it impossible to serialize out in a nice format (when using the browser renderer to give you the tree structure). * Internet Explorer does not always keep .. html:: Enter some text, then press the button to see it in encoded format

Format some HTML markup with three space indent ----------------------------------------------- .. code-example:: :djConfig: parseOnLoad: true :version: 1.4 .. javascript:: .. html:: Enter some text, then press the button to see it in encoded format

Format some HTML markup with three space indent and 20 character line wrap -------------------------------------------------------------------------- .. code-example:: :djConfig: parseOnLoad: true :version: 1.4 .. javascript:: .. html:: Enter some text, then press the button to see it in encoded format

Format some HTML markup with three space indent and 20 character line wrap, XHTML --------------------------------------------------------------------------------- .. code-example:: :djConfig: parseOnLoad: true :version: 1.4 .. javascript:: .. html:: Enter some text, then press the button to see it in encoded format