当前位置: 首页>>代码示例>>C#>>正文


C# HtmlTag.CreateCloseTag方法代码示例

本文整理汇总了C#中HtmlTag.CreateCloseTag方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlTag.CreateCloseTag方法的具体用法?C# HtmlTag.CreateCloseTag怎么用?C# HtmlTag.CreateCloseTag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HtmlTag的用法示例。


在下文中一共展示了HtmlTag.CreateCloseTag方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FilterLiteral

        /// <summary>
        /// Optionally finds any URLs and wraps them with a hyperlink
        /// </summary>
        /// <param name="source">original string</param>
        /// <param name="start">starting index inclusive</param>
        /// <param name="end">ending index exclusive</param>
        /// <param name="replacement">a replacement string</param>
        /// <returns>true if <paramref name="replacement"/> should be used to replace literal</returns>
        public override bool FilterLiteral(string source, int start, int end, out string replacement)
        {
            if (!this.AutoLink || source == null)
            {
                return base.FilterLiteral(source, start, end, out replacement);
            }

            int index,			// the start index of the match
                length,			// the length of the match
                last = start;	// the last index written out

            bool foundUrl = false;
            while (this.DetectUrl(source, last, end, out index, out length))
            {
                if (this.HtmlWriter == null)
                {
                    throw new NullReferenceException("HtmlWriter was never set on the HtmlFilter.");
                }

                foundUrl = true;

                // append next unmatched substring
                if (base.FilterLiteral(source, last, index, out replacement))
                {
                    // use the word broken replacement text
                    this.HtmlWriter.WriteLiteral(replacement);
                }
                else
                {
                    this.HtmlWriter.WriteLiteral(source.Substring(last, index-last));
                }

                bool replace;
                if (source.IndexOf("://", index, length) < 0)
                {
                    replace = true;
                    string plusScheme = "http://"+source.Substring(index, length);
                    if (!this.FilterUrl(plusScheme, 0, plusScheme.Length, out replacement))
                    {
                        replacement = plusScheme;
                    }
                }
                else
                {
                    replace = this.FilterUrl(source, index, index+length, out replacement);
                }

                if (replace && String.IsNullOrEmpty(replacement))
                {
                    // filter URL isn't allowing this to be linked as a URL
                    if (base.FilterLiteral(source, index, index+length, out replacement))
                    {
                        this.HtmlWriter.WriteLiteral(replacement);
                    }
                    else
                    {
                        this.HtmlWriter.WriteLiteral(source.Substring(index, length));
                    }
                }
                else
                {
                    // wrap the match in a hyperlink
                    HtmlTag link = new HtmlTag(LinkTagName, this);
                    if (replace)
                    {
                        // allow additional filtering on the safety of the URL
                        link.Attributes[LinkAttrib] = replacement;
                    }
                    else
                    {
                        link.Attributes[LinkAttrib] = source.Substring(index, length);
                    }
                    this.HtmlWriter.WriteTag(link);

                    if (base.FilterLiteral(source, index, index+length, out replacement))
                    {
                        this.HtmlWriter.WriteLiteral(replacement);
                    }
                    else
                    {
                        this.HtmlWriter.WriteLiteral(source.Substring(index, length));
                    }
                    this.HtmlWriter.WriteTag(link.CreateCloseTag());
                }

                // continue searching from the end of the match
                last = index+length;
            }

            if (!foundUrl)
            {
                // no matches were found, defer to base implementation
//.........这里部分代码省略.........
开发者ID:pocket-playlab,项目名称:jsonfx-v1,代码行数:101,代码来源:HtmlFilter.cs


注:本文中的HtmlTag.CreateCloseTag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。