public static string ParsePost(string post) { try { var doc = BBCodeDocument.Load(post, false); var LookupTable = HtmlRenderer.DefaultLookupTable.ToList(); LookupTable.Remove(LookupTable.First(x => x.Key == "code")); LookupTable.Remove(LookupTable.First(x => x.Key == "i")); LookupTable.Remove(LookupTable.First(x => x.Key == "img")); LookupTable.Add(new KeyValuePair <string, HtmlRendererCallback>("code", BBCode.RenderCode)); LookupTable.Add(new KeyValuePair <string, HtmlRendererCallback>("s", BBCode.RenderStrikethough)); LookupTable.Add(new KeyValuePair <string, HtmlRendererCallback>("img", BBCode.RenderImg)); return(doc.Children.ToHtml(false, LookupTable.ToArray())); } catch { return(post.Replace("\n", "<br />")); } }
/// <summary> /// Quick and easy method for converting BBCode to HTML. Batteries included. /// </summary> /// <param name="BBCode">A string of BBCode formatted text</param> /// <returns>A string of HTML code</returns> public static string BbToHtml(this string BBCode) { return(BBCodeDocument.Load(BBCode, false, new string[] { "hr" }).ToHtml(false)); }