public static IRuleAppender RegularContent(this IRuleAppender appender) { return(appender.Treat(e => e.Elements("i", "b", "u", "em", "strong", "acronym", "h1", "h2", "h3", "h4", "h5", "h6") .As(AllowFlags | HtmlElementOptions.Text | HtmlElementOptions.UseTypography)) .Treat(e => e.Element("p").As(AllowFlags | HtmlElementOptions.AllowContent | HtmlElementOptions.UseTypography) .Treat(a => a.Attribute("align").Validate("left", "right", "center"))) .Treat(e => e.Element("nobr").As(AllowFlags | HtmlElementOptions.Text | HtmlElementOptions.UseTypography)) .Treat(e => e.Element("ul").As(AllowFlags | HtmlElementOptions.Container) .Treat(l => l.Element("li").As(HtmlElementOptions.Allowed | HtmlElementOptions.Text | HtmlElementOptions.UseTypography))) .Treat(e => e.Elements("code", "pre").As(AllowFlags | HtmlElementOptions.Preformatted)) .Treat(e => e.Element("br").As(AllowFlags | HtmlElementOptions.SelfClosing)) .Treat(e => e.Elements("script", "iframe").As(HtmlElementOptions.Denied | HtmlElementOptions.Global))); }
public static IRuleAppender Abstract(this IRuleAppender appender) { return(appender.Treat(e => e.Element("cut").As(AllowFlags | HtmlElementOptions.SelfClosing) .Convert((context, element) => { XmlElement link = element.OwnerDocument.CreateElement("a"); string url = context.Parameters.GetValue <string>("url", String.Empty); link.SetAttribute("href", url); link.AppendText(String.Format("{0} →", element.GetAttribute("title").Define(s => !String.IsNullOrEmpty(s), "читать далее") )); return link; }))); }
public static IRuleAppender Links(this IRuleAppender appender) { return(appender.Treat(e => e.Element("a") .As(AllowFlags | HtmlElementOptions.Text) .Convert((context, element) => { if (element.InnerText.StartsWith("http://", StringComparison.OrdinalIgnoreCase) && element.InnerText.Length > 30) { element.SetAttribute("title", element.InnerText); element.InnerText = element.InnerText.Substring(0, 30) + "…"; } return context.CrossDomainLink(element); }) .Treat(a => a.Attribute("href").Validate("#url")) .Treat(a => a.Attributes("rel", "target")) .Treat(a => a.Attribute("title")))); }
public static IRuleAppender Images(this IRuleAppender appender) { return(appender.Treat(e => e.Element("img") .As(AllowFlags | HtmlElementOptions.SelfClosing) .Convert((context, element) => { if (element.HasAttribute("alt")) { element.SetAttribute("title", element.GetAttribute("alt")); } return element; }) .Treat(a => a.Attribute("src").Validate("#url")) .Treat(a => a.Attribute("width").Validate("#int")) .Treat(a => a.Attribute("height").Validate("#int")) .Treat(a => a.Attribute("title")))); }
public static IRuleAppender Youtube(this IRuleAppender appender) { return(appender.Treat(e => e.Elements("object").As(InternalFlags | HtmlElementOptions.Container) .Treat(p => p.Element("param").As(HtmlElementOptions.Allowed | HtmlElementOptions.SelfClosing) .Treat(a => a.Attributes("name", "value").As(HtmlAttributeOptions.Allowed | HtmlAttributeOptions.Required)) ) .Treat(i => i.Element("embed").As(HtmlElementOptions.Allowed | HtmlElementOptions.SelfClosing)) .Treat(a => a.Attributes("classid", "name").As(HtmlAttributeOptions.Allowed)) .Treat(a => a.Attributes("width", "height").As(HtmlAttributeOptions.Allowed).Validate("#int"))) .Treat(e => e.Element("youtube").As(AllowFlags | HtmlElementOptions.SelfClosing) .Convert((context, element) => { string location = element.GetAttribute("src"); if (String.IsNullOrEmpty(location)) { return null; } return context.FlashPlayer(element, location, 640, 360, ""); }))); }