WikiFunctions.SubstTemplates.SubstituteTemplates C# (CSharp) Method

SubstituteTemplates() public method

Substitutes templates in the given article text
public SubstituteTemplates ( string articleText, string articleTitle ) : string
articleText string The wiki text of the article.
articleTitle string Title of the article
return string
        public string SubstituteTemplates(string articleText, string articleTitle)
        {
            if (!HasSubstitutions)
                return articleText; // nothing to substitute

            if (chkIgnoreUnformatted.Checked)
                articleText = RemoveUnformatted.HideUnformatted(articleText);

            if (!chkUseExpandTemplates.Checked)
            {
                foreach (KeyValuePair<Regex, string> p in Regexes)
                {
                    articleText = p.Key.Replace(articleText, p.Value);
                }
            }
            else
                articleText = Tools.ExpandTemplate(articleText, articleTitle, Regexes, chkIncludeComment.Checked);

            if (chkIgnoreUnformatted.Checked)
                articleText = RemoveUnformatted.AddBackUnformatted(articleText);

            return articleText;
        }

Usage Example

コード例 #1
0
        /// <summary>
        /// Process a "find and replace"
        /// </summary>
        /// <param name="findAndReplace">A FindandReplace object</param>
        /// <param name="substTemplates">A SubstTemplates object</param>
        /// <param name="replaceSpecial">An MWB ReplaceSpecial object</param>
        /// <param name="SkipIfNoChange">True if the article should be skipped if no changes are made</param>
        public void PerformFindAndReplace(FindandReplace findAndReplace, SubstTemplates substTemplates,
                                          ReplaceSpecial.ReplaceSpecial replaceSpecial, bool SkipIfNoChange)
        {
            if (!findAndReplace.HasReplacements && !replaceSpecial.HasRules && !substTemplates.HasSubstitutions)
            {
                return;
            }

            string strTemp        = mArticleText.Replace("\r\n", "\n"),
                   testText       = strTemp,
                   tmpEditSummary = "";

            strTemp = findAndReplace.MultipleFindAndReplace(strTemp, mName, ref tmpEditSummary);
            strTemp = replaceSpecial.ApplyRules(strTemp, mName);
            strTemp = substTemplates.SubstituteTemplates(strTemp, mName);

            if (testText == strTemp)
            {
                if (SkipIfNoChange)
                {
                    Trace.AWBSkipped("No Find And Replace Changes");
                }
                else
                {
                    return;
                }
            }
            else
            {
                AWBChangeArticleText("Find and replace applied" + tmpEditSummary,
                                     strTemp.Replace("\n", "\r\n"), true);
                EditSummary += tmpEditSummary;
            }
        }
All Usage Examples Of WikiFunctions.SubstTemplates::SubstituteTemplates