using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.ComponentModel;
namespace NearForums
{
public static class Utils
{
public static bool IsHtmlFragment(string value)
{
return Regex.IsMatch(value, @"?(p|div)>");
}
///
/// Remove tags from a html string
///
///
///
public static string RemoveTags(string value)
{
if (value != null)
{
value = CleanHtmlComments(value);
value = CleanHtmlBehaviour(value);
value = Regex.Replace(value, @"[^>]+?>", " ");
value = Regex.Replace(value, @"<[^>]+?>", "");
value = value.Trim();
}
return value;
}
///
/// Clean script and styles html tags and content
///
///
public static string CleanHtmlBehaviour(string value)
{
value = Regex.Replace(value, "()|()", "", RegexOptions.IgnoreCase | RegexOptions.Singleline);
return value;
}
///
/// Replace the html commens (also html ifs of msword).
///
public static string CleanHtmlComments(string value)
{
//Remove disallowed html tags.
value = Regex.Replace(value, "", "", RegexOptions.IgnoreCase | RegexOptions.Singleline);
return value;
}
///
/// Adds rel=nofollow to html anchors
///
public static string HtmlLinkAddNoFollow(string value)
{
return Regex.Replace(value, "]+href=\"?'?(?!#[\\w-]+)([^'\">]+)\"?'?[^>]*>(.*?)", "$2", RegexOptions.IgnoreCase | RegexOptions.Compiled);
}
}
}