public override void OuterHtmlHead(StringBuilder accum, int depth, OutputSettings output) { accum .Append("<") .Append(_isProcessingInstruction ? "!" : "?") .Append(GetWholeDeclaration()) .Append(">"); }
public override void OuterHtmlHead(StringBuilder accum, int depth, OutputSettings output) { if (output.PrettyPrint()) { Indent(accum, depth, output); } accum .Append("<!--") .Append(GetData()) .Append("-->"); }
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('>'); }
public static string Escape(string s, OutputSettings output) { return(Escape(s, output.Encoding, output.EscapeMode)); }
public override void OuterHtmlTail(StringBuilder accum, int depth, OutputSettings output) { }
public OuterHtmlVisitor(StringBuilder accum, OutputSettings output) { this._accum = accum; this._output = output; }
protected void Indent(StringBuilder accum, int depth, OutputSettings output) { accum.Append("\n").Append(StringUtil.Padding(depth * output.IndentAmount())); }
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 }
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); }
public static string Escape(string s, OutputSettings output) { return Escape(s, output.Encoding, output.EscapeMode); }
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; }
/// <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; }
/// <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(); }
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>ℬ</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>ℬ</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>ℬ</p></div>", customOut2); }