Skip to content

Commit

Permalink
Added options for: #567
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanMagnan committed Aug 30, 2024
1 parent d9f4c05 commit 224030f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/HtmlAgilityPack.Shared/HtmlDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,16 @@ public static bool DisableBehaviorTagP
/// </summary>
public bool OptionWriteEmptyNodes;

/// <summary>
/// The max number of nested child nodes.
/// Added to prevent stackoverflow problem when a page has tens of thousands of opening html tags with no closing tags
/// </summary>
public int OptionMaxNestedChildNodes = 0;
/// <summary>
/// Defines if empty nodes must be written without the additional space. Default is false.
/// </summary>
public bool OptionWriteEmptyNodesWithoutSpace;

/// <summary>
/// The max number of nested child nodes.
/// Added to prevent stackoverflow problem when a page has tens of thousands of opening html tags with no closing tags
/// </summary>
public int OptionMaxNestedChildNodes = 0;


#endregion
Expand Down
11 changes: 10 additions & 1 deletion src/HtmlAgilityPack.Shared/HtmlNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2073,7 +2073,16 @@ public virtual void WriteTo(TextWriter outText, int level = 0)
if (IsEmptyElement(Name))
{
if ((_ownerdocument.OptionWriteEmptyNodes) || (_ownerdocument.OptionOutputAsXml))
outText.Write(" />");
{
if(_ownerdocument.OptionWriteEmptyNodesWithoutSpace)
{
outText.Write("/>");
}
else
{
outText.Write(" />");
}
}
else
{
if (Name.Length > 0 && Name[0] == '?')
Expand Down

0 comments on commit 224030f

Please sign in to comment.