Skip to content

Commit

Permalink
Change options behavior + some fix to embedded header
Browse files Browse the repository at this point in the history
Change `options` behavior + some fix to embedded header
  • Loading branch information
zzzprojects committed Nov 30, 2017
1 parent ed53a1b commit 3d73f1d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
58 changes: 58 additions & 0 deletions src/HtmlAgilityPack.Shared/HtmlDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,14 @@ private void Parse()
CloseParentExplicitEnd();
}

//// CHECK if parent is compatible with end tag
//if (IsParentIncompatibleEndTag())
//{
// _state = ParseState.Text;
// PushNodeStart(HtmlNodeType.Text, _index);
// break;
//}

PushNodeNameEnd(_index - 1);
if (_state != ParseState.Tag)
continue;
Expand Down Expand Up @@ -1677,6 +1685,9 @@ private bool IsParentImplicitEnd()
case "p":
isImplicitEnd = nodeName == "p";
break;
case "option":
isImplicitEnd = nodeName == "option";
break;
}

return isImplicitEnd;
Expand All @@ -1697,11 +1708,58 @@ private bool IsParentExplicitEnd()
case "title":
isExplicitEnd = nodeName == "title";
break;
case "h1":
isExplicitEnd = nodeName == "h2" || nodeName == "h3" || nodeName == "h4" || nodeName == "h5";
break;
case "h2":
isExplicitEnd = nodeName == "h1" || nodeName == "h3" || nodeName == "h4" || nodeName == "h5";
break;
case "h3":
isExplicitEnd = nodeName == "h1" || nodeName == "h2" || nodeName == "h4" || nodeName == "h5";
break;
case "h4":
isExplicitEnd = nodeName == "h1" || nodeName == "h2" || nodeName == "h3" || nodeName == "h5";
break;
case "h5":
isExplicitEnd = nodeName == "h1" || nodeName == "h2" || nodeName == "h3" || nodeName == "h4";
break;
}

return isExplicitEnd;
}

//private bool IsParentIncompatibleEndTag()
//{
// // MUST be a end tag
// if (_currentnode._starttag) return false;

// bool isIncompatible = false;

// var parent = _lastparentnode.Name;
// var nodeName = Text.Substring(_currentnode._namestartindex, _index - _currentnode._namestartindex - 1);

// switch (parent)
// {
// case "h1":
// isIncompatible = nodeName == "h2" || nodeName == "h3" || nodeName == "h4" || nodeName == "h5";
// break;
// case "h2":
// isIncompatible = nodeName == "h1" || nodeName == "h3" || nodeName == "h4" || nodeName == "h5";
// break;
// case "h3":
// isIncompatible = nodeName == "h1" || nodeName == "h2" || nodeName == "h4" || nodeName == "h5";
// break;
// case "h4":
// isIncompatible = nodeName == "h1" || nodeName == "h2" || nodeName == "h3" || nodeName == "h5";
// break;
// case "h5":
// isIncompatible = nodeName == "h1" || nodeName == "h2" || nodeName == "h3" || nodeName == "h4";
// break;
// }

// return isIncompatible;
//}

private void CloseParentImplicitEnd()
{
HtmlNode close = new HtmlNode(_lastparentnode.NodeType, this, -1);
Expand Down
4 changes: 2 additions & 2 deletions src/HtmlAgilityPack.Shared/HtmlNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ static HtmlNode()
ElementsFlags.Add("source", HtmlElementFlag.Empty);
ElementsFlags.Add("form", HtmlElementFlag.CanOverlap);

// they sometimes contain, and sometimes they don 't...
ElementsFlags.Add("option", HtmlElementFlag.Empty);
//// they sometimes contain, and sometimes they don 't...
//ElementsFlags.Add("option", HtmlElementFlag.Empty);

// tag whose closing tag is equivalent to open tag:
// <p>bla</p>bla will be transformed into <p>bla</p>bla
Expand Down

0 comments on commit 3d73f1d

Please sign in to comment.