mil.dod.th.confluence.doclet/src/org/udri/doclet/confluence/ConfluenceDoclet.java
public static String htmlToWiki(String html)
    {
        //TODO TH-1475 This would probably be more efficient using a StringBuilder 
        // to build the final string as it replaces html with wiki markup.
        
        // Convert links that make it past the tags structure to wiki links
        ArrayList<String> links = new ArrayList<String>();
        Pattern linkPattern = Pattern.compile("<a href.*?</a.*?>", Pattern.DOTALL);
        Matcher linkMatcher = linkPattern.matcher(html);
        while (linkMatcher.find())
        {
            links.add(linkMatcher.group());
        }
        for (String link : links)
        {
            String original = link;
            link = link.replaceAll("\\r\\n|\\r|\\n", " ");
            String alias = link.replaceAll("<a.*?>", "");
            alias = alias.replaceAll("</a>", "").trim();
            link = link.replaceAll("<a.*?\"", "["); 
            link = link.replaceAll("\".*?>.*?</a>", "]");           
            if (!link.contains("http"))
            {
                link = link.replaceAll("\\.", "#");
            }
            link = link.replace("[", "[" + alias + "|");
            html = html.replace(original, link);
        }
        
        // Convert ordered lists
        Pattern olPattern = Pattern.compile("<ol>.*?</ol>", Pattern.DOTALL);
        Matcher olMatcher = olPattern.matcher(html);
        while (olMatcher.find())
        {
            String original = olMatcher.group();
            String bullets = original.replaceAll("<li>", " # ");
            html = html.replaceAll(Pattern.quote(original), bullets);
        }
        
        // Convert unordered lists
        Pattern ulPattern = Pattern.compile("<ul>.*</ul>", Pattern.DOTALL);
        Matcher ulMatcher = ulPattern.matcher(html);
        while (ulMatcher.find())
        {
            String original = ulMatcher.group();
            String bullets = original.replaceAll("<li>", " - ");
            html = html.replaceAll(Pattern.quote(original), bullets);
        }
        
        // Convert code tags to monospace font
        html = html.replaceAll("<code( .*)?>", "{{");
        html = html.replaceAll("</code>", "}}");
        
        // Convert header tags
        html = html.replaceAll("<h1( .*)?>", "h1. ");
        html = html.replaceAll("<h2( .*)?>", "h2. ");
        html = html.replaceAll("<h3( .*)?>", "h3. ");
        html = html.replaceAll("<h4( .*)?>", "h4. ");
        html = html.replaceAll("<h5( .*)?>", "h5. ");
        
        // Convert italic tags
        html = html.replaceAll("<i( .*)?> ", " _");
        html = html.replaceAll("</i>", "_ ");
        
        // Convert bold tags
        html = html.replaceAll("<b( .*)?> ", " *");
        html = html.replaceAll("</b>", "* ");
        
        // Remove all remaining tags as a last resort, catch all.
        html = html.replaceAll("\\<.*?\\>", "");
        return html;
    }
/**
     * Convert to confluence wiki markup or remove all html tags in a string.
     * 
     * @param html
     *     The html string to convert.
     * @return
     *     The same string with all html removed or converted to confluence wiki.
     */
Convert to confluence wiki markup or remove all html tags in a string.

