예제 #1
0
        internal IReadOnlyList<Node> ParseFragment(string inputFragment, Element context, string baseUri, ParseErrorList errors)
        {
            // context may be null
            state = HtmlTreeBuilderState.Initial;
            InitialiseParse(inputFragment, baseUri, errors);
            contextElement = context;
            fragmentParsing = true;
            Element root = null;
            if (context != null)
            {
                if (context.OwnerDocument != null)
                {
                    // quirks setup:
                    doc.QuirksMode = context.OwnerDocument.QuirksMode;
                }
                // initialise the tokeniser state:
                string contextTag = context.TagName;
                if (StringUtil.In(contextTag, "title", "textarea"))
                {
                    tokeniser.Transition(TokeniserState.Rcdata);
                }
                else if (StringUtil.In(contextTag, "iframe", "noembed", "noframes", "style", "xmp"))
                {
                    tokeniser.Transition(TokeniserState.Rawtext);
                }
                else if (contextTag.Equals("script"))
                {
                    tokeniser.Transition(TokeniserState.ScriptData);
                }
                else if (contextTag.Equals(("noscript")))
                {
                    tokeniser.Transition(TokeniserState.Data); // if scripting enabled, rawtext
                }
                else if (contextTag.Equals("plaintext"))
                {
                    tokeniser.Transition(TokeniserState.Data);
                }
                else
                {
                    tokeniser.Transition(TokeniserState.Data);
                }

                // default
                root = new Element(Tag.ValueOf("html"), baseUri);
                doc.AppendChild(root);
                stack.Push(root);
                ResetInsertionMode();
                // setup form element to nearest form on context (up ancestor chain). ensures form controls are associated
                // with form correctly
                Elements contextChain = context.Parents;
                contextChain.Insert(0, context);
                foreach (Element parent in contextChain)
                {
                    if (parent is FormElement)
                    {
                        formElement = (FormElement)parent;
                        break;
                    }
                }
            }
            RunParser();
            if (context != null)
            {
                return root.ChildNodes;
            }
            else
            {
                return doc.ChildNodes;
            }
        }
예제 #2
0
 // tag searches
 //private static final String[] TagsScriptStyle = new String[]{"script", "style"};
 // the current state
 // original / marked state
 // the current head element
 // the current form element
 // fragment parse context -- could be null even if fragment parsing
 // active (open) formatting elements
 // chars in table to be shifted out
 // if ok to go into frameset
 // if next inserts should be fostered
 // if parsing a fragment of html
 internal override Document Parse(string input, string baseUri, ParseErrorList errors)
 {
     state = HtmlTreeBuilderState.Initial;
     baseUriSetFromDoc = false;
     return base.Parse(input, baseUri, errors);
 }
예제 #3
0
 internal void Error(HtmlTreeBuilderState state)
 {
     if (errors.CanAddError)
     {
         errors.Add(new ParseError(reader.Pos(), "Unexpected token [{0}] when in state [{1}]", currentToken.Type(), state.Name()));
     }
 }
예제 #4
0
 internal void MarkInsertionMode()
 {
     originalState = state;
 }
예제 #5
0
 internal void Transition(HtmlTreeBuilderState state)
 {
     this.state = state;
 }
예제 #6
0
 internal bool Process(Token token, HtmlTreeBuilderState state)
 {
     currentToken = token;
     return state.Process(token, this);
 }