static LinkedListNode<Tag> ProcessListContent(TranslateContext context, int level, LinkedListNode<Tag> start) {
            var n = start;
            do
            {
                var thisLineStar = n.FirstNode(x => (x.Value is StarTag || x.Value is NewLineTag));
                if (thisLineStar == null || thisLineStar.Value is NewLineTag || ListPrefixLevel(thisLineStar) == 0) return n;
                n = thisLineStar;

                var endline = n.FirstNode(x => x.Value is NewLineTag);
                var p = ListPrefixLevel(n);
                if (p == level) // same level add item
                {
                    context.Append("<li>\n");
                    n.Next?.Next?.TranslateUntilNode(context, endline);
                    context.Append("</li>\n");
                    n = endline?.Next;
                } else if (p > level) // increasing level, start list, recursion
                {
                    context.Append("<ul>\n");
                    n = ProcessListContent(context, p, n);
                    context.Append("</ul>\n");
                } else // decreasing level
                    return n; // this is continuation of lower level ul, return endline so taht code can resume

            } while (n != null);
            return n;
        }
        public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
        {
            // unordered lists
            if (ListPrefixLevel(self) > 0)
            {
                return(ProcessListContent(context, 0, self));
            }


            // to bolden text - find second star tag
            var node = self.Next;

            while (node != null && !(node.Value is NewLineTag) && !(node.Value is SpaceTag) && node.Value.Mode == OpeningClosingMode.SelfClosed && !(node.Value is TableCellTag))
            {
                if (node.Value is LiteralTag && node.Value.Text.All(Char.IsNumber))
                {
                    break;
                }

                if (node.Value is StarTag)
                {
                    context.Append("<strong>");
                    self.Next.TranslateUntilNode(context, node);
                    context.Append("</strong>");
                    return(node.Next);
                }
                node = node.Next;
            }

            context.Append("*");
            return(self.Next);
        }
        static LinkedListNode <Tag> ProcessListContent(TranslateContext context, int level, LinkedListNode <Tag> start)
        {
            var n = start;

            do
            {
                var thisLineStar = n.FirstNode(x => (x.Value is StarTag || x.Value is NewLineTag));
                if (thisLineStar == null || thisLineStar.Value is NewLineTag || ListPrefixLevel(thisLineStar) == 0)
                {
                    return(n);
                }
                n = thisLineStar;

                var endline = n.FirstNode(x => x.Value is NewLineTag);
                var p       = ListPrefixLevel(n);
                if (p == level) // same level add item
                {
                    context.Append("<li>\n");
                    n.Next?.Next?.TranslateUntilNode(context, endline);
                    context.Append("</li>\n");
                    n = endline?.Next;
                }
                else if (p > level)   // increasing level, start list, recursion
                {
                    context.Append("<ul>\n");
                    n = ProcessListContent(context, p, n);
                    context.Append("</ul>\n");
                }
                else           // decreasing level
                {
                    return(n); // this is continuation of lower level ul, return endline so taht code can resume
                }
            } while (n != null);
            return(n);
        }
        public override LinkedListNode<Tag> Translate(TranslateContext context, LinkedListNode<Tag> self) {
            if (!(self.Previous?.Value is LiteralTag)) // previous is not a continuous text
            {
                var ender = self.Next.FirstNode(x => !(x.Value is LiteralTag || x.Value is UnderscoreTag));
                var val = self.Next.GetOriginalContentUntilNode(ender); // get next string

                if (!string.IsNullOrEmpty(val))
                {
                    val = Account.StripInvalidLobbyNameChars(val.Trim());
                    var db = new ZkDataContext();

                    var acc = Account.AccountByName(db, val);
                    if (acc != null)
                    {
                        context.Append(context.Html.PrintAccount(acc));
                        return ender;
                    }
                    var clan = db.Clans.FirstOrDefault(x => x.Shortcut == val);
                    if (clan != null)
                    {
                        context.Append(context.Html.PrintClan(clan));
                        return ender;
                    }
                    var fac = db.Factions.FirstOrDefault(x => x.Shortcut == val);
                    if (fac != null)
                    {
                        context.Append(context.Html.PrintFaction(fac, false));
                        return ender;
                    }
                    if (val.StartsWith("b", StringComparison.InvariantCultureIgnoreCase))
                    {
                        var bid = 0;
                        if (int.TryParse(val.Substring(1), out bid))
                        {
                            var bat = db.SpringBattles.FirstOrDefault(x => x.SpringBattleID == bid);
                            if (bat != null)
                            {
                                context.Append(context.Html.PrintBattle(bat));
                                return ender;
                            }
                        }
                    }
                }
            }
            context.Append("@");
            return self.Next;
        }
        public override LinkedListNode<Tag> Translate(TranslateContext context, LinkedListNode<Tag> self) {
            var cellCount = self.AsEnumerable().Skip(1).TakeWhile(x => !(x.Value is NewLineTag)).Count(x => x.Value is TableCellTag);

            // only start tables if this tag appears on start of line
            if (cellCount > 0 && self.AsReverseEnumerable().TakeWhile(x => !(x.Value is NewLineTag)).All(x => x.Value is SpaceTag)) 
            {
                context.Append("<table class='wikitable'>");

                var n = self;
                while (n?.Value is TableCellTag)
                {
                    if (cellCount != n.AsEnumerable().Skip(1).TakeWhile(x => !(x.Value is NewLineTag)).Count(x => x.Value is TableCellTag)) break;

                    context.Append("<tr>");

                    LinkedListNode<Tag> nextStop;
                    while ((nextStop = n.Next.FirstNode(x => x.Value is NewLineTag || x.Value is TableCellTag))?.Value is TableCellTag)
                    {
                        context.Append("<td>");
                        n.Next.TranslateUntilNode(context, nextStop);
                        context.Append("</td>");
                        n = nextStop;
                    }

                    context.Append("</tr>");

                    n = n.FirstNode(x => x.Value is NewLineTag)?.Next; // move after nextline
                }
                context.Append("</table>");
                return n;
            }
            context.Append(Text);
            
            return self.Next;
        }
        public override LinkedListNode<Tag> Translate(TranslateContext context, LinkedListNode<Tag> self) {
            var parts = arguments.Split(new[] { ' ' }, 2);
            var name = parts.Length > 1 ? parts[1] : parts[0];
            var link = parts[0];
            if (link.IsValidLink()) context.AppendFormat("<a href=\"{0}\">{1}</a>", link, name);
            else context.Append(context.Html?.ActionLink(name, "Index", "Wiki", new { node = link }, null));

            return self.Next;
        }