@param html
The html string to convert.
@return
The same string with all html removed or converted to confluence wiki.
Convert to confluence wiki markup or remove all html tags in a string . @param html The html string to convert . @return The same string with all html removed or converted to confluence wiki .
public static String htmlToWiki(String html)
    {
        ArrayList<String> links = new ArrayList<String>();
        Pattern linkPattern = Pattern.compile("<a href.*?</a.*?>", Pattern.DOTALL);
        Matcher linkMatcher = linkPattern.matcher(html);
        while (linkMatcher.find())
        {
            links.add(linkMatcher.group());
        }
        for (String link : links)
        {
            String original = link;
            link = link.replaceAll("\\r\\n|\\r|\\n", " ");
            String alias = link.replaceAll("<a.*?>", "");
            alias = alias.replaceAll("</a>", "").trim();
            link = link.replaceAll("<a.*?\"", "["); 
            link = link.replaceAll("\".*?>.*?</a>", "]");           
            if (!link.contains("http"))
            {
                link = link.replaceAll("\\.", "#");
            }
            link = link.replace("[", "[" + alias + "|");
            html = html.replace(original, link);
        }
        Pattern olPattern = Pattern.compile("<ol>.*?</ol>", Pattern.DOTALL);
        Matcher olMatcher = olPattern.matcher(html);
        while (olMatcher.find())
        {
            String original = olMatcher.group();
            String bullets = original.replaceAll("<li>", " # ");
            html = html.replaceAll(Pattern.quote(original), bullets);
        }
        Pattern ulPattern = Pattern.compile("<ul>.*</ul>", Pattern.DOTALL);
        Matcher ulMatcher = ulPattern.matcher(html);
        while (ulMatcher.find())
        {
            String original = ulMatcher.group();
            String bullets = original.replaceAll("<li>", " - ");
            html = html.replaceAll(Pattern.quote(original), bullets);
        }
        html = html.replaceAll("<code( .*)?>", "{{");
        html = html.replaceAll("</code>", "}}");
        html = html.replaceAll("<h1( .*)?>", "h1. ");
        html = html.replaceAll("<h2( .*)?>", "h2. ");
        html = html.replaceAll("<h3( .*)?>", "h3. ");
        html = html.replaceAll("<h4( .*)?>", "h4. ");
        html = html.replaceAll("<h5( .*)?>", "h5. ");
        html = html.replaceAll("<i( .*)?> ", " _");
        html = html.replaceAll("</i>", "_ ");
        html = html.replaceAll("<b( .*)?> ", " *");
        html = html.replaceAll("</b>", "* ");
        html = html.replaceAll("\\<.*?\\>", "");
        return html;
    }
public static String htmlToWiki ( String html ) { ArrayList < String > links = new ArrayList < String > ( ) ; Pattern linkPattern = Pattern . compile ( "<a href.*?</a.*?>" , Pattern . DOTALL ) ; Matcher linkMatcher = linkPattern . matcher ( html ) ; while ( linkMatcher . find ( ) ) { links . add ( linkMatcher . group ( ) ) ; } for ( String link : links ) { String original = link ; link = link . replaceAll ( "\\r\\n|\\r|\\n" , " " ) ; String alias = link . replaceAll ( "<a.*?>" , "" ) ; alias = alias . replaceAll ( "</a>" , "" ) . trim ( ) ; link = link . replaceAll ( "<a.*?\"" , "[" ) ; link = link . replaceAll ( "\".*?>.*?</a>" , "]" ) ; if ( ! link . contains ( "http" ) ) { link = link . replaceAll ( "\\." , "#" ) ; } link = link . replace ( "[" , "[" + alias + "|" ) ; html = html . replace ( original , link ) ; } Pattern olPattern = Pattern . compile ( "<ol>.*?</ol>" , Pattern . DOTALL ) ; Matcher olMatcher = olPattern . matcher ( html ) ; while ( olMatcher . find ( ) ) { String original = olMatcher . group ( ) ; String bullets = original . replaceAll ( "<li>" , " # " ) ; html = html . replaceAll ( Pattern . quote ( original ) , bullets ) ; } Pattern ulPattern = Pattern . compile ( "<ul>.*</ul>" , Pattern . DOTALL ) ; Matcher ulMatcher = ulPattern . matcher ( html ) ; while ( ulMatcher . find ( ) ) { String original = ulMatcher . group ( ) ; String bullets = original . replaceAll ( "<li>" , " - " ) ; html = html . replaceAll ( Pattern . quote ( original ) , bullets ) ; } html = html . replaceAll ( "<code( .*)?>" , "{{" ) ; html = html . replaceAll ( "</code>" , "}}" ) ; html = html . replaceAll ( "<h1( .*)?>" , "h1. " ) ; html = html . replaceAll ( "<h2( .*)?>" , "h2. " ) ; html = html . replaceAll ( "<h3( .*)?>" , "h3. " ) ; html = html . replaceAll ( "<h4( .*)?>" , "h4. " ) ; html = html . replaceAll ( "<h5( .*)?>" , "h5. " ) ; html = html . replaceAll ( "<i( .*)?> " , " _" ) ; html = html . replaceAll ( "</i>" , "_ " ) ; html = html . replaceAll ( "<b( .*)?> " , " *" ) ; html = html . replaceAll ( "</b>" , "* " ) ; html = html . replaceAll ( "\\<.*?\\>" , "" ) ; return html ; }
Convert to confluence wiki markup or remove all html tags in a string.
Convert to confluence wiki markup or remove all html tags in a string .
//TODO TH-1475 This would probably be more efficient using a StringBuilder  // to build the final string as it replaces html with wiki markup. // Convert links that make it past the tags structure to wiki links // Convert ordered lists // Convert unordered lists // Convert code tags to monospace font // Convert header tags // Convert italic tags // Convert bold tags // Remove all remaining tags as a last resort, catch all.