private string ReplaceLinks(string input) { if (LinkList != null) { // Only replace links that don't refer to the current species (either by name or by target). input = WikiPageUtils.FormatPageLinksIf(input, LinkList, x => !StringMatchesSpeciesName(x.Value, Species) && !StringMatchesSpeciesName(x.Target, Species)); } return(input); }
private async Task <string> GetDescriptionTokenValueAsync() { string description = Species.GetDescriptionOrDefault(); description = ItalicizeBinomialNames(description); // do this before replacing links so that links can be italicized more easily description = ReplaceLinks(description); description = EmboldenFirstMentionOfSpecies(description); description = WikiPageUtils.ReplaceMarkdownWithWikiMarkup(description); return(await Task.FromResult(description)); }
private string EmboldenFirstMentionOfSpecies(string input) { List <string> toMatch = new List <string> { string.Format(WikiPageUtils.UnlinkedWikiTextPatternFormat, Regex.Escape(Species.GetFullName().ToLower())), string.Format(WikiPageUtils.UnlinkedWikiTextPatternFormat, Regex.Escape(Species.GetShortName().ToLower())), string.Format(WikiPageUtils.UnlinkedWikiTextPatternFormat, Regex.Escape(Species.Name.ToLower())) }; if (!string.IsNullOrEmpty(Species.GetCommonName())) { string.Format(WikiPageUtils.UnlinkedWikiTextPatternFormat, Regex.Escape(Species.GetCommonName().ToLower())); } Regex regex = new Regex(string.Join("|", toMatch), RegexOptions.IgnoreCase); return(WikiPageUtils.FormatFirstMatch(input, regex, TextFormatting.Bold)); }
private string ItalicizeBinomialNames(string input) { if (AllSpecies != null) { foreach (ISpecies species in AllSpecies) { List <string> to_match = new List <string> { string.Format(WikiPageUtils.UnformattedWikiTextPatternFormat, Regex.Escape(species.GetFullName())), string.Format(WikiPageUtils.UnformattedWikiTextPatternFormat, Regex.Escape(species.GetShortName())), }; Regex regex = new Regex(string.Join("|", to_match), RegexOptions.IgnoreCase); input = WikiPageUtils.FormatAllMatches(input, regex, TextFormatting.Italic); // Also italicize binomial names that might be using outdated genera (e.g. Species moved to a new genus since the description was written). // This might create some false-positives, so it could be a good idea to limit matches only to known genera (at the expense of a significantly longer regex). input = WikiPageUtils.FormatAllMatches(input, new Regex(string.Format(WikiPageUtils.UnformattedWikiTextPatternFormat, @"[A-Z](?:[a-z]+|\.)\s" + Regex.Escape(species.Name.ToLower()))), TextFormatting.Italic); } } return(input); }