Ejemplo n.º 1
0
        public static XmlDocument ToXml(this BBCodeDocument obj)
        {
            var xdoc = new XmlDocument();

            var root = xdoc.CreateElement("body");

            foreach (var c in obj.Children)
            {
                root.AppendChild(c.ToXml(xdoc));
            }

            return(xdoc);
        }
Ejemplo n.º 2
0
        public string Parse(string bbCode)
        {
            bbCode = bbCode.Trim();
            var doc = new BBCodeDocument(bbCode);

            // No new line to html parsing here. This would create too much new lines by templates like spoiler. We do this inside the parse method on the inner html.
            RemoveLineBreaksAroundBlockElements(doc.Nodes);

            string html = "";

            doc.Nodes.ForEach(node => {
                string nodeHtml = ParseNode(node);
                string saveHtml = sanitizer.Sanitize(nodeHtml);
                html           += saveHtml;
            });
            return(html);
        }
Ejemplo n.º 3
0
        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 />"));
            }
        }
Ejemplo n.º 4
0
 /// <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));
 }