Skip to content

Commit

Permalink
Fix EmptyTag + Support NETStandard1_3 + Class Helper + Remove Fix
Browse files Browse the repository at this point in the history
Fix EmptyTag + Support NETStandard1_3 + Class Helper + Remove Fix
  • Loading branch information
zzzprojects committed Jun 17, 2017
1 parent 8c6f326 commit 418ab76
Show file tree
Hide file tree
Showing 11 changed files with 322 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
<Description />
<PostBuildEvent>del /f /q $(SolutionDir)..\Nuget\lib\NetStandard1_6\*
copy "$(TargetDir)Html*.*" $(SolutionDir)..\Nuget\lib\NetStandard1_6\*</PostBuildEvent>
<Authors>ZZZ Projects Inc.</Authors>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;DEBUG;NETSTANDARD;NETSTANDARD1_6;</DefineConstants>
<DefineConstants>TRACE;DEBUG;NETSTANDARD;NETSTANDARD1_6</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>TRACE;RELEASE;NETSTANDARD;NETSTANDARD1_6</DefineConstants>
<DefineConstants>TRACE;NETSTANDARD;NETSTANDARD1_6</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>

<PropertyGroup>
<TargetFramework>netstandard1.3</TargetFramework>
<PostBuildEvent>del /f /q C:\Users\Jonathan\Desktop\Z\zzzproject\HtmlAgilityPack\Solutions\..\Nuget\lib\NetStandard1_3\*
copy "Html*.*" C:\Users\Jonathan\Desktop\Z\zzzproject\HtmlAgilityPack\Solutions\..\Nuget\lib\NetStandard1_3\*</PostBuildEvent>
<PackageId>HtmlAgilityPack</PackageId>
<Version>1.5.0</Version>
<Authors>ZZZ Projects Inc.</Authors>
<Company>ZZZ Projects Inc.</Company>
<Product>Html Agility Pack</Product>
<Copyright>Copyright © ZZZ Projects Inc. 2014 - 2017</Copyright>
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>HtmlAgilityPack.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DefineConstants>TRACE;DEBUG;NETSTANDARD;NETSTANDARD1_3</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DefineConstants>TRACE;NETSTANDARD;NETSTANDARD1_3</DefineConstants>
</PropertyGroup>

<Import Project="..\HtmlAgilityPack.Shared\HtmlAgilityPack.Shared.projitems" Label="Shared" />

<ItemGroup>
<PackageReference Include="System.Net.Http" Version="4.3.1" />
<PackageReference Include="System.Xml.XmlDocument" Version="4.3.0" />
<PackageReference Include="System.Xml.XPath" Version="4.3.0" />
<PackageReference Include="System.Xml.XPath.XmlDocument" Version="4.3.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}
Binary file not shown.
13 changes: 9 additions & 4 deletions src/HtmlAgilityPack.Shared/HtmlDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,11 @@ public partial class HtmlDocument

internal static readonly string HtmlExceptionRefNotChild = "Reference node must be a child of this node";

internal static readonly string HtmlExceptionUseIdAttributeFalse =
"You need to set UseIdAttribute property to true to enable this feature";
internal static readonly string HtmlExceptionUseIdAttributeFalse = "You need to set UseIdAttribute property to true to enable this feature";

internal static readonly string HtmlExceptionClassDoesNotExist = "Class name doesn't exist";

internal static readonly string HtmlExceptionClassExists = "Class name already exists";

#endregion

Expand Down Expand Up @@ -1287,8 +1290,10 @@ private void Parse()
// by a /-character. If so, start parsing attribute-name immediately.
if (!IsWhiteSpace(_c))
{
PushAttributeNameStart(_index - 1);
_state = ParseState.AttributeName;
// Just do nothing and push to next one!
DecrementPosition();
_state = ParseState.BetweenAttributes;
continue;
}
else
{
Expand Down
98 changes: 87 additions & 11 deletions src/HtmlAgilityPack.Shared/HtmlNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,9 +1261,11 @@ public void PrependChildren(HtmlNodeCollection newChildren)
/// </summary>
public void Remove()
{
if (ParentNode != null)
ParentNode.ChildNodes.Remove(this);
}
if (ParentNode != null)
{
ParentNode.ChildNodes.Remove(this);
}
}

/// <summary>
/// Removes all the children and/or attributes of the current node.
Expand Down Expand Up @@ -1891,20 +1893,40 @@ private string GetRelativeXpath()
#endregion

