public static Dictionary <string, Player> GetPlayerInfoFromParticipants(ICarnoServiceSink sink, string s) { List <WikiNode> nodes = WikiParser.Parse(s).ToList(); var participants = new Dictionary <string, Player>(); bool taking = false; foreach (var node in nodes) { if (node.IsSection()) { taking = ((node as WikiTextNode).Text == "Participants"); } if (taking && node is WikiTableNode) { foreach (var cell in (node as WikiTableNode).Cells) { var cellnodes = (from cellnode in cell where cellnode is WikiTemplateNode let nodetemplate = cellnode as WikiTemplateNode orderby nodetemplate.Name select nodetemplate).ToList(); if (cellnodes.Count == 0 || cellnodes.Count > 2 || cellnodes[0].Name.ToLower() != "player") { continue; } WikiTemplateNode player = cellnodes[0]; string playerId = GetPlayerId(player); string team = "noteam"; if (cellnodes.Count == 2) { WikiTemplateNode temppart = cellnodes[1]; team = temppart.Name.From("TeamPart/"); team = sink.ConformTeamId(team); } Player info = new Player(); info.Id = player.GetParamText("1"); info.Flag = player.GetParamText("flag"); info.Team = team; info.Link = LiquipediaUtils.NormaliseLink(GetPlayerLink(player.GetParamText("link"))); participants[playerId] = info; if (!string.IsNullOrEmpty(info.Link)) { sink.SetIdLinkMap(info.Id, info.Link); } } } } return(participants); }
private string ParseAndRenderWikiText(string text) { var buf = new StringBuilder(); using (var writer = new HtmlTextWriter(new StringWriter(buf))) { Page container = new Page(); renderer.AddTo(parser.Parse(text), container, article); container.RenderControl(writer); } return(buf.ToString()); }
protected override void OnInit(EventArgs e) { if (IsNew) { h1.Text = CurrentArguments; } else { h1.Text = CurrentPage.Title; txtText.Text = CurrentPage.Text; } txtText.EnableFreeTextArea = CurrentPage.WikiRoot.EnableFreeText; phSubmit.Visible = cvAuthorized.IsValid = IsAuthorized; if (!string.IsNullOrEmpty(Text)) { WikiParser parser = Engine.Resolve <WikiParser>(); WikiRenderer renderer = Engine.Resolve <WikiRenderer>(); renderer.AddTo(parser.Parse(Text), pnlMessage, CurrentPage); } Register.JQuery(Page); base.OnInit(e); }
public void TripleTilde_IsParsedAs_UserName() { var fragments = parser.Parse("~~~").ToList(); Assert.That(fragments.Count, Is.EqualTo(1)); Assert.That(fragments[0].Command, Is.EqualTo("UserInfo")); }
public static void ProcessWikicode(string s, ICarnoServiceSink sink) { List <WikiNode> items = WikiParser.Parse(s).ToList(); var templates = from item in items where item is WikiTemplateNode select item as WikiTemplateNode; foreach (WikiTemplateNode template in templates) { if (template.Name == "MatchList") { int matchno = 1; while (true) { List <WikiNode> contents; if (!template.Params.TryGetValue("match" + matchno.ToString(), out contents)) { break; } if (contents.Count == 1 && contents[0] is WikiTemplateNode) { TryProcessMatchMaps(sink, contents[0] as WikiTemplateNode); } matchno++; } //sink.ClearTemporaryIdMap(); continue; } if (TryProcessMatchMaps(sink, template)) { continue; } if (TryProcessBracket(sink, template)) { continue; } if (TryProcessTeamBracket(sink, template)) { continue; } if (TryProcessGroupTableSlot(sink, template)) { continue; } if (TryProcessPlayerCrossTable(sink, template)) { continue; } // if we ended up here, we don't support this template //sw.WriteLine("; -- Unsupported template: {0} --", template.Name); sink.UnknownTemplate(template); } }
protected virtual IEnumerable<WikiToken> Parse(TextReader reader, NameValueCollection headers) { WikiParser parser = new WikiParser(); string src = Src; string urlFormat = WikiWordUrlFormat; if (src.Length > 0 && urlFormat.Length > 0) { string basePath = VirtualPathUtility.GetDirectory(src); string extension = VirtualPathUtility.GetExtension(src); parser.WikiWordResolver = delegate(string word) { string path = VirtualPathUtility.Combine(basePath, word + extension); if (!HostingEnvironment.VirtualPathProvider.FileExists(path)) return null; return new Uri(ResolveUrl(string.Format(urlFormat, word)), UriKind.Relative); }; } return parser.Parse(reader, headers); }