Skip to content

Commit

Permalink
Merge pull request AngleSharp#5 from ricardobrandao/master
Browse files Browse the repository at this point in the history
We can now render the DOM with a custom IOutputFormatter.
  • Loading branch information
mganss committed Aug 13, 2014
2 parents 0e968a6 + 01bd3f2 commit f28e122
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions HtmlSanitizer/HtmlSanitizer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CsQuery;
using CsQuery.Output;
using System;
using System.Collections.Generic;
using System.Globalization;
Expand Down Expand Up @@ -272,8 +273,9 @@ protected virtual void OnRemovingStyle(RemovingStyleEventArgs e)
/// </summary>
/// <param name="html">The HTML to sanitize.</param>
/// <param name="baseUrl">The base URL relative URLs are resolved against. No resolution if empty.</param>
/// <returns>The sanitized HTML.</returns>
public string Sanitize(string html, string baseUrl = "")
/// <param name="outputFormatter">The CsQuery output formatter used to render the DOM. Using the default formatter if null.</param>
/// <returns>The sanitized HTML.</returns>
public string Sanitize(string html, string baseUrl = "", IOutputFormatter outputFormatter = null)
{
var dom = CQ.Create(html);

Expand Down Expand Up @@ -313,9 +315,12 @@ public string Sanitize(string html, string baseUrl = "")
if (val.Contains('<')) { val = val.Replace("<", "&lt;"); tag.SetAttribute(attribute.Key, val); }
if (val.Contains('>')) { val = val.Replace(">", "&gt;"); tag.SetAttribute(attribute.Key, val); }
}
}

var output = dom.Render(DomRenderingOptions.RemoveComments | DomRenderingOptions.QuoteAllAttributes);
}

if (outputFormatter == null)
outputFormatter = new FormatDefault(DomRenderingOptions.RemoveComments | DomRenderingOptions.QuoteAllAttributes, HtmlEncoders.Default);

var output = dom.Render(outputFormatter);

return output;
}
Expand Down

0 comments on commit f28e122

Please sign in to comment.