private TextEditor escapeSpecialCharsWithinTagAttributes(TextEditor text) {
        Collection<HTMLToken> tokens = text.tokenizeHTML();
        TextEditor newText = new TextEditor("");

        for (HTMLToken token : tokens) {
            String value = token.getText();
            if (token.isTag()) {
                value = value.replaceAll("\\\\", CHAR_PROTECTOR.encode("\\"));
                value = value.replaceAll("`", CHAR_PROTECTOR.encode("`"));
                value = value.replaceAll("\\*", CHAR_PROTECTOR.encode("*"));
                value = value.replaceAll("_", CHAR_PROTECTOR.encode("_"));
            }
            newText.append(value);
        }

        return newText;
    }
private TextEditor escapeSpecialCharsWithinTagAttributes(TextEditor text) {
        Collection<HTMLToken> tokens = text.tokenizeHTML();
        TextEditor newText = new TextEditor("");

        for (HTMLToken token : tokens) {
            String value = token.getText();
            if (token.isTag()) {
                value = value.replaceAll("\\\\", CHAR_PROTECTOR.encode("\\"));
                value = value.replaceAll("`", CHAR_PROTECTOR.encode("`"));
                value = value.replaceAll("\\*", CHAR_PROTECTOR.encode("*"));
                value = value.replaceAll("_", CHAR_PROTECTOR.encode("_"));
            }
            newText.append(value);
        }

        return newText;
    }
private TextEditor escapeSpecialCharsWithinTagAttributes ( TextEditor text ) { Collection < HTMLToken > tokens = text . tokenizeHTML ( ) ; TextEditor newText = new TextEditor ( "" ) ; for ( HTMLToken token : tokens ) { String value = token . getText ( ) ; if ( token . isTag ( ) ) { value = value . replaceAll ( "\\\\" , CHAR_PROTECTOR . encode ( "\\" ) ) ; value = value . replaceAll ( "`" , CHAR_PROTECTOR . encode ( "`" ) ) ; value = value . replaceAll ( "\\*" , CHAR_PROTECTOR . encode ( "*" ) ) ; value = value . replaceAll ( "_" , CHAR_PROTECTOR . encode ( "_" ) ) ; } newText . append ( value ) ; } return newText ; }
escape special characters

Within tags -- meaning between < and > -- encode [\ ` * _] so they
don't conflict with their use in Markdown for code, italics and strong.
We're replacing each such character with its corresponding random string
value; this is likely overkill, but it should prevent us from colliding
with the escape values by accident.

@param text
@return
escape special characters