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