Exemple #7
0
        public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
        {
            // to bolden text - find second star tag
            var node = self.Next;

            while (node != null && !(node.Value is NewLineTag) && node.Value.Mode == OpeningClosingMode.SelfClosed && !(node.Value is TableCellTag))
            {
                if (node.Value is UnderscoreTag)
                {
                    context.Append("<em>");
                    self.Next.TranslateUntilNode(context, node);
                    context.Append("</em>");
                    return(node.Next);
                }
                node = node.Next;
            }

            context.Append(Text);
            return(self.Next);
        }
        public override LinkedListNode<Tag> Translate(TranslateContext context, LinkedListNode<Tag> self) {

            // to bolden text - find second star tag
            var node = self.Next;
            while (node != null && !(node.Value is NewLineTag) && node.Value.Mode == OpeningClosingMode.SelfClosed && !(node.Value is TableCellTag))
            {
                if (node.Value is UnderscoreTag)
                {
                    context.Append("<em>");
                    self.Next.TranslateUntilNode(context, node);
                    context.Append("</em>");
                    return node.Next;
                }
                node = node.Next;
            }

            context.Append(Text);
            return self.Next;

        }
        public override LinkedListNode<Tag> Translate(TranslateContext context, LinkedListNode<Tag> self) {
            // unordered lists
            if (ListPrefixLevel(self) > 0) return ProcessListContent(context, 0, self);


            // to bolden text - find second star tag
            var node = self.Next;
            while (node != null && !(node.Value is NewLineTag) && !(node.Value is SpaceTag) && node.Value.Mode == OpeningClosingMode.SelfClosed && !(node.Value is TableCellTag))
            {
                if (node.Value is LiteralTag && node.Value.Text.All(Char.IsNumber)) break; 

                if (node.Value is StarTag)
                {
                    context.Append("<strong>");
                    self.Next.TranslateUntilNode(context, node);
                    context.Append("</strong>");
                    return node.Next;
                }
                node = node.Next;
            }

            context.Append("*");
            return self.Next;
        }
