HTML Tidy Sample Program in C++17
Observation.

Though you are compiling this with a C++ compiler and using a couple of C++ classes this is still C code. The style is C and does not reflect the standard idioms of C++.

We refer to code written like this as "C with classes".

Exception Safety

When you see code that looks like:

&lt;Create Resource&gt;

&lt;Do Stuff&gt;

&lt;Destroy Resource&gt;


This is not exception safe. If the code in &lt;Do Stuff&gt; throws an exception then &lt;Destroy Resource&gt; will not be executed. Now you think none of this code throws exceptions and Tidy is a C-library so it will not. But I bet Tidy allows you to register callbacks. These callbacks can throw exceptions and eventually you will add one to the code.

Example:

   TidyDoc tdoc = tidyCreate();
   // Stuff
   tidyRelease(tdoc);


The correct way to do this is to use the RAII idiom. This means creating a class where the constructor allocates the resource and the destructor deallocates the resource.

Since the destructor of an object is automatically called when an object goes out of scope (this includes when the stack is unwound by an exception being thrown) this makes resource allocation/deallocation exception safe.

class TidyDocCPP
{
    TidyDoc tdoc;
    public:
        TidyDocCPP() {
            tdoc = tidyCreate();
        }
        ~TidyDocCPP() {
            tidyRelease(tdoc);
        }
        // This is used to convert an object back to the C form
        // so it can be used in the normal C tidy functions.
        operator TidyDoc() const {
            return tdoc;
        }

        // Need to do this to satisfy rule of 5
        // Don't worry about this section yet.
        TidyDocCPP(TidyDocCPP const&amp;)            = delete;
        TidyDocCPP(TidyDocCPP&amp;&amp;)                 = delete;
        TidyDocCPP&amp; operator=(TidyDocCPP const&amp;) = delete;
        TidyDocCPP&amp; operator=(TidyDocCPP&amp;&amp;)      = delete;
};


Now it can be used like this:

{
    TidyDocCPP    doc;
    tidyOptSetInt(doc, TidyIndentContent, yes); // doc is auto converted
}
// doc goes out of scope here.
// This calls the destructor and releases the resource.


Design

You read the input into a string. Then pass this string to tidyit().

The first issue I have with this is that you pass the string by value. This basically makes a copy of the whole string. Given that modern web pages are huge this is a terrible idea. The main page of stackoverflow.com is 250K.

You should pass immutable strings by const reference (this prevents the copy but still allows full read access).

But even reading the data into a string is incorrect. You have a stream of data (the input) you should use Tidy stream reading capabilities.

Rather than using

 tidyParseString(tdoc, a_input.c_str()


You should use:

 tidyParseStdin(doc);


If you want to be more generic:

 tidyParseSource(doc, inputSource);
 // You will need to build a wrapper aournd TidyInputSource
 // http://tidy.sourceforge.net/docs/api/group__IO.html#g86fcc3c86bd63b26a559938bc38d34bb


Vertical Space

Add vertical space to make your code readable. The current way it is all jammed together makes it highly unreadable.

Brace Alignment

Use one of the standard brae alignment strategies. Yours does not match any standard I have seen.

// K&amp;R Style.  Very common
if () {
}

// Allman.     Very common
if ()
{
}


What you are using seems to be a mix of K&amp;R and Ratliff Style

// Ratliff     Very uncommon
if () {
    }


I have never seen it outside this wikipedia page: https://en.wikipedia.org/wiki/Indent_style 

Pick one and use it consistently.