WikiFunctions.ReplaceSpecial.InTemplateRule.ReplaceOn C# (CSharp) Method

ReplaceOn() private static method

private static ReplaceOn ( string template, TreeNode tn, string text, string title ) : string
template string
tn System.Windows.Forms.TreeNode
text string
title string
return string
        private static string ReplaceOn(string template, TreeNode tn, string text, string title)
        {
            InTemplateRule r = (InTemplateRule)tn.Tag;

            foreach (TreeNode t in tn.Nodes)
            {
                IRule sr = (IRule)t.Tag;
                text = sr.Apply(t, text, title);
            }

            if (r.DoReplace_ && !string.IsNullOrEmpty(r.ReplaceWith_))
            {
                if (string.IsNullOrEmpty(template))
                    return text;

                string pattern =
                  @"^([\s]*)" + Tools.CaseInsensitive(template) + @"([\s]*(?:<!--.*-->)?[\s]*(\}\}|\|))";

                pattern = pattern.Replace(" ", "[ _]+");

                string replace = Tools.ApplyKeyWords(title, r.ReplaceWith_, false);

                text = Regex.Replace(text, pattern, "$1" + replace + "$2");
            }

            return text;
        }