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;
        }
Пример #2
0
        public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
        {
            var closing = self.NextNodeOfType <YouTubeCloseTag>();

            var content = self.Next.GetOriginalContentUntilNode(closing);

            if (!string.IsNullOrEmpty(content))
            {
                string content2 = content.Replace("autoplay=1", "");
                var    match    = Regex.Match(content2, "v=([^&]+)");
                if (match.Success)
                {
                    context.AppendFormat("<iframe width=\"420\" height=\"315\" src=\"https://www.youtube.com/embed/{0}\" frameborder=\"0\" hd=\"1\" allowfullscreen=\"1\"></iframe>", match.Groups[1].Value);
                    return(closing.Next);
                }
                match = Regex.Match(content2, @"\.be/([^&]+)");
                if (match.Success)
                {
                    context.AppendFormat("<iframe width=\"420\" height=\"315\" src=\"https://www.youtube.com/embed/{0}\" frameborder=\"0\" hd=\"1\" allowfullscreen=\"1\"></iframe>", match.Groups[1].Value);
                    return(closing.Next);
                }
            }

            return(closing.Next);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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 (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);
                // YouTube auto-embed
                else if (Text.StartsWith("http://www.youtube.com/watch") || Text.StartsWith("https://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 if (Text.StartsWith("http://youtu.be/") || Text.StartsWith("https://youtu.be/"))
                {
                    var m = Regex.Match(Text, @"\.be/([^&?]+)");
                    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;
        }
Пример #7
0
        public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
        {
            var closing = self.FirstNode(x => x.Value is CodeCloseTag);
            var str     = self.Next.GetOriginalContentUntilNode(closing);

            context.AppendFormat("<pre>{0}</pre>", HttpUtility.HtmlEncode(str));
            return(closing.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;
        }
Пример #9
0
        public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
        {
            var closingTag = self.NextNodeOfType <ImgCloseTag>();

            // get url either from param or from inner literal between tags
            var url = arguments.Length == 0 ? self.Next.GetOriginalContentUntilNode(closingTag) : arguments.Substring(1, arguments.Length - 1);

            if (url.IsValidLinkOrRelativeUrl(true))
            {
                context.AppendFormat("<a href=\"{0}\" target=\"_blank\" ><img src=\"{0}\" max-width=\"100%\" height=\"auto\"/></a>", url);
            }

            return(closingTag?.Next); // move to after closing img
        }
Пример #10
0
        /// <summary>
        ///     Renders final tags to html string builder
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        static string RenderTags(LinkedList <Tag> tags, HtmlHelper html)
        {
            var context = new TranslateContext(html);

            tags = EliminateUnclosedTags(tags);

            var node = tags.First;

            while (node != null)
            {
                node = node.Value.Translate(context, node);
            }
            context.FinishRendering();

            return(context.ToString());
        }
Пример #11
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);
        }
Пример #12
0
        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;
        }
Пример #13
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);
        }
Пример #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 =  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;
        }
Пример #15
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) {

            // 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;

        }
Пример #17
0
        public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
        {
            var closing = self.NextNodeOfType <VidCloseTag>();

            var content = self.Next.GetOriginalContentUntilNode(closing);

            if (!string.IsNullOrEmpty(content))
            {
                var match = Regex.Match(content, @"(https?\:\/\/)((\w|-|_|\.|\/)+\.)(mp4|webm|ogg|ogv|3gp|gifv)", RegexOptions.IgnoreCase);
                if (match.Success)
                {
                    var urlPart = match.Groups[1].Value + match.Groups[2].Value;
                    context.AppendFormat(
                        "<div class=\"video-container\"><video preload=\"auto\" height=\"auto\" width=\"auto\" controls=\"controls\"><source type=\"video/webm\" src=\"{0}webm\"><source type=\"video/mp4\" src=\"{0}mp4\"><source type=\"video/ogg\" src=\"{0}ogg\"><source type=\"video/ogv\" src=\"{0}ogv\"><source type=\"video/3gp\" src=\"{0}3gp\">Your browser does not support the video tag. Find out if your Browser is supported at www.w3schools.com/tags/tag_video.asp</video></div>",
                        urlPart);
                }
            }

            return(closing.Next);
        }
Пример #18
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);
        }
Пример #19
0
        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);
        }
Пример #20
0
        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);
        }
Пример #21
0
        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;
        }
Пример #22
0
 public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
 {
     context.AppendFormat("<a href=\"{0}\" target=\"_blank\">", arguments);
     return(self.Next);
 }
Пример #23
0
 public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
 {
     context.Append("<br/>");
     return(self.Next);
 }
Пример #24
0
 public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
 {
     return(new QTagClose().Translate(context, self));
 }
Пример #25
0
 public override LinkedListNode<Tag> Translate(TranslateContext context, LinkedListNode<Tag> self) {
     context.Append("<br/>");
     return self.Next;
 }
Пример #26
0
 public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
 {
     context.AppendFormat("<span nicetitle=\"{0}\">", arguments);
     return(self.Next);
 }
Пример #27
0
 public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
 {
     throw new ApplicationException("This isn't happening"); // should not be called
 }
Пример #28
0
 public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
 {
     context.AppendFormat(
         "<small class=\"js_expand\"><a nicetitle-processed=\"Expand/Collapse\" style=\"display:block\" href=\"#\">[Spoiler]</a></small><div style=\"display: none;\" class=\"collapse\">");
     return(self.Next);
 }
        /// <summary>
        ///     Renders final tags to html string builder
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        static string RenderTags(LinkedList<Tag> tags, HtmlHelper html) {
            var context = new TranslateContext(html);

            tags = EliminateUnclosedTags(tags);

            var node = tags.First;
            while (node != null) node = node.Value.Translate(context, node);
            context.FinishRendering();

            return context.ToString();
        }
Пример #30
0
 public abstract LinkedListNode<Tag> Translate(TranslateContext context, LinkedListNode<Tag> self);
Пример #31
0
        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);
        }
Пример #32
0
 public abstract LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self);
Пример #33
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);
        }
Пример #34
0
 public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
 {
     throw new NotImplementedException(); // should not be executed
 }
Пример #35
0
 public override LinkedListNode <Tag> Translate(TranslateContext context, LinkedListNode <Tag> self)
 {
     context.Append("</em></td></tr></tbody></table>");
     return(self.Next);
 }
Пример #36
0
 public static LinkedListNode <Tag> TranslateUntilNode(this LinkedListNode <Tag> startNode, TranslateContext context, LinkedListNode <Tag> endNode)
 {
     return(startNode.TranslateWhile(context, x => x != endNode));
 }
Пример #37
0
        public static LinkedListNode <Tag> TranslateWhile(this LinkedListNode <Tag> startNode, TranslateContext context, Antlr.Runtime.Misc.Func <LinkedListNode <Tag>, bool> condition)
        {
            var n = startNode;

            while (n != null && condition(n))
            {
                n = n.Value.Translate(context, n);
            }
            return(n);
        }
Пример #38
0
 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);
 }