here's the issue, but first a foreword.
Everything is fine until there are single or double quotes INSIDE the 'string' value. Having a double quote inside the string, even JS escaped leads to the onclick argument value being cut :
<button onclick=<font color='"Red"'>"DoSomething('str\\"</font>ing')">
If you replace the double quote by '"' then you don't get a double quote inside DoSomething (you could always replace " by " in JS).
Similar problem if you choose to enclose the onclick argument in single quotes and happen to have a single quote JS escaped inside the string.
So, is there any other way of dealing with potential presence of single AND double quotes in the 'string' value, other than replacing them before by ' and " and then replacing them back inside DoSomething ?