WikiFunctions.Parse.HideText.HideMore C# (CSharp) Method

HideMore() public method

Hides images, external links, templates, headings
public HideMore ( string articleText, bool hideOnlyTargetOfWikilink, bool hideWikiLinks, bool hideItalics ) : string
articleText string the text of the article
hideOnlyTargetOfWikilink bool whether to hide only the target of a wikilink (so that fixes such as typo corrections may be applied to the piped part of the link)
hideWikiLinks bool whether to hide all wikilinks including those with words attached outside the link
hideItalics bool whether to hide italics
return string
        public string HideMore(string articleText, bool hideOnlyTargetOfWikilink, bool hideWikiLinks, bool hideItalics)
        {
            MoreHide.Clear();
            cachedOriginalArticleTextBeforeHideMore = articleText;

            ReplaceMore(WikiRegexes.NestedTemplates.Matches(articleText), ref articleText);

            ReplaceMore(WikiRegexes.AllTags.Matches(articleText), ref articleText);

            // this replace done for performance: quickly clear out lots of standard refs
            ReplaceMore(SimpleRef.Matches(articleText), ref articleText);

            if (HideExternalLinks)
            {
                // performance: only use all-protocol regex if the uncommon protocols are in use
                ReplaceMore(WikiRegexes.ExternalLinksHTTPOnly.Matches(articleText), ref articleText);

                if (articleText.Contains("//"))
                    ReplaceMore(WikiRegexes.ExternalLinks.Matches(articleText), ref articleText);
            }

            ReplaceMore(WikiRegexes.Headings.Matches(articleText), ref articleText);

            ReplaceMore(WikiRegexes.Comments.Matches(articleText), ref articleText);

            ReplaceMore(WikiRegexes.IndentedText.Matches(articleText), ref articleText);

            // This hides internal wikilinks (with or without pipe) with extra word character(s) e.g. [[link]]age, which need hiding even if hiding for typo fixing
            // https://en.wikipedia.org/wiki/Wikipedia_talk:AutoWikiBrowser/Feature_requests#Improve_HideText.HideMore.28.29
            // place this as first wikilink rule as otherwise WikiLinksOnly will grab link without extra word character(s)
            if (hideWikiLinks)
                ReplaceMore(WikiRegexes.WikiLinksOnlyPlusWord.Matches(articleText), ref articleText);

            // if HideOnlyTargetOfWikilink is not set, pipes of links e.g. [[target|pipe]] will be hidden
            // if set then don't mask the pipe of a link so that typo fixing can be done on it
            if (!hideOnlyTargetOfWikilink && hideWikiLinks)
                ReplaceMore(WikiRegexes.SimpleWikiLink.Matches(articleText), ref articleText);

            // if hiding target of wikilinks only, this does not apply to Category links, hide all of these
            if (hideOnlyTargetOfWikilink && hideWikiLinks)
                ReplaceMore(WikiRegexes.Category.Matches(articleText), ref articleText);

            ReplaceMore(WikiRegexes.Refs.Matches(articleText), ref articleText);

            // performance: get all remaining tags in format <tag...> in article, apply ReplaceMore only if needed
            List<string> AnyTagList = (from Match m in AnyTag.Matches(articleText)
                select m.Groups[1].Value.Trim().ToLower()).ToList();

            // gallery tag does not require Image: namespace link before image in gallery, so hide anything before pipe
            if (AnyTagList.Any(t => t.Contains("gallery")))
                articleText = WikiRegexes.GalleryTag.Replace(articleText, m => {
                    string res = m.Value;
                    ReplaceMore(ImageToBar.Matches(res), ref res);
                    return res;});

            // this hides only the target of a link, leaving the pipe exposed
            if (hideWikiLinks)
                ReplaceMore(WikiRegexes.WikiLink.Matches(articleText), ref articleText);

            // Image links within templates already hidden as NestedTemplates hides all of templates
            if (AnyTagList.Any(t => t.Contains("gallery")) || articleText.Contains(@"[[")) // check for performance
                ReplaceMore(WikiRegexes.ImagesNotTemplates.Matches(articleText), ref articleText);

            // hide untemplated quotes between some form of quotation marks (most particularly for typo fixing)
            ReplaceMore(WikiRegexes.UntemplatedQuotes.Matches(articleText), ref articleText);

            if (hideItalics)
                ReplaceMore(WikiRegexes.Italics.Matches(articleText), ref articleText);

            if (AnyTagList.Any(t => t.Contains("p style")))
                ReplaceMore(WikiRegexes.Pstyles.Matches(articleText), ref articleText);

            cachedArticleTextAfterHideMore = articleText;
            return articleText;
        }

Same methods

HideText::HideMore ( string articleText ) : string
HideText::HideMore ( string articleText, bool hideOnlyTargetOfWikilink ) : string
HideText::HideMore ( string articleText, bool hideOnlyTargetOfWikilink, bool hideWikiLinks ) : string

Usage Example

 private string HideMore(string text, bool hideExternalLinks, bool leaveMetaHeadings, bool hideImages)
 {
     Hider = new HideText(hideExternalLinks, leaveMetaHeadings, hideImages);
     string s = Hider.HideMore(text);
     Assert.AreEqual(text, Hider.AddBackMore(s));
     return s;
 }
All Usage Examples Of WikiFunctions.Parse.HideText::HideMore