public void removeWikiLinkMarkup(StringBuilder article, String title) {
        int bracketStart = article.indexOf("[[");
        boolean includeLinkText = 
            options.contains(CleanerOption.INCLUDE_LINK_TEXT);
        while (bracketStart >= 0) {
            
            // grab the linked article name which is all text to the next ]], or
            // to
            int bracketEnd = article.indexOf("]]", bracketStart);
            // If there wasn't a matching closing bracket (i.e. malformatted
            // wiki), then abort the replacement
            if (bracketEnd < 0)
                break;
            
            // If the link text is supposed to be included in the document, then
            // strip out the pertinent text.  However, ensure that the link
            // points to an article, which filters out non-content links in the
            // article headers and footers
            if (includeLinkText && 
                isArticleLink(article.substring(bracketStart+2, 
                                                bracketEnd), title)) {

                // the link may also have a text description that replaces the
                // link text, e.g.  [[article title|link text]].
                int optionalLinkDescriptionStart = 
                    article.indexOf("|", bracketStart);
                // When selecting the optional text, ensure that the | delimeter
                // falls within the link structure itself
                int linkTextStart = 
                    (optionalLinkDescriptionStart >= 0 && 
                     optionalLinkDescriptionStart < bracketEnd)
                    ? optionalLinkDescriptionStart + 1
                    : bracketStart + 2;
                // Parse out the link text
                String linkText = article.substring(linkTextStart, bracketEnd);
                // Then replace the entire link with the desired text
                article.replace(bracketStart, bracketEnd+2, linkText);
            }
            // If the link text isn't to be used in the document, remove it
            // completely
            else {
                article.delete(bracketStart, bracketEnd + 2);
            }
            bracketStart = article.indexOf("[[", bracketStart);
        }   
    }
public void removeWikiLinkMarkup ( StringBuilder article , String title ) { int bracketStart = article . indexOf ( "[[" ) ; boolean includeLinkText = options . contains ( CleanerOption . INCLUDE_LINK_TEXT ) ; while ( bracketStart >= 0 ) { int bracketEnd = article . indexOf ( "]]" , bracketStart ) ; if ( bracketEnd < 0 ) break ; if ( includeLinkText && isArticleLink ( article . substring ( bracketStart + 2 , bracketEnd ) , title ) ) { int optionalLinkDescriptionStart = article . indexOf ( "|" , bracketStart ) ; int linkTextStart = ( optionalLinkDescriptionStart >= 0 && optionalLinkDescriptionStart < bracketEnd ) ? optionalLinkDescriptionStart + 1 : bracketStart + 2 ; String linkText = article . substring ( linkTextStart , bracketEnd ) ; article . replace ( bracketStart , bracketEnd + 2 , linkText ) ; } else { article . delete ( bracketStart , bracketEnd + 2 ) ; } bracketStart = article . indexOf ( "[[" , bracketStart ) ; } }
Replace [[link]] tags with link name and track what articles this article
links to.

@param text The article text to clean and process link structure of.

@return A Duple containing the cleaned text and the outgoing link count.