Nested Forms
Hi. Reading through this: https://htmlparser.info/parser/#forms I am confused about parsing the below html ( github was hiding less than and greater than symbols): form A div B form /form C /div D /form
### From the Spec:
An end tag whose tag name is "form" If there is no template element on the stack of open elements, then run these substeps:
-
Let node be the element that the form element pointer is set to, or null if it is not set to an element.
-
Set the form element pointer to null.
-
If node is null or if the stack of open elements does not have node in scope, then this is a parse error; return and ignore the token.
-
Generate implied end tags.
-
If the current node is not node, then this is a parse error.
-
Remove node from the stack of open elements.
My questions are: According to the spec it states "Let node be the element that the form element pointer is set to, or null if it is not set to an element." What node was let to ? Why was 4. Generate implied end tags (I don't understand the meaning of implied tags, please explain) ? While explaining in your book you mentioned (I quote) "step 3 doesn't apply (node is the form),..." If node is form then why did you said Step 5 applies since the current node is a div ? What is the difference between node in step 1 and node in step 5 ? Thank you
You can use triple backtick (```) for code blocks in GitHub:
<form>
A
<div>
B
<form></form>
C
</div>
D
</form>
My questions are: According to the spec it states "Let node be the element that the form element pointer is set to, or null if it is not set to an element." What node was let to ?
node is set to the outer form element. "form element pointer" gets set when parsing that start tag: https://html.spec.whatwg.org/multipage/parsing.html#parsing-main-inbody:form-element-pointer-2
Why was 4. Generate implied end tags (I don't understand the meaning of implied tags, please explain) ?
It's defined here: https://html.spec.whatwg.org/multipage/parsing.html#generate-implied-end-tags
If the current node is one of the listed elements (like p, dd, etc, which have optional end tags), they get popped off the stack of open elements, without a parse error. In our case, the current node is a div, which is not one of the listed elements in "generate implied end tags".
While explaining in your book you mentioned (I quote) "step 3 doesn't apply (node is the form),..." If node is form then why did you said Step 5 applies since the current node is a div ? What is the difference between node in step 1 and node in step 5 ?
"current node" in step 5 refers to: https://html.spec.whatwg.org/multipage/parsing.html#current-node
"node" in step 1 is a variable that is set to the form element pointer.
So current node is the div, and node is the outer form.
This could maybe be easier to follow if the spec quotes in the book contain links and are more carefully marked up so it's clearer what is a variable, etc. I can try to make this clearer. Thank you!