Exemple #10
0
        public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
        {
            var closing = self.NextNodeOfType <PollCloseTag>();

            if (context.Html != null)
            {
                var content = self.Next.GetOriginalContentUntilNode(closing);
                int pollID;
                if (!string.IsNullOrEmpty(content) && int.TryParse(content, out pollID))
                {
                    context.Append(context.Html.Action("Index", "Poll", new { pollID }));
                }
            }

            return(closing.Next);
        }
Exemple #11
0
        public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
        {
            var parts = arguments.Split(new[] { ' ' }, 2);
            var name  = parts.Length > 1 ? parts[1] : parts[0];
            var link  = parts[0];

            if (link.IsValidLink())
            {
                context.AppendFormat("<a href=\"{0}\">{1}</a>", link, name);
            }
            else
            {
                context.Append(context.Html?.ActionLink(name, "Index", "Wiki", new { node = link }, null));
            }

            return(self.Next);
        }
        public override LinkedListNode<Tag> Translate(TranslateContext context, LinkedListNode<Tag> self) {
            var level = Text.Length;

            var ender = self.Next.FirstNode(x => x.Value is HeaderTag || x.Value is NewLineTag);
            if (ender?.Value is HeaderTag && ender.Value.Text.Length == level)
            {
                var name = HttpUtility.HtmlEncode(self.Next.GetOriginalContentUntilNode(ender).Trim());
                var link =  Account.StripInvalidLobbyNameChars(name.Replace(" ", "_").Replace("\"", "_").Replace("'", "_"));
                context.AppendFormat("<h{0}><a name=\"{1}\"></a>{2}</h{0}>", level, link, name);
                context.AddTocEntry(new TocEntry(name, link, level));

                return ender.Next;
            }

            context.Append(Text);
            return self.Next;
        }
        public override LinkedListNode<Tag> Translate(TranslateContext context, LinkedListNode<Tag> self) {
            if (Text.IsValidLink())
            {
                // implicit linkification and imagifination
                if (Text.EndsWith(".png") || Text.EndsWith(".gif") || Text.EndsWith(".jpg") || Text.EndsWith(".jpeg")) context.AppendFormat("<a href=\"{0}\" target=\"_blank\" ><img src=\"{0}\" max-width=\"100%\" height=\"auto\"/></a>", Text);
                else if (Text.StartsWith("http://www.youtube.com/watch"))
                {
                    var m = Regex.Match(Text,"v=([^&]+)");
                    if (m.Success)
                    {
                        context.AppendFormat("<iframe width=\"420\" height=\"315\" src=\"http://www.youtube.com/embed/{0}\" frameborder=\"0\" hd=\"1\" allowfullscreen=\"1\"></iframe>", m.Groups[1].Value);
                    }
                } else context.AppendFormat("<a href=\"{0}\">{0}</a>", Text);
            } else context.Append(HttpUtility.HtmlEncode(Text));

            return self.Next;
        }
