namespace Textile; /// /// A utility class for global things used by the TextileFormatter. /// static class Globals { #region Global Regex Patterns public const string HorizontalAlignPattern = @"(?:[()]*(\<(?!>)|(?|\<\>|=)[()]*)"; public const string VerticalAlignPattern = @"[\-^~]"; public const string CssClassPattern = @"(?:\([^)]+\))"; public const string LanguagePattern = @"(?:\[[^]]+\])"; public const string CssStylePattern = @"(?:\{[^}]+\})"; public const string ColumnSpanPattern = @"(?:\\\d+)"; public const string RowSpanPattern = @"(?:/\d+)"; public const string AlignPattern = "(?" + HorizontalAlignPattern + "?" + VerticalAlignPattern + "?|" + VerticalAlignPattern + "?" + HorizontalAlignPattern + "?)"; public const string SpanPattern = @"(?" + ColumnSpanPattern + "?" + RowSpanPattern + "?|" + RowSpanPattern + "?" + ColumnSpanPattern + "?)"; public const string BlockModifiersPattern = @"(?" + CssClassPattern + "?" + CssStylePattern + "?" + LanguagePattern + "?|" + CssStylePattern + "?" + LanguagePattern + "?" + CssClassPattern + "?|" + LanguagePattern + "?" + CssStylePattern + "?" + CssClassPattern + "?)"; public const string PunctuationPattern = @"[\!""#\$%&'()\*\+,\-\./:;<=>\?@\[\\\]\^_`{}~]"; public const string HtmlAttributesPattern = @"(\s+\w+=((""[^""]+"")|('[^']+')))*"; #endregion /// /// Image alignment tags, mapped to their HTML meanings. /// public static Dictionary ImageAlign { get; set; } /// /// Horizontal text alignment tags, mapped to their HTML meanings. /// public static Dictionary HorizontalAlign { get; set; } /// /// Vertical text alignment tags, mapped to their HTML meanings. /// public static Dictionary VerticalAlign { get; set;} static Globals() { ImageAlign = new Dictionary { ["<"] = "left", ["="] = "center", [">"] = "right" }; HorizontalAlign = new Dictionary { ["<"] = "left", ["="] = "center", [">"] = "right", ["<>"] = "justify" }; VerticalAlign = new Dictionary { ["^"] = "top", ["-"] = "middle", ["~"] = "bottom" }; } public static string EncodeHTMLLink(string url) { url = url.Replace("&", "&"); url = System.Text.RegularExpressions.Regex.Replace(url, "&(?=[^#])", "&"); return url; } }