public static void Init(string Tag, string HTML, string HTMLClosure, bool AcceptParameters = false, bool TopMost = false, Func<BBCodeTag, BBTreeNode, string> Parser = null, bool SupressChildren = false, bool AllowNesting = false) { BBCodeTag New = new BBCodeTag() { Tag = Tag, HTML = HTML, HTMLClosure = HTMLClosure, AcceptParameters = AcceptParameters, Parser = Parser ?? HTMLEncodeTagParser, TopMost = TopMost, SupressChildren = SupressChildren, AllowNesting = AllowNesting }; BBDict.Add(New.Tag.ToLowerInvariant(), New); }
public BBTreeNode(string Data, BBCodeTag TagType) { Children = new List<BBTreeNode>(); this.Data = Data; this.TagType = TagType; }
static string UrlEncodeTagParser(BBCodeTag ToEncode, BBTreeNode NodeToParse) { string URL = NodeToParse.Data; if (String.IsNullOrEmpty(URL) && NodeToParse.Children.Count > 0) { URL = NodeToParse.Children[0].Data; } Regex Reg = new Regex(URLProtocolRegex); if (!Reg.IsMatch(URL, 0)) { URL = "http://" + URL; } return String.Format(ToEncode.HTML, HttpUtility.HtmlAttributeEncode(HttpUtility.UrlPathEncode(URL))); }
static string UrlEncodePartParser(BBCodeTag ToEncode, BBTreeNode NodeToParse) { string URL = NodeToParse.Data; if (String.IsNullOrEmpty(URL) && NodeToParse.Children.Count > 0) URL = NodeToParse.Children[0].Data; return String.Format(ToEncode.HTML, HttpUtility.HtmlAttributeEncode(HttpUtility.UrlPathEncode(URL))); }
static string QuoteParser(BBCodeTag ToEncode, BBTreeNode NodeToParse) { string Name = "Quote"; if (!String.IsNullOrWhiteSpace(NodeToParse.Data)) Name = HttpUtility.HtmlAttributeEncode(NodeToParse.Data); return String.Format(ToEncode.HTML, Name); }
static string HTMLEncodeTagParser(BBCodeTag ToEncode, BBTreeNode NodeToParse) { if (!ToEncode.AcceptParameters) return ToEncode.HTML; return String.Format(ToEncode.HTML, HttpUtility.HtmlAttributeEncode(NodeToParse.Data)); }
static string CodeParser(BBCodeTag ToEncode, BBTreeNode NodeToParse) { StringBuilder Test = new StringBuilder(); foreach (var Child in NodeToParse.Children) Test.Append(HttpUtility.HtmlEncode(Child.Data)); var data = Test.Replace("\n", "</li><li>").Replace("\r", "").ToString(); return String.Format(ToEncode.HTML, data); }