#region Class Helper
/*

/// <summary>
/// Adds one or more classes to this node.
/// </summary>
/// <param name="name">The node list to add. May not be null.</param>
public void AddClass(string name)
{
AddClass(name, false);
}

/// <summary>
/// Adds one or more classes to this node.
/// </summary>
/// <param name="name">The node list to add. May not be null.</param>
/// <param name="throwError">true to throw Error if class name exists, false otherwise.</param>
public void AddClass(string name, bool throwError)
{
var classAttributes = Attributes.AttributesWithName("class");

if (!IsEmpty(classAttributes))
{
foreach (HtmlAttribute att in classAttributes)
{
SetAttributeValue(att.Name, att.Value + " " + name);
if (att.Value.Equals(name) || att.Value.Contains(name))
{
if (throwError)
{
throw new Exception(HtmlDocument.HtmlExceptionClassExists);
}
}
else
{
SetAttributeValue(att.Name, att.Value + " " + name);
}
}
}
else
Expand All @@ -1914,16 +1936,52 @@ public void AddClass(string name)
}
}

/// <summary>
/// Removes the class attribute from the node.
/// </summary>
public void RemoveClass()
{
RemoveClass(false);
}

/// <summary>
/// Removes the class attribute from the node.
/// </summary>
/// <param name="throwError">true to throw Error if class name doesn't exist, false otherwise.</param>
public void RemoveClass(bool throwError)
{
var classAttributes = Attributes.AttributesWithName("class");
if (IsEmpty(classAttributes) && throwError)
{
throw new Exception(HtmlDocument.HtmlExceptionClassDoesNotExist);
}

foreach (var att in classAttributes)
{
Attributes.Remove(att);
}
}

/// <summary>
/// Removes the specified class from the node.
/// </summary>
/// <param name="name">The class being removed. May not be <c>null</c>.</param>
public void RemoveClass(string name)
{
RemoveClass(name, false);
}

/// <summary>
/// Removes the specified class from the node.
/// </summary>
/// <param name="name">The class being removed. May not be <c>null</c>.</param>
/// <param name="throwError">true to throw Error if class name doesn't exist, false otherwise.</param>
public void RemoveClass(string name, bool throwError)
{
var classAttributes = Attributes.AttributesWithName("class");
if (IsEmpty(classAttributes))
if (IsEmpty(classAttributes) && throwError)
{
throw new ArgumentNullException("class");
throw new Exception(HtmlDocument.HtmlExceptionClassDoesNotExist);
}

else
Expand All @@ -1949,6 +2007,13 @@ public void RemoveClass(string name)
newClassNames = newClassNames.Trim();
SetAttributeValue(att.Name, newClassNames);
}
else
{
if (throwError)
{
throw new Exception(HtmlDocument.HtmlExceptionClassDoesNotExist);
}
}
if (string.IsNullOrEmpty(att.Value))
{
Attributes.Remove(att);
Expand All @@ -1963,6 +2028,17 @@ public void RemoveClass(string name)
/// <param name="newClass">The new class name.</param>
/// <param name="oldClass">The class being replaced.</param>
public void ReplaceClass(string newClass, string oldClass)
{
ReplaceClass(newClass, oldClass, false);
}

/// <summary>
/// Replaces the class name oldClass with newClass name.
/// </summary>
/// <param name="newClass">The new class name.</param>
/// <param name="oldClass">The class being replaced.</param>
/// <param name="throwError">true to throw Error if class name doesn't exist, false otherwise.</param>
public void ReplaceClass(string newClass, string oldClass, bool throwError)
{
if (string.IsNullOrEmpty(newClass))
{
Expand All @@ -1975,10 +2051,10 @@ public void ReplaceClass(string newClass, string oldClass)
}

var classAttributes = Attributes.AttributesWithName("class");

if (IsEmpty(classAttributes))
{
throw new ArgumentNullException("class");
throw new Exception(HtmlDocument.HtmlExceptionClassDoesNotExist);
}

foreach (var att in classAttributes)
Expand All @@ -1988,13 +2064,13 @@ public void ReplaceClass(string newClass, string oldClass)
}
}

private bool IsEmpty(IEnumerable en)
private bool IsEmpty(IEnumerable en)
{

foreach (var c in en) { return false; }
return true;
}
*/

#endregion
}
}
2 changes: 2 additions & 0 deletions src/HtmlAgilityPack.Shared/HtmlNodeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ public void RemoveAt(int index)
oldnode._prevnode = null;
oldnode._nextnode = null;
oldnode._parentnode = null;

_parentnode.SetChanged();
}

#endregion
Expand Down
Loading

0 comments on commit 418ab76

Please sign in to comment.