Text.Tidy
---------

Performs tidy on XML or HTML.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [Text](component_Text.md) | [14.4](newinversion144.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "Text.Tidy"; Input { ; Options } ) 

**MBS**( **"Text.Tidy";** /\* Performs tidy on XML or HTML. \*/  
**$Input**; /\* The input text.  
Can be broken HTML or XML.e.g. "&lt;title&gt;test&lt;/title" // missing &gt; \*/   
**$Options**) /\* Optional; The tidy options as JSON object. \*/ 

### Parameters

| Parameter | Description | Example | Flags |
|---|---|---|---|
| Input | The input text.   Can be broken HTML or XML. | "&lt;title&gt;test&lt;/title" // missing &gt; |  |
| Options | The tidy 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](TextTidyErrorLog.md) 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](https://api.html-tidy.org/tidy/tidylib_api_5.8.0/tidy_quickref.html)  
  
Use [XML.Colorize](XMLColorize.md) 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"; "&lt;title&gt;Test" )  
<small>  
Example result:   
&lt;!DOCTYPE html&gt;  
&lt;html&gt;  
&lt;head&gt;  
&lt;title&gt;Test&lt;/title&gt;  
&lt;/head&gt;  
&lt;body&gt;  
&lt;/body&gt;  
&lt;/html&gt;</small>Cleanup some XML:

 MBS ( "Text.Tidy"; "&lt;title&gt;Test"; "{\\"output-xml\\": true, \\"input-xml\\": true}" )  
Remove comments and only body part:

 MBS ( "Text.Tidy"; "&lt;p&gt;Hello&lt;/p&gt; &lt;!-- hello --&gt; &lt;p&gt;World&lt;/p&gt;"; "{\\"hide-comments\\":1, \\"show-body-only\\":1}" )  
<small>  
Example result:   
&lt;p&gt;Hello&lt;/p&gt;  
&lt;p&gt;World&lt;/p&gt;</small>Perform accessibility check:

 Let(\[  
html = MBS ( "Text.Tidy"; "&lt;p&gt;Hello&lt;/p&gt;"; "{\\"accessibility-check\\":1}" );  
log = MBS ("[Text.TidyErrorLog](TextTidyErrorLog.md)")  
\]; log)  
<small>  
Example result:   
line 1 column 1 - Warning: missing &lt;!DOCTYPE&gt; declaration  
line 1 column 1 - Warning: inserting implicit &lt;body&gt;  
  
Accessibility Checks:  
  
line 1 column 1 - Warning: inserting missing 'title' element  
Info: Document content looks like HTML5  
Tidy found 3 warnings and 0 errors!</small>Perform cleanup of HTML fragment:

 MBS ( "Text.Tidy"; "&lt;p&gt;&lt;i&gt;Hello &lt;b&gt;World&lt;/p&gt;"; "{\\"show-body-only\\":1}" )  
<small>  
Example result: &lt;p&gt;&lt;i&gt;Hello &lt;b&gt;World&lt;/b&gt;&lt;/i&gt;&lt;/p&gt;</small>### See also

- [Text.HTMLtoJSON](TextHTMLtoJSON.md)
- [Text.HTMLtoStyledText](TextHTMLtoStyledText.md)
- [Text.TidyErrorLog](TextTidyErrorLog.md)
- [XML.Colorize](XMLColorize.md)
- [XML.Tidy](XMLTidy.md)

### Release notes

- **Version 14.4**
    - Added [Text.Tidy](https://www.mbsplugins.eu/TextTidy.shtml) and [Text.TidyErrorLog](https://www.mbsplugins.eu/TextTidyErrorLog.shtml) functions to tidy XML and HTML.

### Blog Entries

- [New in MBS FileMaker Plugin 14.4](https://www.mbsplugins.de/archive/2024-09-24/New_in_MBS_FileMaker_Plugin_14/monkeybreadsoftware_blog_filemaker)
- [Neues MBS Plugin 14.4 für Claris FileMaker](https://www.mbsplugins.de/archive/2024-09-17/Neues_MBS_Plugin_144_für_Clar/monkeybreadsoftware_blog_filemaker)
- [MBS Plugin 14.4 for Claris FileMaker](https://www.mbsplugins.de/archive/2024-09-17/MBS_Plugin_144_for_Claris_File/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 14.4pr1](https://www.mbsplugins.de/archive/2024-07-24/MBS_FileMaker_Plugin_version_1/monkeybreadsoftware_blog_filemaker)

This function checks for a license.

Created 21st July 2024 , last changed 11st October 2025

  
[Text.TextToRTF](TextTextToRTF.md) - [Text.TidyErrorLog](TextTidyErrorLog.md)

[HTML Version](TextTidy.shtml)