Skip to content

Commit

Permalink
Add HtmlParserFactory and DefaultHtmlParserFactory.
Browse files Browse the repository at this point in the history
Closes #79
  • Loading branch information
mganss committed Aug 4, 2016
1 parent 3c02cec commit 97d7532
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/HtmlSanitizer/HtmlSanitizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ public HtmlSanitizer(IEnumerable<string> allowedTags = null, IEnumerable<string>
AllowedAtRules = new HashSet<CssRuleType>(DefaultAllowedAtRules);
}

/// <summary>
/// Gets or sets the default <see cref="Func{HtmlParser}"/> object that creates the parser used for parsing the input.
/// </summary>
public static Func<HtmlParser> DefaultHtmlParserFactory { get; set; } = CreateParser;

/// <summary>
/// Gets or sets the <see cref="Func{HtmlParser}"/> object the creates the parser used for parsing the input.
/// </summary>
public Func<HtmlParser> HtmlParserFactory { get; set; } = DefaultHtmlParserFactory;

/// <summary>
/// Gets or sets the default <see cref="IMarkupFormatter"/> object used for generating output. Default is <see cref="HtmlMarkupFormatter.Instance"/>.
/// </summary>
Expand Down Expand Up @@ -363,7 +373,7 @@ private static IEnumerable<INode> GetAllNodes(INode dom)
/// <returns>The sanitized HTML body fragment.</returns>
public string Sanitize(string html, string baseUrl = "", IMarkupFormatter outputFormatter = null)
{
var parser = CreateParser();
var parser = HtmlParserFactory();
var dom = parser.Parse("<html><body></body></html>");
dom.Body.InnerHtml = html;

Expand All @@ -383,7 +393,7 @@ public string Sanitize(string html, string baseUrl = "", IMarkupFormatter output
/// <returns>The sanitized HTML document.</returns>
public string SanitizeDocument(string html, string baseUrl = "", IMarkupFormatter outputFormatter = null)
{
var parser = CreateParser();
var parser = HtmlParserFactory();
var dom = parser.Parse(html);

DoSanitize(dom, dom.DocumentElement, baseUrl);
Expand Down

0 comments on commit 97d7532

Please sign in to comment.