Ejemplo n.º 1
0
 public override void OuterHtmlHead(StringBuilder accum, int depth, OutputSettings output)
 {
     accum
         .Append("<")
         .Append(_isProcessingInstruction ? "!" : "?")
         .Append(GetWholeDeclaration())
         .Append(">");
 }
Ejemplo n.º 2
0
 public override void OuterHtmlHead(StringBuilder accum, int depth, OutputSettings output)
 {
     if (output.PrettyPrint())
     {
         Indent(accum, depth, output);
     }
     
     accum
         .Append("<!--")
         .Append(GetData())
         .Append("-->");
 }
Ejemplo n.º 3
0
        public override void OuterHtmlHead(StringBuilder accum, int depth, OutputSettings output)
        {
            accum.Append("<!DOCTYPE ").Append(Attr("name"));
            
            if (!StringUtil.IsBlank(Attr("publicId")))
            {
                accum.Append(" PUBLIC \"").Append(Attr("publicId")).Append("\"");
            }
            
            if (!StringUtil.IsBlank(Attr("systemId")))
            {
                accum.Append(" \"").Append(Attr("systemId")).Append("\"");
            }

            accum.Append('>');
        }
Ejemplo n.º 4
0
 public static string Escape(string s, OutputSettings output)
 {
     return(Escape(s, output.Encoding, output.EscapeMode));
 }
Ejemplo n.º 5
0
 public override void OuterHtmlTail(StringBuilder accum, int depth, OutputSettings output)
 {
 }
Ejemplo n.º 6
0
 public OuterHtmlVisitor(StringBuilder accum, OutputSettings output)
 {
     this._accum  = accum;
     this._output = output;
 }
Ejemplo n.º 7
0
 protected void Indent(StringBuilder accum, int depth, OutputSettings output)
 {
     accum.Append("\n").Append(StringUtil.Padding(depth * output.IndentAmount()));
 }
Ejemplo n.º 8
0
 public abstract void OuterHtmlTail(StringBuilder accum, int depth, OutputSettings output);
Ejemplo n.º 9
0
 public override void OuterHtmlHead(StringBuilder accum, int depth, OutputSettings output)
 {
     accum.Append(GetWholeData()); // data is not escaped in return from data nodes, so " in script, style is plain
 }
Ejemplo n.º 10
0
 public abstract void OuterHtmlTail(StringBuilder accum, int depth, OutputSettings output);
 public override void OuterHtmlHead(StringBuilder accum, int depth, OutputSettings output)
 {
     accum.Append(GetWholeData()); // data is not escaped in return from data nodes, so " in script, style is plain
 }
Ejemplo n.º 12
0
        public override void OuterHtmlHead(StringBuilder accum, int depth, OutputSettings output)
        {
            string html = Entities.Escape(GetWholeText(), output);
            if (output.PrettyPrint() && ParentNode is Element && !((Element)ParentNode).PreserveWhitespace)
            {
                html = NormaliseWhitespace(html);
            }

            if (output.PrettyPrint() && SiblingIndex == 0 && ParentNode is Element && ((Element)ParentNode).Tag.FormatAsBlock && !IsBlank)
            {
                Indent(accum, depth, output);
            }
            accum.Append(html);
        }
Ejemplo n.º 13
0
 public static string Escape(string s, OutputSettings output)
 {
     return Escape(s, output.Encoding, output.EscapeMode);
 }
Ejemplo n.º 14
0
        public object Clone()
        {
            OutputSettings clone = new OutputSettings();

            clone.SetEncoding(_encoding.WebName); // new charset and charset encoder
            clone.EscapeMode = _escapeMode;
            clone.PrettyPrint(_prettyPrint);
            clone.IndentAmount(_indentAmount);

            return clone;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Sets the document's output settings.
        /// </summary>
        /// <param name="outputSettings">New output settings</param>
        /// <returns>This document, for chaining</returns>
        public Document OutputSettings(OutputSettings outputSettings)
        {
            if (outputSettings == null)
            {
                throw new ArgumentNullException("outputSettings");
            }

            this._outputSettings = outputSettings;
            return this;
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Get safe HTML from untrusted input HTML, by parsing input HTML and filtering it through a white-list of
 /// permitted tags and attributes.
 /// </summary>
 /// <param name="bodyHtml">Input untrusted HTML (body fragment)</param>
 /// <param name="baseUri">URL to resolve relative URLs against</param>
 /// <param name="whitelist">White-list of permitted HTML elements</param>
 /// <param name="outputSettings">Document output settings; use to control pretty-printing and entity escape modes</param>
 /// <returns>Safe HTML (body fragment)</returns>
 /// <see cref="Cleaner.Clean(Document)"/>
 public static string Clean(string bodyHtml, string baseUri, Whitelist whitelist, OutputSettings outputSettings)
 {
     Document dirty = ParseBodyFragment(bodyHtml, baseUri);
     Cleaner cleaner = new Cleaner(whitelist);
     Document clean = cleaner.Clean(dirty);
     clean.OutputSettings(outputSettings);
     return clean.Body.Html();
 }
Ejemplo n.º 17
0
 protected void Indent(StringBuilder accum, int depth, OutputSettings output)
 {
     accum.Append("\n").Append(StringUtil.Padding(depth * output.IndentAmount()));
 }
Ejemplo n.º 18
0
 public OuterHtmlVisitor(StringBuilder accum, OutputSettings output)
 {
     this._accum = accum;
     this._output = output;
 }
Ejemplo n.º 19
0
 public override void OuterHtmlTail(StringBuilder accum, int depth, OutputSettings output) { }
Ejemplo n.º 20
0
        public void supplyOutputSettings()
        {
            // test that one can override the default document output settings
            OutputSettings os = new OutputSettings();
            os.PrettyPrint(false);
            os.EscapeMode = Entities.EscapeMode.Extended;

            string html = "<div><p>&bernou;</p></div>";
            string customOut = NSoupClient.Clean(html, "http://foo.com/", Whitelist.Relaxed, os);
            string defaultOut = NSoupClient.Clean(html, "http://foo.com/", Whitelist.Relaxed);
            Assert.AreNotSame(defaultOut, customOut);

            Assert.AreEqual("<div><p>&bernou;</p></div>", customOut);
            Assert.AreEqual("<div>\n" +
                " <p>ג„¬</p>\n" +
                "</div>", defaultOut);

            os.Encoding = Encoding.ASCII;
            os.EscapeMode = Entities.EscapeMode.Base;
            String customOut2 = NSoupClient.Clean(html, "http://foo.com/", Whitelist.Relaxed, os);
            Assert.AreEqual("<div><p>&#8492;</p></div>", customOut2);
        }