GetAllTemplateDetail() public static method

Extracts a distinct list of all template calls in the input text, supporting any level of template nesting.
public static GetAllTemplateDetail ( string articleText ) : List
articleText string
return List
        /// <summary>
        /// Merges multiple {{portal}} templates into a single one, removing any duplicates. En-wiki only.
        /// Restricted to {{portal}} calls with one argument
        /// Article must have existing {{portal}} and/or a 'see also' section
        /// </summary>
        /// <param name="articleText">The article text</param>
        /// <returns>The updated article text</returns>
        public static string MergePortals(string articleText)
        {
            if (!Variables.LangCode.Equals("en"))
            {
                return(articleText);
            }

            // return if {{portal}} within {{stack}}
            List <string> stacks = Parsers.GetAllTemplateDetail(articleText).Where(t => StackTemplate.IsMatch(t)).ToList();

            if (stacks.Any(s => WikiRegexes.PortalTemplate.IsMatch(s)))
            {
                return(articleText);
            }

            string        originalArticleText = articleText;
            List <string> Portals             = new List <string>();
            int           firstPortal         = WikiRegexes.PortalTemplate.Match(articleText).Index;

            MatchCollection portalCalls = WikiRegexes.PortalTemplate.Matches(articleText);

            foreach (Match m in portalCalls)
            {
                string thePortalCall = m.Value;

                // Do not process portal templates with named arguments
                if (!Tools.GetTemplateParameterValues(thePortalCall).Any())
                {
                    for (int i = 1; i <= Tools.GetTemplateArgumentCount(thePortalCall); i++)
                    {
                        Portals.Add(Tools.GetTemplateArgument(thePortalCall, i).Trim());
                    }

                    articleText = Regex.Replace(articleText, Regex.Escape(thePortalCall) + @"\s*(?:\r\n)?", "");
                }
            }

            // if no portal parameters, return now, removing empty portal template
            if (!Portals.Any())
            {
                return(articleText);
            }

            // abort if not enough portals to merge, or all in one existing template
            if (Portals.Count < 2 || portalCalls.Count == 1)
            {
                return(originalArticleText);
            }

            // generate portal string
            string portalsToAdd = Tools.DeduplicateList(Portals).Aggregate("", (current, portal) => current + ("|" + portal));

            // first merge to see also section
            if (WikiRegexes.SeeAlso.Matches(articleText).Count == 1)
            {
                return(WikiRegexes.SeeAlso.Replace(articleText, "$0" + Tools.Newline(@"{{Portal" + portalsToAdd + @"}}")));
            }

            // otherwise merge to original location if all portals in same section
            if (!WikiRegexes.Headings.IsMatch(originalArticleText) || Summary.ModifiedSection(originalArticleText, articleText).Length > 0)
            {
                return(articleText.Insert(firstPortal, @"{{Portal" + portalsToAdd + @"}}" + "\r\n"));
            }

            return(originalArticleText);
        }