/// <summary> /// Initializes a new instance of the <see cref="HtmlWriterToText"/> class. /// </summary> /// <param name="writer">The writer.</param> /// <param name="options">The options.</param> /// <exception cref="System.ArgumentNullException">if writer is null</exception> public HtmlWriterToText(TextWriter writer, HtmlToTextOptions options) { if (writer == null) { throw new ArgumentNullException(nameof(writer)); } Writer = writer; this.options = options; }
/// <summary> /// Extract the text from a HTML string. /// </summary> /// <param name="source">The source HTML</param> /// <param name="options">The options to extract the text.</param> /// <param name="sourceFileName">The source file name used when reporting errors. Default is <c>null</c></param> /// <returns>The text extracted from this HTML string</returns> public static UglifyResult HtmlToText(string source, HtmlToTextOptions options = HtmlToTextOptions.None, string sourceFileName = null) { // Use specific settings to extract text from html var settings = new HtmlSettings { RemoveOptionalTags = false, RemoveEmptyAttributes = false, RemoveAttributeQuotes = false, DecodeEntityCharacters = true, RemoveScriptStyleTypeAttribute = false, ShortBooleanAttribute = false, MinifyJs = false, MinifyJsAttributes = false, MinifyCss = false, MinifyCssAttributes = false }; var parser = new HtmlParser(source, sourceFileName, settings); var document = parser.Parse(); string text = null; var errors = new List <UglifyError>(parser.Errors); if (document != null) { var minifier = new HtmlMinifier(document, settings); minifier.Minify(); errors.AddRange(minifier.Errors); var writer = new StringWriter(); var htmlWriter = new HtmlWriterToText(writer, options); htmlWriter.Write(document); text = writer.ToString(); } return(new UglifyResult(text, errors)); }
public HtmlWriterToSummary(TextWriter writer, HtmlToTextOptions options) : base(writer, options) { }