PostHeaderIcon c++ tidy

LibTidy is a library to clean or process HTML documents, well formed or not. For more information, please see tidy homepage.

How to use it?

1.Download the windows libtidy from github page

2.built it on diff platform:
Directory System Comments
——— ——————– ————————–
gmake GNU Make Used for “official” builds

gnuauto GNU AutoConf Supports shared lib builds

msvc MS Visual C++ v6 Win32 only

rpm Script for packages For Linux distribution supporting rpm
3.include it in your project.
Here for example, I use VS2005(why it? because the newer of VS is so big and heavyweight)
a. include the include dir which contains the all header files
b. link the libtidy.lib
c. compile your code.

// stdafx.h
#pragma once

#define WIN32_LEAN_AND_MEAN
#include <stdio.h>
#include <tchar.h>
#include <tidy.h>
#include <buffio.h>
// tidydemo.cpp
//

#include "stdafx.h"

int _tmain(int argc, _TCHAR* argv[])
{
	const char* input = "

Foo!";
	TidyBuffer output = {0};
	TidyBuffer errbuf = {0};
	int rc = -1;
	Bool ok;

	TidyDoc tdoc = tidyCreate();                     // Initialize "document"

	ok = tidyOptSetBool( tdoc, TidyXhtmlOut, yes );  // Convert to XHTML
	if ( ok )
		rc = tidySetErrorBuffer( tdoc, &errbuf );      // Capture diagnostics
	if ( rc >= 0 )
		rc = tidyParseString( tdoc, input );           // Parse the input
	if ( rc >= 0 )
		rc = tidyCleanAndRepair( tdoc );               // Tidy it up!
	if ( rc >= 0 )
		rc = tidyRunDiagnostics( tdoc );               // Kvetch
	if ( rc > 1 )                                    // If error, force output.
		rc = ( tidyOptSetBool(tdoc, TidyForceOutput, yes) ? rc : -1 );
	if ( rc >= 0 )
		rc = tidySaveBuffer( tdoc, &output );          // Pretty Print

	if ( rc >= 0 )
	{
		printf( "\nThen here is the result:\n\n%s", output.bp );
	}
	else
		printf( "A severe error (%d) occurred.\n", rc );

	tidyBufFree( &output );
	tidyBufFree( &errbuf );
	tidyRelease( tdoc );
	return rc;
}
12,385 views

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Copyright © 2010 - C++ Technology. All Rights Reserved.

Powered by Jerry | Free Space Provided by connove.com