WikiFunctions.Parse.Parsers.SameNamedRefShortText C# (CSharp) Method

SameNamedRefShortText() private static method

refs with same name, but one is very short, so just change to <ref name=foo/> notation
private static SameNamedRefShortText ( string articleText ) : string
articleText string the wiki text of the page
return string
        private static string SameNamedRefShortText(string articleText)
        {
            // Peformance: get a list of all the short named refs that could be condensed
            // then only attempt replacement if some found and matching long named refs found
            string justNamedRefs = string.Join("", GetNamedRefs(articleText).Select(m => m.Value).ToArray());
            List<string> ShortNamed = (from Match m in ShortNameReference.Matches(justNamedRefs) select m.Groups[2].Value).ToList();

            if (ShortNamed.Any())
            {
                foreach (Match m in LongNamedReferences.Matches(articleText))
                {
                    string refname = m.Groups[2].Value;

                   // don't apply if short ref is a page ref
                   if (ShortNamed.Contains(refname) && m.Groups[3].Value.Length > 30)
                      articleText = Regex.Replace(articleText, @"(<\s*ref\s+name\s*=\s*(?:""|')?(" + Regex.Escape(refname) + @")(?:""|')?\s*>\s*([^<>]{1,9}?|\[?[Ss]ee above\]?|{{\s*[Cc]ite *\w+\s*}})\s*<\s*/\s*ref>)",
                                                    m2=> PageRef.IsMatch(m2.Groups[3].Value) ? m2.Value : @"<ref name=""" + refname + @"""/>");
                }
            }

            return articleText;
        }
Parsers