public virtual void Parse(Lexer lexer, Node table, short mode) { Node node, parent; int istackbase; TagTable tt = lexer.Options.tt; lexer.DeferDup(); istackbase = lexer.istackbase; lexer.istackbase = lexer.istack.Count; while (true) { node = lexer.GetToken(Lexer.IgnoreWhitespace); if (node == null) break; if (node.Tag == table.Tag && node.Type == Node.EndTag) { lexer.istackbase = istackbase; table.Closed = true; Node.TrimEmptyElement(lexer, table); return; } /* deal with comments etc. */ if (Node.InsertMisc(table, node)) continue; /* discard unknown tags */ if (node.Tag == null && node.Type != Node.TextNode) { Report.Warning(lexer, table, node, Report.DISCARDING_UNEXPECTED); continue; } /* if TD or TH or text or inline or block then infer <TR> */ if (node.Type != Node.EndTag) { if (node.Tag == tt.TagTd || node.Tag == tt.TagTh || node.Tag == tt.tagTable) { lexer.UngetToken(); node = lexer.InferredTag("tr"); Report.Warning(lexer, table, node, Report.MISSING_STARTTAG); } else if (node.Type == Node.TextNode || (node.Tag.Model & (ContentModel.Block | ContentModel.Inline)) != 0) { Node.InsertNodeBeforeElement(table, node); Report.Warning(lexer, table, node, Report.TAG_NOT_ALLOWED_IN); lexer.exiled = true; /* AQ: TODO Line 2040 of parser.c (13 Jan 2000) reads as follows: if (!node->type == TextNode) This will always evaluate to false. This has been reported to Dave Raggett <*****@*****.**> */ //Should be?: if (!(node.Type == Node.TextNode)) // if (false) // TidyNet.ParserImpl.parseTag(lexer, node, Lexer.IgnoreWhitespace); lexer.exiled = false; continue; } else if ((node.Tag.Model & ContentModel.Head) != 0) { TidyNet.ParserImpl.moveToHead(lexer, table, node); continue; } } /* if this is the end tag for an ancestor element then infer end tag for this element */ if (node.Type == Node.EndTag) { if (node.Tag == tt.TagForm) { lexer.badForm = 1; Report.Warning(lexer, table, node, Report.DISCARDING_UNEXPECTED); continue; } if (node.Tag != null && (node.Tag.Model & (ContentModel.Table | ContentModel.Row)) != 0) { Report.Warning(lexer, table, node, Report.DISCARDING_UNEXPECTED); continue; } for (parent = table.Parent; parent != null; parent = parent.Parent) { if (node.Tag == parent.Tag) { Report.Warning(lexer, table, node, Report.MISSING_ENDTAG_BEFORE); lexer.UngetToken(); lexer.istackbase = istackbase; Node.TrimEmptyElement(lexer, table); return; } } } if (!((node.Tag.Model & ContentModel.Table) != 0)) { lexer.UngetToken(); Report.Warning(lexer, table, node, Report.TAG_NOT_ALLOWED_IN); lexer.istackbase = istackbase; Node.TrimEmptyElement(lexer, table); return; } if (node.Type == Node.StartTag || node.Type == Node.StartEndTag) { Node.InsertNodeAtEnd(table, node); ; TidyNet.ParserImpl.parseTag(lexer, node, Lexer.IgnoreWhitespace); continue; } /* discard unexpected text nodes and end tags */ Report.Warning(lexer, table, node, Report.DISCARDING_UNEXPECTED); } Report.Warning(lexer, table, node, Report.MISSING_ENDTAG_FOR); Node.TrimEmptyElement(lexer, table); lexer.istackbase = istackbase; }