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 < p > 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 .