Exemple #14
0
        public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
        {
            var level = Text.Length;

            var ender = self.Next.FirstNode(x => x.Value is HeaderTag || x.Value is NewLineTag);

            if (ender?.Value is HeaderTag && ender.Value.Text.Length == level)
            {
                var name = HttpUtility.HtmlEncode(self.Next.GetOriginalContentUntilNode(ender).Trim());
                var link = Utils.StripInvalidLobbyNameChars(name.Replace(" ", "_").Replace("\"", "_").Replace("'", "_"));
                context.AppendFormat("<h{0}><a name=\"{1}\"></a>{2}</h{0}>", level, link, name);
                context.AddTocEntry(new TocEntry(name, link, level));

                return(ender.Next);
            }

            context.Append(Text);
            return(self.Next);
        }
        public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
        {
            if (Text.IsValidLink())
            {
                // implicit linkification and imagifination
                if ((Text.EndsWith(".png") || Text.EndsWith(".gif") || Text.EndsWith(".jpg") || Text.EndsWith(".jpeg")) && Text.IsValidLinkOrRelativeUrl(true))
                {
                    context.AppendFormat("<a href=\"{0}\" target=\"_blank\" ><img src=\"{0}\" max-width=\"100%\" height=\"auto\"/></a>", Text);
                }
                // YouTube auto-embed
                else if (Text.StartsWith("http://www.youtube.com/watch") || Text.StartsWith("https://www.youtube.com/watch"))
                {
                    var m = Regex.Match(Text.Replace("autoplay=1", ""), "v=([^&]+)");
                    if (m.Success)
                    {
                        context.AppendFormat("<iframe width=\"420\" height=\"315\" src=\"https://www.youtube.com/embed/{0}\" frameborder=\"0\" hd=\"1\" allowfullscreen=\"1\"></iframe>", m.Groups[1].Value);
                    }
                }
                else if (Text.StartsWith("http://youtu.be/") || Text.StartsWith("https://youtu.be/"))
                {
                    var m = Regex.Match(Text.Replace("autoplay=1", ""), @"\.be/([^&?]+)");
                    if (m.Success)
                    {
                        context.AppendFormat("<iframe width=\"420\" height=\"315\" src=\"https://www.youtube.com/embed/{0}\" frameborder=\"0\" hd=\"1\" allowfullscreen=\"1\"></iframe>", m.Groups[1].Value);
                    }
                }
                else
                {
                    context.AppendFormat("<a href=\"{0}\">{0}</a>", Text);
                }
            }
            else
            {
                context.Append(HttpUtility.HtmlEncode(Text));
            }

            return(self.Next);
        }
        public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
        {
            var cellCount = self.AsEnumerable().Skip(1).TakeWhile(x => !(x.Value is NewLineTag)).Count(x => x.Value is TableCellTag);

            // only start tables if this tag appears on start of line
            if (cellCount > 0 && self.AsReverseEnumerable().TakeWhile(x => !(x.Value is NewLineTag)).All(x => x.Value is SpaceTag))
            {
                context.Append("<table class='wikitable'>");

                var n = self;
                while (n?.Value is TableCellTag)
                {
                    if (cellCount != n.AsEnumerable().Skip(1).TakeWhile(x => !(x.Value is NewLineTag)).Count(x => x.Value is TableCellTag))
                    {
                        break;
                    }

                    context.Append("<tr>");

                    LinkedListNode <Tag> nextStop;
                    while ((nextStop = n.Next.FirstNode(x => x.Value is NewLineTag || x.Value is TableCellTag))?.Value is TableCellTag)
                    {
                        context.Append("<td>");
                        n.Next.TranslateUntilNode(context, nextStop);
                        context.Append("</td>");
                        n = nextStop;
                    }

                    context.Append("</tr>");

                    n = n.FirstNode(x => x.Value is NewLineTag)?.Next; // move after nextline
                }
                context.Append("</table>");
                return(n);
            }
            context.Append(Text);

            return(self.Next);
        }
 public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
 {
     context.Append(
         "<table border=\"0\" cellpadding=\"6\" cellspacing=\"0\" width=\"100%\"><tbody><tr><td style=\"border: 1px inset;\"><em>quote:<br/>");
     return(self.Next);
 }
 public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
 {
     context.Append("<br/>");
     return(self.Next);
 }
 public override LinkedListNode<Tag> Translate(TranslateContext context, LinkedListNode<Tag> self) {
     context.Append("<br/>");
     return self.Next;
 }
        public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
        {
            if (!(self.Previous?.Value is LiteralTag)) // previous is not a continuous text
            {
                var ender = self.Next.FirstNode(x => !(x.Value is LiteralTag || x.Value is UnderscoreTag));
                var text  = self.Next.GetOriginalContentUntilNode(ender); // get next string

                if (!string.IsNullOrEmpty(text))
                {
                    int idx;
                    for (idx = 0; idx < text.Length; idx++)
                    {
                        if (!Utils.ValidLobbyNameCharacter(text[idx]))
                        {
                            break;
                        }
                    }
                    string remainder = null;
                    string val       = text;
                    if (idx != 0 && idx < text.Length)
                    {
                        remainder = text.Substring(idx, text.Length - idx);
                        val       = text.Substring(0, idx);
                    }

                    if (!string.IsNullOrEmpty(val))
                    {
                        var db = new ZkDataContext();

                        var fac = db.Factions.FirstOrDefault(x => x.Shortcut == val);
                        if (fac != null)
                        {
                            context.Append(context.Html.PrintFaction(fac, false));
                            context.Append(remainder);
                            return(ender);
                        }
                        var acc = Account.AccountByName(db, val);
                        if (acc != null)
                        {
                            context.Append(context.Html.PrintAccount(acc));
                            context.Append(remainder);
                            return(ender);
                        }
                        var clan = db.Clans.FirstOrDefault(x => x.Shortcut == val);
                        if (clan != null)
                        {
                            context.Append(context.Html.PrintClan(clan));
                            context.Append(remainder);
                            return(ender);
                        }
                        if (val.StartsWith("b", StringComparison.InvariantCultureIgnoreCase))
                        {
                            var bid = 0;
                            if (int.TryParse(val.Substring(1), out bid))
                            {
                                var bat = db.SpringBattles.FirstOrDefault(x => x.SpringBattleID == bid);
                                if (bat != null)
                                {
                                    context.Append(context.Html.PrintBattle(bat));
                                    context.Append(remainder);
                                    return(ender);
                                }
                            }
                        }
                    }
                }
            }
            context.Append("@");
            return(self.Next);
        }
 public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
 {
     context.Append("</em></td></tr></tbody></table>");
     return(self.Next);
 }
