Esempio n. 1
0
        /// <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;
            }
        }
Esempio n. 2
0
 /// <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));
 }
Esempio n. 3
0
        /// <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;
            }
        }
Esempio n. 4
0
        /// <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();
        }
Esempio n. 5
0
 /// <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);
 }
Esempio n. 6
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;
 }
Esempio n. 7
0
 /// <summary>引发 Rendered 事件</summary>
 protected virtual void OnRendered( HtmlRequestContext context, IHtmlFilter[] filters )
 {
   foreach ( var filter in filters.Reverse() )
   {
     try
     {
       filter.OnRendered( context );
     }
     catch { }
   }
 }
Esempio n. 8
0
 /// <summary>引发 Processing 事件</summary>
 protected virtual void OnProcessing( HtmlRequestContext context, IHtmlFilter[] filters )
 {
   foreach ( var filter in filters )
   {
     try
     {
       filter.OnProcessing( context );
     }
     catch { }
   }
 }