Esempio n. 1
0
 // attr html starts with a " "
 /// <exception cref="System.IO.IOException"/>
 internal override void OuterHtmlHead(StringBuilder accum, int depth, OutputSettings @out)
 {
     accum.Append("<").Append(isProcessingInstruction ? "!" : "?").Append(name);
     attributes.Html(accum, @out);
     accum.Append(isProcessingInstruction ? "!" : "?").Append(">");
 }
Esempio n. 2
0
 internal override void OuterHtmlTail(StringBuilder accum, int depth, OutputSettings @out)
 {
 }
Esempio n. 3
0
 internal OuterHtmlVisitor(StringBuilder accum, OutputSettings @out)
 {
     this.accum = accum;
     this.@out  = @out;
 }
Esempio n. 4
0
 /// <summary>Collapsible if it's a boolean attribute and value is empty or same as name</summary>
 /// <param name="out">Outputsettings</param>
 /// <returns>Returns whether collapsible or not</returns>
 protected internal bool ShouldCollapseAttribute(OutputSettings @out)
 {
     return(("".Equals(value) || value.EqualsIgnoreCase(key)) && @out.Syntax() == Syntax.html && IsBooleanAttribute
                ());
 }
Esempio n. 5
0
 protected internal virtual void Indent(StringBuilder accum, int depth, OutputSettings @out)
 {
     accum.Append("\n").Append(iText.StyledXmlParser.Jsoup.Helper.StringUtil.Padding(depth * @out.IndentAmount(
                                                                                         )));
 }
Esempio n. 6
0
 internal abstract void OuterHtmlTail(StringBuilder accum, int depth, OutputSettings @out);
Esempio n. 7
0
        // this method is ugly, and does a lot. but other breakups cause rescanning and stringbuilder generations
        /// <exception cref="System.IO.IOException"/>
        internal static void Escape(StringBuilder accum, String str, OutputSettings outputSettings, bool inAttribute
                                    , bool normaliseWhite, bool stripLeadingWhite)
        {
            bool lastWasWhite    = false;
            bool reachedNonWhite = false;

            Entities.EscapeMode escapeMode = outputSettings.EscapeMode();
            Encoding            encoder    = outputSettings.Charset();

            Entities.CoreCharset       coreCharset = GetCoreCharsetByName(outputSettings.Charset().Name());
            IDictionary <char, String> map         = escapeMode.GetMap();
            int length = str.Length;
            int codePoint;

            for (int offset = 0; offset < length; offset += iText.IO.Util.TextUtil.CharCount(codePoint))
            {
                codePoint = str.CodePointAt(offset);
                if (normaliseWhite)
                {
                    if (iText.StyledXmlParser.Jsoup.Helper.StringUtil.IsWhitespace(codePoint))
                    {
                        if ((stripLeadingWhite && !reachedNonWhite) || lastWasWhite)
                        {
                            continue;
                        }
                        accum.Append(' ');
                        lastWasWhite = true;
                        continue;
                    }
                    else
                    {
                        lastWasWhite    = false;
                        reachedNonWhite = true;
                    }
                }
                // surrogate pairs, split implementation for efficiency on single char common case (saves creating strings, char[]):
                if (codePoint < iText.IO.Util.TextUtil.CHARACTER_MIN_SUPPLEMENTARY_CODE_POINT)
                {
                    char c = (char)codePoint;
                    switch (c)
                    {
                    case '&': {
                        // html specific and required escapes:
                        accum.Append("&amp;");
                        break;
                    }

                    case (char)0xA0: {
                        if (escapeMode != Entities.EscapeMode.xhtml)
                        {
                            accum.Append("&nbsp;");
                        }
                        else
                        {
                            accum.Append("&#xa0;");
                        }
                        break;
                    }

                    case '<': {
                        // escape when in character data or when in a xml attribue val; not needed in html attr val
                        if (!inAttribute || escapeMode == Entities.EscapeMode.xhtml)
                        {
                            accum.Append("&lt;");
                        }
                        else
                        {
                            accum.Append(c);
                        }
                        break;
                    }

                    case '>': {
                        if (!inAttribute)
                        {
                            accum.Append("&gt;");
                        }
                        else
                        {
                            accum.Append(c);
                        }
                        break;
                    }

                    case '"': {
                        if (inAttribute)
                        {
                            accum.Append("&quot;");
                        }
                        else
                        {
                            accum.Append(c);
                        }
                        break;
                    }

                    default: {
                        if (CanEncode(coreCharset, c, encoder))
                        {
                            accum.Append(c);
                        }
                        else
                        {
                            if (map.ContainsKey(c))
                            {
                                accum.Append('&').Append(map.Get(c)).Append(';');
                            }
                            else
                            {
                                accum.Append("&#x").Append(JavaUtil.IntegerToHexString(codePoint)).Append(';');
                            }
                        }
                        break;
                    }
                    }
                }
                else
                {
                    String c = new String(iText.IO.Util.TextUtil.ToChars(codePoint));
                    if (encoder.CanEncode(c))
                    {
                        // uses fallback encoder for simplicity
                        accum.Append(c);
                    }
                    else
                    {
                        accum.Append("&#x").Append(JavaUtil.IntegerToHexString(codePoint)).Append(';');
                    }
                }
            }
        }
Esempio n. 8
0
 /// <summary>Set the document's output settings.</summary>
 /// <param name="outputSettings">new output settings.</param>
 /// <returns>this document, for chaining.</returns>
 public virtual Document OutputSettings(OutputSettings outputSettings)
 {
     Validate.NotNull(outputSettings);
     this.outputSettings = outputSettings;
     return(this);
 }
Esempio n. 9
0
 internal override void OuterHtmlHead(StringBuilder accum, int depth, OutputSettings @out)
 {
     accum.Append(GetWholeData());
 }