static SyntaxTreeNode CreateNode(BBTag[] allowedTags, bool allowText) { switch (PexChoose.ValueFromRange("type", allowText ? 0 : 1, 2)) { case 0: var text = PexChoose.Value<string>("text"); PexAssume.IsTrue(!String.IsNullOrEmpty(text)); return new TextNode(text); case 1: var tag = allowedTags[PexChoose.ValueFromRange("tag", 0, allowedTags.Length)]; var node = new TagNode(tag); AddSubnodes(allowedTags, node); if (tag.Attributes != null) { var selectedIds = new List<string>(); foreach (var attr in tag.Attributes) { if (!selectedIds.Contains(attr.ID) && PexChoose.Value<bool>("include")) { var val = PexChoose.Value<string>("val"); PexAssume.IsTrue(val != null); PexAssume.IsTrue(val.IndexOfAny("[] ".ToCharArray()) == -1); node.AttributeValues[attr] = val; selectedIds.Add(attr.ID); } } } return node; default: PexAssume.Fail(); return null; } }
public static string BBCodeToHtml(string rawString, BBTag bbTag, bool htmlEncode = false) { if (string.IsNullOrEmpty(rawString)) { return rawString; } return HtmlUtility.BBCodeToHtml(rawString, new System.Collections.Generic.List<BBTag> { bbTag }, htmlEncode); }
static void AddSubnodes(BBTag[] allowedTags, SyntaxTreeNode node) { int count = PexChoose.ValueFromRange("count", 0, 3); bool lastWasText = false; for (int i = 0; i < count; i++) { var subNode = CreateNode(allowedTags, !lastWasText); lastWasText = subNode is TextNode; node.SubNodes.Add(subNode); } }
private void LoadDefaultTags() { _tags = new Dictionary<string, BBTag>(10); _tags["b"] = new BBTag("b", "<strong class=\"bbcode-bold\">", "</strong>"); _tags["i"] = new BBTag("i", "<em class=\"bbcode-italic\">", "</em>"); _tags["u"] = new BBTag("u", "<em class=\"bbcode-underline\">", "</em>"); _tags["s"] = new BBTag("s", "<del class=\"bbcode-strikethrough\">", "</del>"); _tags["code"] = new BBTag("code", "<code class=\"bbcode-code\">", "</code>"); _tags["img"] = new BBTag("img", "<img src=\"${content}\" class=\"bbcode-image\" />", "", false, true); _tags["quote"] = new BBTag("quote", "<blockquote class=\"bbcode-quote\">", "</blockquote>"); _tags["sup"] = new BBTag("sup", "<sup class=\"bbcode-superscript\">", "</sup>"); _tags["sub"] = new BBTag("sub", "<sub class=\"bbcode-subscript\">", "</sub>"); _tags["url"] = new BBTag("url", "<a href=\"${href}\" class=\"bbcode-url\">", "</a>", new BBAttribute("href", ""), new BBAttribute("href", "href")); }
public void AddTag(BBTag tag) { TryLoadDefaultTags(); // This is so defaults can be modified _tags[tag.Name] = tag; _parser = null; }
public static SequenceNode CreateRootNode(BBTag[] allowedTags) { var node = new SequenceNode(); AddSubnodes(allowedTags, node); return node; }