本文整理汇总了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
//.........这里部分代码省略.........