/// <summary> /// Ctor. /// </summary> /// <param name="name"></param> public HtmlTag(string name, IHtmlFilter filter) { this.filter = filter; if (name == null) { name = String.Empty; } this.rawName = name.Trim(); if (this.rawName.StartsWith("!") || this.rawName.StartsWith("?") || this.rawName.StartsWith("%")) { this.tagType = HtmlTagType.Unparsed; } else if (this.rawName.StartsWith("/")) { this.tagType = HtmlTagType.EndTag; this.rawName = this.rawName.Substring(1); } else if (HtmlTag.FullTagRequired(this.TagName)) // this.TagName is lowercase { this.tagType = HtmlTagType.FullTag; } else { this.tagType = HtmlTagType.BeginTag; } }
/// <summary> /// 实例化一个富文本对象 /// </summary> /// <param name="source">未被过滤的源文本</param> /// <param name="htmlFilter">html过滤器</param> public RichText(string source, IHtmlFilter htmlFilter) { this.source = source; this.htmlFilter = htmlFilter ?? throw new ArgumentNullException(nameof(htmlFilter)); }
/// <summary> /// Quick parsing utility for common usage. /// </summary> /// <param name="html">the source text</param> /// <param name="filter">a custom HtmlFilter</param> /// <param name="maxLength">the maximum text length</param> /// <returns>the filtered markup</returns> public static string Parse(string html, IHtmlFilter filter, int maxLength) { StringWriter writer = new StringWriter(); HtmlDistiller parser = new HtmlDistiller(maxLength, filter); parser.HtmlWriter = new HtmlWriter(writer); parser.Parse(html); return writer.ToString(); }
/// <summary> /// Quick parsing utility for common usage. /// </summary> /// <param name="html">the source text</param> /// <param name="filter">a custom HtmlFilter</param> /// <returns>the filtered markup</returns> public static string Parse(string html, IHtmlFilter filter) { return HtmlDistiller.Parse(html, filter, 0); }
/// <summary> /// Ctor /// </summary> /// <param name="text">the text to parse</param> /// <param name="filter"></param> public HtmlDistiller(int maxLength, IHtmlFilter filter) { this.maxLength = maxLength; this.htmlFilter = filter; }
/// <summary>引发 Rendered 事件</summary> protected virtual void OnRendered( HtmlRequestContext context, IHtmlFilter[] filters ) { foreach ( var filter in filters.Reverse() ) { try { filter.OnRendered( context ); } catch { } } }
/// <summary>引发 Processing 事件</summary> protected virtual void OnProcessing( HtmlRequestContext context, IHtmlFilter[] filters ) { foreach ( var filter in filters ) { try { filter.OnProcessing( context ); } catch { } } }