Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #26. Exclude 'Form' tag from ElementsFlags #28

Merged

Conversation

feeeper
Copy link
Contributor

@feeeper feeeper commented Oct 20, 2016

Fix #26
As I can see it the feature of the HtmlAgilityPack (for HTML 3.2). And one of the workarounds is exclude "form" from ElementsFlags dictionary.

@JackWFinlay
Copy link
Owner

What does it do exactly? Does it actually exclude all form tags and their children? I'm wary of bringing this in until I know what the output will be. Can you give some examples of the output?

I don't really want to be excluding forms from the output (I'm using the jsonize library in another project that it would be really nice to have forms included in).

@feeeper
Copy link
Contributor Author

feeeper commented Oct 20, 2016

No, it doesn't exclude all form tags. It just says to HtmlAgilityPack that form tag can not overlap other HTML elements like so:

<!-- Valid HTML 3 markup -->
<div><form></div></form>

HtmlNode.ElementsFlags.Remove("form"); disables that behavior.

More about what it it on StackOverflow discussion or on HtmlAgilityPack repository workitem on CodePlex.

With that line of code test TestFormNodeShouldBeNode passes:

Jsonize jsonize = new Jsonize("<html><head></head><body><form></form></body></html>");
var result = jsonize.ParseHtmlAsJsonString(jsonizeConfiguration);
/*
result:
{
    "node":"Document",
    "child":[
        {
            "tag":"html",
            "child":[
                {
                    "tag":"head"
                },
                {
                    "tag":"body",
                    "child":[
                        {
                            "tag":"form"
                        }
                    ]
                }
            ]
        }
    ]
}
*/

UPD: From HtmlAgilityPack sources:

public partial class HtmlNode : IHtmlBaseNode
{
        /// <summary>
        /// Gets a collection of flags that define specific behaviors for specific element nodes.
        /// The table contains a DictionaryEntry list with the lowercase tag name as the Key, and a combination of HtmlElementFlags as the Value.
        /// </summary>
        public static Dictionary<string, HtmlElementFlag> ElementsFlags;

        // some code

        static HtmlNode()
        {
            // ...
            ElementsFlags.Add("form", HtmlElementFlag.CanOverlap | HtmlElementFlag.Empty);
            // ...
        }
// more code
}

@feeeper feeeper changed the title Fix #26. Exclude 'From' tag from ElementsFlags Fix #26. Exclude 'Form' tag from ElementsFlags Oct 20, 2016
@JackWFinlay JackWFinlay merged commit a1a5b53 into JackWFinlay:master Oct 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants