Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

Text.Tidy

Performs tidy on XML or HTML.

Component Version macOS Windows Linux Server iOS SDK
Text 14.4 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "Text.Tidy"; Input { ; Options } )   More

Parameters

Parameter Description Example Flags
Input The input text.
Can be broken HTML or XML.
"<title>test</title" // missing >
Options The options as JSON object. Optional

Result

Returns text or error.

Description

Performs tidy on XML or HTML.
Sets error log, which can be queried with Text.TidyErrorLog function.
Returns new XML or HTML back after repairing.

For options, check this website:
https://api.html-tidy.org/tidy/tidylib_api_5.8.0/tidy_quickref.html

Use XML.Colorize to apply colors if needed.
By default we apply options to use utf-8 for input and output as encoding. Line endings use Char(13) as FileMaker does and we disable the tidy mark for the html header.

Examples

Cleanup HTML:

MBS( "Text.Tidy"; "<title>Test" )

Example result:
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
</head>
<body>
</body>
</html>

Cleanup some XML:

MBS( "Text.Tidy"; "<title>Test"; "{\"output-xml\": true, \"input-xml\": true}" )

Remove comments and only body part:

MBS( "Text.Tidy"; "<p>Hello</p> <!-- hello --> <p>World</p>"; "{\"hide-comments\":1, \"show-body-only\":1}" )

Example result:
<p>Hello</p>
<p>World</p>

Perform accessibility check:

Let([
html = MBS( "Text.Tidy"; "<p>Hello</p>"; "{\"accessibility-check\":1}" );
log = MBS("Text.TidyErrorLog")
]; log)

Example result:
line 1 column 1 - Warning: missing <!DOCTYPE> declaration
line 1 column 1 - Warning: inserting implicit <body>

Accessibility Checks:

line 1 column 1 - Warning: inserting missing 'title' element
Info: Document content looks like HTML5
Tidy found 3 warnings and 0 errors!

Perform cleanup of HTML fragment:

MBS( "Text.Tidy"; "<p><i>Hello <b>World</p>"; "{\"show-body-only\":1}" )

Example result: <p><i>Hello <b>World</b></i></p>

See also

Release notes

Blog Entries

This function checks for a license.

Created 21st July 2024, last changed 25th October 2024


Text.TextToRTF - Text.TidyErrorLog