Ejemplo n.º 1
0
        public void SupplyOutputSettings()
        {
            // test that one can override the default document output settings
            DocumentOutputSettings os = new DocumentOutputSettings();

            os.PrettyPrint = false;
            os.EscapeMode  = DocumentEscapeMode.Extended;
            os.Charset     = Encoding.ASCII;

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

            Assert.AreNotEqual(defaultOut, customOut);

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

            os.Charset    = Encoding.ASCII;
            os.EscapeMode = DocumentEscapeMode.Base;
            string customOut2 = Dcsoup.Clean(html, "http://foo.com/", Whitelist.Relaxed, os);

            Assert.AreEqual("<div><p>&#x212c;</p></div>", customOut2);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Set the current output syntax of the specified document settings, and returns the document settings itself.
 /// </summary>
 /// <param name="self">
 /// The input <see cref="DocumentOutputSettings"/>,
 /// which acts as the <b>this</b> instance for the extension method.
 /// </param>
 /// <param name="syntax">the new syntax to use</param>
 /// <returns>The input <see cref="DocumentOutputSettings"/>, for method chaining.</returns>
 /// <seealso cref="DocumentOutputSettings.Syntax">DocumentOutputSettings.Syntax</seealso>
 public static DocumentOutputSettings Syntax(this DocumentOutputSettings self, DocumentSyntax syntax)
 {
     self.Syntax = syntax;
     return self;
 }
Ejemplo n.º 3
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>
        /// <seealso cref="Supremes.Safety.Cleaner.Clean(Supremes.Nodes.Document)">Supremes.Safety.Cleaner.Clean(Supremes.Nodes.Document)</seealso>
        public static string Clean(string bodyHtml, string baseUri, Whitelist whitelist, DocumentOutputSettings 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.º 4
0
 /// <summary>
 /// Set the current output charset of the specified document settings, and returns the document settings itself.
 /// </summary>
 /// <param name="self">
 /// The input <see cref="DocumentOutputSettings"/>,
 /// which acts as the <b>this</b> instance for the extension method.
 /// </param>
 /// <param name="charset">the new charset to use</param>
 /// <returns>The input <see cref="DocumentOutputSettings"/>, for method chaining.</returns>
 /// <seealso cref="DocumentOutputSettings.Charset">DocumentOutputSettings.Charset</seealso>
 public static DocumentOutputSettings Charset(this DocumentOutputSettings self, Encoding charset)
 {
     self.Charset = charset;
     return self;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Set the current output charset of the specified document settings, and returns the document settings itself.
 /// </summary>
 /// <param name="self">
 /// The input <see cref="DocumentOutputSettings"/>,
 /// which acts as the <b>this</b> instance for the extension method.
 /// </param>
 /// <param name="charset">the new charset name to use</param>
 /// <returns>The input <see cref="DocumentOutputSettings"/>, for method chaining.</returns>
 /// <seealso cref="DocumentOutputSettings.Charset">DocumentOutputSettings.Charset</seealso>
 public static DocumentOutputSettings Charset(this DocumentOutputSettings self, String charset)
 {
     self.Charset = Encoding.GetEncoding(charset);
     return self;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Set the current HTML escape mode of the specified document settings, and returns the document settings itself.
 /// </summary>
 /// <param name="self">
 /// The input <see cref="DocumentOutputSettings"/>,
 /// which acts as the <b>this</b> instance for the extension method.
 /// </param>
 /// <param name="escapeMode">the new escape mode to use</param>
 /// <returns>The input <see cref="DocumentOutputSettings"/>, for method chaining.</returns>
 /// <seealso cref="DocumentOutputSettings.EscapeMode">DocumentOutputSettings.EscapeMode</seealso>
 public static DocumentOutputSettings EscapeMode(this DocumentOutputSettings self, DocumentEscapeMode escapeMode)
 {
     self.EscapeMode = escapeMode;
     return self;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Set the specified document's current output settings, and returns the document itself.
 /// </summary>
 /// <param name="self">
 /// The input <see cref="Document"/>,
 /// which acts as the <b>this</b> instance for the extension method.
 /// </param>
 /// <param name="outputSettings">new output settings</param>
 /// <returns>The input <see cref="Document"/>, for method chaining.</returns>
 /// <seealso cref="Document.OutputSettings">Document.OutputSettings</seealso>
 public static Document OutputSettings(this Document self, DocumentOutputSettings outputSettings)
 {
     self.OutputSettings = outputSettings;
     return self;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Set the current tag indent amount of the specified document settings, used when pretty printing, and returns the document settings itself.
 /// </summary>
 /// <param name="self">
 /// The input <see cref="DocumentOutputSettings"/>,
 /// which acts as the <b>this</b> instance for the extension method.
 /// </param>
 /// <param name="indentAmount">number of spaces to use for indenting each level</param>
 /// <returns>The input <see cref="DocumentOutputSettings"/>, for method chaining.</returns>
 /// <seealso cref="DocumentOutputSettings.IndentAmount">DocumentOutputSettings.IndentAmount</seealso>
 public static DocumentOutputSettings IndentAmount(this DocumentOutputSettings self, int indentAmount)
 {
     self.IndentAmount = indentAmount;
     return self;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Set if outline mode is enabled to the specified document settings, and returns the document settings itself.
 /// </summary>
 /// <param name="self">
 /// The input <see cref="DocumentOutputSettings"/>,
 /// which acts as the <b>this</b> instance for the extension method.
 /// </param>
 /// <param name="outlineMode">the new outline mode</param>
 /// <returns>The input <see cref="DocumentOutputSettings"/>, for method chaining.</returns>
 /// <seealso cref="DocumentOutputSettings.Outline">DocumentOutputSettings.Outline</seealso>
 public static DocumentOutputSettings Outline(this DocumentOutputSettings self, bool outlineMode)
 {
     self.Outline = outlineMode;
     return self;
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Set if pretty printing is enabled to the specified document settings, and returns the document settings itself.
 /// </summary>
 /// <param name="self">
 /// The input <see cref="DocumentOutputSettings"/>,
 /// which acts as the <b>this</b> instance for the extension method.
 /// </param>
 /// <param name="pretty">the new pretty print setting</param>
 /// <returns>The input <see cref="DocumentOutputSettings"/>, for method chaining.</returns>
 /// <seealso cref="DocumentOutputSettings.PrettyPrint">DocumentOutputSettings.PrettyPrint</seealso>
 public static DocumentOutputSettings PrettyPrint(this DocumentOutputSettings self, bool pretty)
 {
     self.PrettyPrint = pretty;
     return self;
 }