Esempio n. 1
0
 /// <summary>
 /// Convert parsed HTML to plain text
 /// </summary>
 /// <param name="reader">A stream of <see cref="HtmlNode"/></param>
 /// <param name="settings">Settings controlling how the plain text is rendered</param>
 /// <returns>A plain text representation of the HTML</returns>
 public static string ToPlainText(this IEnumerable <HtmlNode> reader, TextWriterSettings settings = null)
 {
     using (var sw = new StringWriter())
     {
         ToPlainText(reader, sw, settings);
         return(sw.ToString());
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Convert parsed HTML to plain text
        /// </summary>
        /// <param name="html">The HTML content to minify. A <see cref="string"/> or <see cref="Stream"/> can also be used.</param>
        /// <param name="settings">Settings controlling how the plain text is rendered</param>
        /// <returns>A plain text representation of the HTML</returns>
        public static string ToPlainText(TextSource html, TextWriterSettings settings = null)
        {
            var sb = Pool.NewStringBuilder();

            sb.EnsureCapacity(html.Length);
            using (var sw = new StringWriter(sb))
                using (var reader = new HtmlReader(html, false))
                {
                    reader.ToPlainText(sw, settings);
                    sw.Flush();
                    return(sb.ToPool());
                }
        }
Esempio n. 3
0
 /// <summary>
 /// Convert parsed HTML to plain text
 /// </summary>
 /// <param name="reader">A stream of <see cref="HtmlNode"/></param>
 /// <param name="writer">Writer to which the plain text is written</param>
 /// <param name="settings">Settings controlling how the plain text is rendered</param>
 public static void ToPlainText(this IEnumerable <HtmlNode> reader, TextWriter writer, TextWriterSettings settings = null)
 {
     using (var w = new PlainTextWriter(writer, settings))
     {
         ToHtml(reader, w);
         w.Flush();
     }
 }
 public PlainTextWriter(TextWriter writer, TextWriterSettings settings)
 {
     _writer   = writer;
     _settings = settings ?? new TextWriterSettings();
 }