Exemple #22
0
        public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
        {
            if (self.Previous?.Value is LiteralTag) // previous is contiguous text
            {
                context.Append("@");
                return(self.Next);
            }
            var ender = self.Next.FirstNode(x => !(x.Value is LiteralTag || x.Value is UnderscoreTag));
            var text  = self.Next.GetOriginalContentUntilNode(ender); // get next string

            if (string.IsNullOrEmpty(text))
            {
                context.Append("@");
                return(self.Next);
            }
            int idx;

            for (idx = 0; idx < text.Length; idx++)
            {
                if (!Utils.ValidLobbyNameCharacter(text[idx]))
                {
                    break;
                }
            }
            string remainder = null;
            string val       = text;

            if (idx != 0 && idx < text.Length)
            {
                remainder = text.Substring(idx, text.Length - idx);
                val       = text.Substring(0, idx);
            }

            if (string.IsNullOrEmpty(val))
            {
                context.Append("@");
                return(self.Next);
            }
            var  db     = new ZkDataContext();
            char prefix = Char.ToLowerInvariant(val[0]);
            int  id     = 0;

            int.TryParse(val.Substring(1), out id);

            var fac = db.Factions.FirstOrDefault(x => x.Shortcut == val);

            if (fac == null && prefix == 'f')
            {
                fac = db.Factions.FirstOrDefault(x => x.FactionID == id);
            }
            if (fac != null)
            {
                context.Append(context.Html.PrintFaction(fac, false));
                context.Append(remainder);
                return(ender);
            }

            var acc = Account.AccountByName(db, val);

            if (acc == null && prefix == 'u')
            {
                acc = db.Accounts.FirstOrDefault(x => x.AccountID == id);
            }
            if (acc != null)
            {
                context.Append(context.Html.PrintAccount(acc));
                context.Append(remainder);
                return(ender);
            }

            var clan = db.Clans.FirstOrDefault(x => x.Shortcut == val);

            if (clan == null && prefix == 'c')
            {
                clan = db.Clans.FirstOrDefault(x => x.ClanID == id);
            }
            if (clan != null)
            {
                context.Append(context.Html.PrintClan(clan));
                context.Append(remainder);
                return(ender);
            }

            // can't tag a battle by its name
            SpringBattle bat = null;

            if (prefix == 'b')
            {
                bat = db.SpringBattles.FirstOrDefault(x => x.SpringBattleID == id);
            }
            if (bat != null)
            {
                context.Append(context.Html.PrintBattle(bat));
                context.Append(remainder);
                return(ender);
            }

            context.Append("@");
            return(self.Next);
        }