General usage:
var libtidy = require("libtidy");
Asynchronous function. Suggested entry point for most applications.
- input – anything except a buffer will be converted to String and then turned into a buffer.
- opts – a dictionary of libtidy options.
- cb – callback following the
callback convention,
i.e. with signature
function(exception, {output, errlog})
or omitted to return a promise.
The function applies the following libtidy options by default:
- newline = LF
Constructor. Main entry point for low-level access to the library.
Contruction wraps tidyCreateWithAllocator
,
while garbage collection triggers tidyRelease
.
Asynchronous method binding tidyCleanAndRepair
.
- cb – callback following the
callback convention,
i.e. with signature
function(exception, {errlog})
or omitted to return a promise.
Synchronous method binding tidyCleanAndRepair
.
Returns any diagnostics encountered during operation, as a string.
Retrieve the TidyOption object for the key in question.
- key – can be a string (hyphen-separated, underscore_separated or camelCase), a numeric id (not portable) or a TidyOption object (rather pointless here).
Wraps tidyGetOptionByName
and tidyGetOption
.
Retrieve the list of all known options, as an array of TidyOption objects.
Wraps tidyGetOptionList
and tidyGetNextOption
.
Get the current value of the option in question.
For enumerated options,
the result will return the current pick value
as a string.
Otherwise, optGet
returns the option value based on its
type,
i.e. call tidyOptGetBool
, tidyOptGetInt
or tidyOptGetValue
.
Empty strings will be returned as null
like libtidy does.
- key – can be a string (hyphen-separated, underscore_separated or camelCase), a numeric id (not portable) or a TidyOption object.
Get a string representation of the current value for a given option. The option must have a pick list associated. It applies to enumerated options (which internally are of type int) and to boolean options.
For most applications, optGet should be more suitable.
- key – can be a string (hyphen-separated, underscore_separated or camelCase), a numeric id (not portable) or a TidyOption object.
Wraps tidyOptGetCurrPick
.
Describe the named option. The description is a HTML snippet, returned as a string.
- key – can be a string (hyphen-separated, underscore_separated or camelCase), a numeric id (not portable) or a TidyOption object.
Wraps tidyOptGetDoc
.
Identify related options. The result is a (possibly empty) array of TidyOption objects.
- key – can be a string (hyphen-separated, underscore_separated or camelCase), a numeric id (not portable) or a TidyOption object.
Wraps tidyOptGetDocLinksList
and tidyOptGetNextDocLinks
.
Set the value for the option in question.
- key – can be a string (hyphen-separated, underscore_separated or camelCase), a numeric id (not portable) or a TidyOption object.
- value – new value of the option.
The interpretation of the value
depends on the
type of the option:
- If the type of the option is integer and the provided value is a number,
the method will call
tidyOptSetInt
. - If the type of the option is boolean and the provided value is boolean,
the method will call
tidyOptSetBool
. - If the value is
null
,tidyOptSetValue
will be called with an empty string. - In all other cases, it calls
tidyOptSetValue
, which in turn uses the libtidy option parser. This in particular allows parsing enumerated options. The passed value is the result of JavaScript conversion to string. One effect of this is that it is possible to pass a boolean value to an AutoBool option and obtain the expected result.
Note that tidyOptSetValue
may not reject all values you'd expect it would.
For example, boolean options are judged by their first non-whitespace letter,
and accept the auto
keyword just like options of type AutoBool.
Getter and setter pair.
The getter will build a configuration dictionary of all options. Each element of the dictionary corresponds to one option, with the key given in underscore_separated format. Reading that element implies a call to optGet, while writing it corresponds to calling optSet.
The setter will take the assigned value and merge its elements into the configuration one at a time. This merging goes through optSet, so keys can use any of the allowed option naming schemes.
Asynchronous method binding tidyParseBuffer
.
Callback follows the callback convention,
i.e. have signature function(exception, {errlog})
- buf – must be a buffer, other input will be rejected.
- cb – callback following the
callback convention,
i.e. with signature
function(exception, {errlog})
or omitted to return a promise.
It is suggested to use this method for strings as well,
since JavaScript strings come with a length information
and may contain \0
characters while C strings are null-terminated.
Make sure to leave the input-encoding
option at its default of UTF8
if the input is Buffer(str)
.
Synchronous method binding tidyParseBuffer
.
Returns any diagnostics encountered during operation, as a string.
- buf – must be a buffer, other input will be rejected.
It is suggested to use this method for strings as well,
since JavaScript strings come with a length information
and may contain \0
characters while C strings are null-terminated.
Make sure to leave the input-encoding
option at its default of UTF8
if the input is Buffer(str)
.
Asynchronous method binding tidyRunDiagnostics
.
Callback follows the callback convention,
i.e. have signature function(exception, {errlog})
or is omitted to return a promise.
Synchronous method binding tidyRunDiagnostics
.
Returns any diagnostics encountered during operation, as a string.
Asynchronous method binding tidySaveBuffer
.
- cb – callback following the
callback convention,
i.e. with signature
function(exception, {errlog, output})
whereoutput
is a buffer, or omitted to return a promise.
Synchronous method binding tidySaveBuffer
.
Returns the resulting buffer as a string.
Asynchronous method performing the four basic steps in a row:
tidyParseBuffer
tidyCleanAndRepair
tidyRunDiagnostics
tidySaveBuffer
- buf – must be a buffer, other input will be rejected.
- cb – callback following the
callback convention,
i.e. with signature
function(exception, {errlog, output})
whereoutput
is a buffer, or omitted to return a promise.
Although part of the public interface, this constructor is not meant to be called from JavaScript. Its prototype is open to extension, though.
One can obtain objects of this class from TidyDoc.getOption, TidyDoc.getOptionList or TidyDoc.optGetDocLinksList.
The properties of this type are implemented as getters, so actually retrieving these values may incur some performance cost, and retrieving the same property twice may lead to different but equivalent objects.
The category of the option, as a string.
Will be one of "Markup"
, "Diagnostics"
, "PrettyPrint"
,
"Encoding"
or "Miscellaneous"
.
Wraps tidyOptGetCategory
.
The default value of the option.
The returned type depends on the type of the option.
Contrary to optGet
,
the default will be a number for enumerated types,
not a string, since tidyOptGetCurrPick
has no
matching tidyOptGetDefaultPick
or similar.
Wraps tidyOptGetDefaultBool
, tidyOptGetDefaultInt
or tidyOptGetDefault
.
The numeric identifier identifying this option. The returned number is not portable across different versions, different builds and perhaps even different machines. So be careful using this, preferably only within a single process. In general, the name is preferable.
Wraps tidyOptGetId
.
The name of the option, in its hyphen-separated default form.
Wraps tidyOptGetName
.
List of possible values for enumerated properties, as an array of strings. Otherwise the list will be empty.
Wraps tidyOptGetPickList
and tidyOptGetNextPick
.
Indicates whether the property is read-only.
Wraps tidyOptIsReadOnly
.
Returns the name of the option.
Returns the type of the option, as a string.
Will be one of "boolean"
, "integer"
, "string"
.
Note that enumerated options, including those of type AutoBool,
will be represented as type "integer"
.
Wraps tidyOptGetType
.
Elements of the compat
namespace offer
compatibility with other libtidy bindings for node.
This offers a drop-in replacement for htmltidy and htmltidy2.
-var htmltidy = require("htmltidy2");
+var htmltidy = require("libtidy").compat.htmltidy;
Asynchronous function.
Similar to tidyBuffer
,
but the arguments to the callback are different.
In case of a non-serious error,
the first argument will contain any diagnostic messages as a string,
while the second argument holds the output, again as a string.
If the show-warnings
option is false
(which is the default for this function),
then in case of a successfully generated output
an empty diagnostics string will be returned.
- input – anything except a buffer will be converted to String and then turned into a buffer.
- opts – a dictionary of libtidy options.
- cb – callback with signature
function(err, output)
, whereerr
is anError
in case of a serious error, or a diagnostic string in case of less serious problems.
The function applies the following libtidy options by default:
- show-warnings = no
- tidy-mark = no
- force-output = yes
- quiet = no