Esempio n. 1
0
 internal virtual IList <iText.StyledXmlParser.Jsoup.Nodes.Node> ParseFragment(String inputFragment, iText.StyledXmlParser.Jsoup.Nodes.Element
                                                                               context, String baseUri, ParseErrorList errors)
 {
     // context may be null
     state = HtmlTreeBuilderState.Initial;
     InitialiseParse(inputFragment, baseUri, errors);
     contextElement  = context;
     fragmentParsing = true;
     iText.StyledXmlParser.Jsoup.Nodes.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 (iText.StyledXmlParser.Jsoup.Helper.StringUtil.In(contextTag, "title", "textarea"))
         {
             tokeniser.Transition(TokeniserState.Rcdata);
         }
         else
         {
             if (iText.StyledXmlParser.Jsoup.Helper.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);
                     }
                     else
                     {
                         // if scripting enabled, rawtext
                         if (contextTag.Equals("plaintext"))
                         {
                             tokeniser.Transition(TokeniserState.Data);
                         }
                         else
                         {
                             tokeniser.Transition(TokeniserState.Data);
                         }
                     }
                 }
             }
         }
         // default
         root = new iText.StyledXmlParser.Jsoup.Nodes.Element(iText.StyledXmlParser.Jsoup.Parser.Tag.ValueOf("html"
                                                                                                             ), baseUri);
         doc.AppendChild(root);
         stack.Add(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.Add(0, context);
         foreach (iText.StyledXmlParser.Jsoup.Nodes.Element parent in contextChain)
         {
             if (parent is FormElement)
             {
                 formElement = (FormElement)parent;
                 break;
             }
         }
     }
     RunParser();
     if (context != null && root != null)
     {
         return(root.ChildNodes());
     }
     else
     {
         return(doc.ChildNodes());
     }
 }
Esempio n. 2
0
 internal virtual bool IsInActiveFormattingElements(iText.StyledXmlParser.Jsoup.Nodes.Element el)
 {
     return(IsElementInQueue(formattingElements, el));
 }
Esempio n. 3
0
 internal virtual void ReplaceActiveFormattingElement(iText.StyledXmlParser.Jsoup.Nodes.Element @out, iText.StyledXmlParser.Jsoup.Nodes.Element
                                                      @in)
 {
     ReplaceInQueue(formattingElements, @out, @in);
 }
Esempio n. 4
0
        /// <summary>Parse a fragment of HTML into a list of nodes.</summary>
        /// <remarks>Parse a fragment of HTML into a list of nodes. The context element, if supplied, supplies parsing context.
        ///     </remarks>
        /// <param name="fragmentHtml">the fragment of HTML to parse</param>
        /// <param name="context">
        /// (optional) the element that this HTML fragment is being parsed for (i.e. for inner HTML). This
        /// provides stack context (for implicit element creation).
        /// </param>
        /// <param name="baseUri">base URI of document (i.e. original fetch location), for resolving relative URLs.</param>
        /// <returns>list of nodes parsed from the input HTML. Note that the context element, if supplied, is not modified.
        ///     </returns>
        public static IList <iText.StyledXmlParser.Jsoup.Nodes.Node> ParseFragment(String fragmentHtml, iText.StyledXmlParser.Jsoup.Nodes.Element
                                                                                   context, String baseUri)
        {
            HtmlTreeBuilder treeBuilder = new HtmlTreeBuilder();

            return(treeBuilder.ParseFragment(fragmentHtml, context, baseUri, ParseErrorList.NoTracking()));
        }