Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
.DS_Store
bin
*.userprefs
*.pidb
TestHarness
.DS_Store
*.pidb
*.suo
*.user
*.userprefs
TestHarness
UpgradeLog.htm
/.vs/
/Backup
/**/bin/
/**/obj/
/WebEssentials2015-Settings.json
7 changes: 7 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# How to build TidyHtml5Managed

1. Clone the source code
2. Open the solution in Visual Studio
3. Select your target configuration and platform
4. Build the project
5. Copy the TidyHtml5Managed.dll from the output folder to your application project
1 change: 0 additions & 1 deletion Interop/.gitignore

This file was deleted.

143 changes: 0 additions & 143 deletions Interop/TidyOptionId.cs

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Frandi Dwi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
140 changes: 64 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,64 @@
# TidyManaged

This is a managed .NET/Mono wrapper for the open source, cross-platform Tidy library, a HTML/XHTML/XML markup parser & cleaner originally created by Dave Raggett.

I'm not going to explain Tidy's "raison d'être" - please read [Dave Raggett's original web page](http://www.w3.org/People/Raggett/tidy/) for more information, or the [SourceForge project](http://tidy.sourceforge.net/) that has taken over maintenance of the library.

## libtidy

This wrapper is written in C#, and makes use of .NET platform invoke (p/invoke) functionality to interoperate with the Tidy library "libtidy" (written in portable ANSI C).

Therefore, you'll also need a build of the binary appropriate for your platform. If you're after a 32 or 64 bit Windows build, or you want a more recent build for Mac OS X than the one that is bundled with the OS, try these:

- [Windows 32-bit build](http://wemakeapps.net/downloads/TidyManaged/libtidy.dll.Win32.zip)
- [Windows 64-bit build](http://wemakeapps.net/downloads/TidyManaged/libtidy.dll.Win64.zip)
- [Mac x64/x86/PPC fat binary](http://wemakeapps.net/downloads/TidyManaged/libtidy.dylib.zip) - this is a newer build (25 March 2009) than the version included in default OS X installations.

Otherwise, grab the latest source from the [SourceForge project](http://tidy.sourceforge.net/), and roll your own.

## Sample Usage

Here's a quick'n'dirty example using a simple console app.
Note: always remember to .Dispose() of your Document instance (or wrap it in a "using" statement), so the interop layer can clean up any unmanaged resources (memory, file handles etc) when it's done cleaning.

using System;
using TidyManaged;

public class Test
{
public static void Main(string[] args)
{
using (Document doc = Document.FromString("<hTml><title>test</tootle><body>asd</body>"))
{
doc.ShowWarnings = false;
doc.Quiet = true;
doc.OutputXhtml = true;
doc.CleanAndRepair();
string parsed = doc.Save();
Console.WriteLine(parsed);
}
}
}

results in:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Mac OS X (vers 31 October 2006 - Apple Inc. build 13), see www.w3.org" />
<title>test</title>
</head>
<body>
asd
</body>
</html>

## Notes for non-Windows platforms

Thanks to the platform-agnostic nature of ANSI C, and the excellent work of the people at the [Mono Project](http://www.mono-project.com/), you can use this wrapper library anywhere that Mono is supported, assuming you can have (or can build) a version of the underlying Tidy library for your platform. That shouldn't be too hard - it's a default part of a standard Mac OS X install, for example; it probably is for most Linux distributions as well.

Under Mono, you might need to re-map the p/invoke calls to the appropriate library - or you might find it just works. See [this page on DLL mapping](http://www.mono-project.com/Config_DllMap) for more information on achieving this. Note: the .config file needs to be configured for the TidyManaged DLL, NOT your application's binary.

### Example TidyManaged.dll.config
<configuration>
<dllmap dll="libtidy.dll" target="/Users/Mark/Code/Tidy/TestHarness/libtidy.dylib"/>
</configuration>


## The API

At this stage I've just created a basic mapping of each of the configuration options made available by Tidy to properties of the main Document object - I've renamed a few things here & there, but it should be pretty easy to figure out what each property does (the documentation included in the code includes the original Tidy option name for each property). You can read the [Tidy configuration documentation here](http://tidy.sourceforge.net/docs/quickref.html).

## The Future

At some point I'll add a nicer ".NET-style" API layer over the top, as it's a bit clunky (although perfectly usable) at the moment.
# TidyHtml5Managed
This is a managed .NET wrapper for the open source, cross-platform [Tidy HTML5](http://www.html-tidy.org/) library.

TidyHtml5Managed was forked from Mark Beaton's [TidyManaged](https://github.com/markbeaton/TidyManaged), with the main objectives are to implement
the new features of Tidy HTML5 and drop support for the old Tidy library.

Minimum version of the supported Tidy HTML5 library is [5.0.0](https://github.com/htacg/tidy-html5/releases/tag/5.0.0)

## Usage
### From Binary
1. Create your new application project
2. Get **TidyHtml5Managed.dll** from [release page](https://github.com/frandi/TidyHtml5Managed/releases)
(or go [build yourself](BUILD.md)), and add reference to it from your application project
3. Get **tidy.dll** from [release page](http://binaries.html-tidy.org/)
(or go [build yourself](https://github.com/htacg/tidy-html5/blob/master/README/README.md)), and put it in your application project's output folder
4. Build and Run your project

### From NuGet
1. Create your new application project
2. Install TidyHtml5Managed package from NuGet

`Install-Package TidyHtml5Managed`

3. Build and Run your project

### Code Sample

The following code is the sample of using the library in a Console Application.

```C#
using System;
using TidyManaged;

namespace TidyHtml5.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
string dirtyHtml = "<p>Test";
Console.WriteLine("Dirty HTML: " + dirtyHtml);

using (Document doc = Document.FromString(dirtyHtml))
{
doc.OutputBodyOnly = AutoBool.Yes;
doc.Quiet = true;
doc.CleanAndRepair();
string cleanHtml = doc.Save();

Console.WriteLine("Clean HTML: " + cleanHtml);
}

Console.ReadKey();
}
}
}
```

And here is the output:

![sample code output](images/sampleoutput.gif)

## License
TidyHtml5Managed uses MIT License as stated in the [License](LICENSE.md) file.
49 changes: 49 additions & 0 deletions TidyHtml5Managed.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TidyHtml5Managed", "TidyHtml5Managed\TidyHtml5Managed.csproj", "{D799633D-00EF-437C-B158-315557D930FC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TidyHtml5Managed_Net35", "TidyHtml5Managed_Net35\TidyHtml5Managed_Net35.csproj", "{94B637BE-23DC-403D-9369-A40FA2080808}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TidyHtml5Managed_Net45", "TidyHtml5Managed_Net45\TidyHtml5Managed_Net45.csproj", "{5FE3954B-6430-4B35-B5C7-5B32C515FCCD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TidyHtml5Managed_Net40", "TidyHtml5Managed_Net40\TidyHtml5Managed_Net40.csproj", "{840D7069-1605-4DC3-858B-A8F249FEDF4A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TidyHtml5Managed_Net20", "TidyHtml5Managed_Net20\TidyHtml5Managed_Net20.csproj", "{C9FF4F09-BF5E-4A10-B610-1DA0D2BD30DA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D799633D-00EF-437C-B158-315557D930FC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D799633D-00EF-437C-B158-315557D930FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D799633D-00EF-437C-B158-315557D930FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D799633D-00EF-437C-B158-315557D930FC}.Release|Any CPU.Build.0 = Release|Any CPU
{94B637BE-23DC-403D-9369-A40FA2080808}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94B637BE-23DC-403D-9369-A40FA2080808}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94B637BE-23DC-403D-9369-A40FA2080808}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94B637BE-23DC-403D-9369-A40FA2080808}.Release|Any CPU.Build.0 = Release|Any CPU
{5FE3954B-6430-4B35-B5C7-5B32C515FCCD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5FE3954B-6430-4B35-B5C7-5B32C515FCCD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5FE3954B-6430-4B35-B5C7-5B32C515FCCD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5FE3954B-6430-4B35-B5C7-5B32C515FCCD}.Release|Any CPU.Build.0 = Release|Any CPU
{840D7069-1605-4DC3-858B-A8F249FEDF4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{840D7069-1605-4DC3-858B-A8F249FEDF4A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{840D7069-1605-4DC3-858B-A8F249FEDF4A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{840D7069-1605-4DC3-858B-A8F249FEDF4A}.Release|Any CPU.Build.0 = Release|Any CPU
{C9FF4F09-BF5E-4A10-B610-1DA0D2BD30DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C9FF4F09-BF5E-4A10-B610-1DA0D2BD30DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9FF4F09-BF5E-4A10-B610-1DA0D2BD30DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9FF4F09-BF5E-4A10-B610-1DA0D2BD30DA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = TidyManaged.csproj
EndGlobalSection
EndGlobal
Loading