We have a TinyMCE script on one of our pages that allows users to paste text segments from Word into it. We've noticed that on paste from Word documents, we get some additional, unwanted CSS like code prepended in the text are, which looks like
@font-face
{
font-family: "Arial";
}
@font-face
{
font-family: "Cambria Math";
}
@font-face
{
font-family: "Cambria";
}
p.MsoNormal, li.MsoNormal, div.MsoNormal
{
margin: 0in 0in 0.0001pt; font-size: 11pt; font-family: Arial;
}
strong { }
.MsoChpDefault
{
font-size: 10pt;
font-family: Cambria;
}
div.WordSection1
{
page: WordSection1;
}
We currently have a PHP script that uses a regex expression to delete this data before it is saved. However, we wish to have this data deleted on paste, so that the user never comes into contact with it.
I've added the following regex expression into the onPaste plugin of TinyMCE
/@font(.*)\{(.*)\}/i
However, it doesn't delete anything. If I remove the last literal bracket \}, it will remove sections of the code, but not the entire thing, so the expression seems to be in the correct place, however, it seems like it is not formed correctly.
Basically, I'm looking for a valid JavaScript regex expression that will delete everything from @font to the last curly bracket }.