0

Anyone can help me to work this script which should replace tags when a html code is pasted into textarea? For unknown reason only some tags are replaced, but about 1/4 or 1/5 of the tags stays not replaced.

<script>
  CKE_init();
  var editor = CKEDITOR.instances['edit'];

var hArray={'@a\1': /https\:\/\/(\d)\.bp\.blogspot\.com\//gi,
       '@s\1': /src="https:\/\/(\d)\.bp\.blogspot\.com\//gi,
'@im': /(img)/gi,
'@d1': /<div class="separator" style="clear: both; text-align: center;">/gi,
'@sw': /<span class="answer"><span class="answer"><br \/><\/span>/gi, 
'@sp': /<span class="answer"><span class="answer">/gi,
'@ac': /align="center" /gi,
'@al': /align="left"/gi,
'@ar': /align="right"/gi,
'@cp\1': /cellpadding=("?\d*"? )/gi,
'@cs\1': /cellspacing=("?\d*"? )/gi,
'@tb': /<tbody>/gi,
'@st': /style="/gi,
'@ml': /margin-left: /gi,
'@mr': /margin-right: /gi,
'@tc': /"text-align: center;"/gi,
'@t:': /text-align: center;"/gi,
'@tl': /"text-align: left;"/gi,
'@tr': /"text-align: right;"/gi,
'@sa': /<span class="answer">/gi,
'@c1': /class="tr-caption-container" /gi,
'@c2': /class="tr-caption" /gi,
'@/t': /<\/table>/gi,
'@t/': /<\/tbody>/gi,
'@/r': /<\/td><\/tr>/gi,
'@w\1': /width="(\d*)" /gi,
'@h\1': /height="(\d*)" /gi,
'@bs': /<br \/><\/span><\/span><br \/>/gi,
'@s/': /<\/span><\/span><br \/>/gi,
'@/s': /<\/span><\/span>/gi,
'@ts': /<table /gi,
'@a/': /\/><\/a>/gi,
'@r/': /<tr><td /gi,
'@/b': /<br \/>/gi,
'@au': /auto; /gi,
'@b\1': /border="(\d*)"/gi,
'@n\1': /anchor="(\d*)"/gi,
'@d2': /<div class="separator"/gi,
'@/d': /<tr><td /gi,
'@da': /<\/a><\/div>/gi,
'@j': /\.jpg" \/>/gi,
'@p': /\.png" \/>/gi,
'@g': /\.gif" \/>/gi,
'@im': /;"><img /gi
};

  editor.on( 'paste', function( evt ) {
    for (k in hArray) 
      evt.data.dataValue = evt.data.dataValue
          .replace( hArray[k], k );

  });
</script>

The text which is pasted and should be replaced:

<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://1.bp.blogspot.com/-RIsL-uwaO4/VstRPZ0U6dI/AAAAAAAAChw/MHWTQ09DRGQ/s1600/n%25C3%25A1let000.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="266" src="https://1.bp.blogspot.com/-RGIsL-uwaO4/VstRPZ0U6dI/AAAAAAAAChw/MHWTQ09DRGQ/s400/file0.jpg" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>some text here.</i></td></tr>
</tbody></table>
<br /><span class="answer"><span class="answer"><br /></span></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://4.bp.blogspot.com/-Nv8BBDRzK8/VstSBSdINlI/AAAAAAAACh4/UoCuxubTGlY/s1600/n%25C3%25A1let002.jpg" style="margin-left: auto; margin-right: auto;"><img border="0" height="266" src="https://4.bp.blogspot.com/-NTv8BBDRzK8/VstSBSdINlI/AAAAAAAACh4/UoCuxubTGlY/s400/file2.jpg" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i>some text here.</i></td></tr>
</tbody></table>
<span class="answer"><span class="answer"><br /></span></span><br />
<br />
<br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://2.bp.blogspot.com/-PVNoX7ffiw/VstXyi3a-dI/AAAAAAAACiI/-Ijv2cOzSwc/s1600/F4F-3-45kg-2s.gif" style="margin-left: auto; margin-right: auto;"><img border="0" height="400" src="https://2.bp.blogspot.com/-PVWNoX7ffiw/VstXyi3a-dI/AAAAAAAACiI/file.gif" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><i><span class="answer"><span class="answer">some text here.</span></span></i></td></tr>
</tbody></table>
<span class="answer"><span class="answer"><br /></span></span>
<span class="answer"><span class="answer"></span></span><br />
<br /><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://3.bp.blogspot.com/-_mOBQG5AEbE/Vs9U3jodYWI/AAAAAAAACm0/TuIvD8_N0w/s1600/bounce%2Bf4f-3%2Bwildcat.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://3.bp.blogspot.com/-_mOBQG5AEbE/Vs9U3jodYWI/AAAAAAAACm0/TuIYvD8_N0w/s1600/files.jpg" /></a></div>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://2.bp.blogspot.com/-Wi3KwbjGO4/Vs9VBQNkd2I/AAAAAAAACm4/H0BWjNyHtsk/s1600/F4F-3-45kg-2s-low.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://2.bp.blogspot.com/-Wio3KwbjGO4/Vs9VBQNkd2I/AAAAAAAACm4/H0BWjNyHtsk/s1600/file.gif" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">some text here.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://1.bp.blogspot.com/-mztbZKi6uQ/Vs9fMJMdU1I/AAAAAAAACnI/pHx73lxSlTU/s1600/F4F-3-45kg-2s-low-2-right.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://1.bp.blogspot.com/-mztbbZKi6uQ/Vs9fMJMdU1I/AAAAAAAACnI/pHx73lxSlTU/s1600/file.gif" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">some text here.</td></tr>
</tbody></table>
some text here<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://2.bp.blogspot.com/-ToAt8EbjaRM/Vs9hLgWFr9I/AAAAAAAACnU/6UZ65VW2nY/s1600/ttss.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://2.bp.blogspot.com/-ToAt8EbjaRM/Vs9hLgWFr9I/AAAAAAAACnU/6U8Z65VW2nY/s1600/filenamehere.gif" /></a></div>
<br />

Far more I did a test with this:

  editor.on( 'paste', function( evt ) {
    for (k in hArray) 
{
console.log(k + ': ' +evt.data.dataValue
          .match( hArray[k] ));
      evt.data.dataValue = evt.data.dataValue
          .replace( hArray[k], k );
}

And I got this in console log:

"wysiwyg" add.php:782
"editor is ready" add.php:778
"@a: 1.bp.blogspot.com/,https://1.bp.blogspot.com/,https://4.bp.blogspot.com/,https://4.bp.blogspot.com/,https://2.bp.blogspot.com/,https://2.bp.blogspot.com/,https://3.bp.blogspot.com/,https://3.bp.blogspot.com/,https://2.bp.blogspot.com/,https://2.bp.blogspot.com/,https://1.bp.blogspot.com/,https://1.bp.blogspot.com/,https://2.bp.blogspot.com/,https://2.bp.blogspot.com" add.php:836
"@s: null" add.php:836
"@im: null" add.php:836
"@d1: null" add.php:836
"@sw: null" add.php:836
"@sp: null" add.php:836
"@ac: align="center" ,align="center" ,align="center" ,align="center" ,align="center" " add.php:836
"@al: null" add.php:836
"@ar: null" add.php:836
"@cp: cellpadding="0" ,cellpadding="0" ,cellpadding="0" ,cellpadding="0" ,cellpadding="0" " add.php:836
"@cs: cellspacing="0" ,cellspacing="0" ,cellspacing="0" ,cellspacing="0" ,cellspacing="0" " add.php:836
"@tb: null" add.php:836
"@st: style=",style=",style=",style=",style=",style=",style=",style=",style=",style=",style=",style=",style=",style=",style=",style=",style=",style=",style=",style=",style=",style=",style=",style="" add.php:836
"@ml: margin-left: ,margin-left: ,margin-left: ,margin-left: ,margin-left: ,margin-left: ,margin-left: ,margin-left: ,margin-left: ,margin-left: ,margin-left: ,margin-left: " add.php:836
"@mr: margin-right: ,margin-right: ,margin-right: ,margin-right: ,margin-right: ,margin-right: ,margin-right: ,margin-right: ,margin-right: ,margin-right: ,margin-right: ,margin-right: " add.php:836
"@tc: null" add.php:836
"@t:: text-align: center;",text-align: center;",text-align: center;",text-align: center;",text-align: center;",text-align: center;",text-align: center;",text-align: center;",text-align: center;",text-align: center;",text-align: center;",text-align: center;",text-align: center;",text-align: center;",text-align: center;",text-align: center;",text-align: center;"" add.php:836
"@tl: null" add.php:836
"@tr: null" add.php:836
"@sa: null" add.php:836
"@c1: class="tr-caption-container" ,class="tr-caption-container" ,class="tr-caption-container" ,class="tr-caption-container" ,class="tr-caption-container" " add.php:836
"@c2: class="tr-caption" ,class="tr-caption" ,class="tr-caption" ,class="tr-caption" ,class="tr-caption" " add.php:836
"@/t: null" add.php:836
"@t/: null" add.php:836
"@/r: null" add.php:836
"@w: width="400" ,width="400" ,width="640" " add.php:836
"@h: height="266" ,height="266" ,height="400" " add.php:836
"@bs: null" add.php:836
"@s/: null" add.php:836
"@/s: null" add.php:836
"@ts: null" add.php:836
"@a/: null" add.php:836
"@r/: null" add.php:836
"@/b: null" add.php:836
"@au: auto; ,auto; ,auto; ,auto; ,auto; ,auto; ,auto; ,auto; ,auto; ,auto; ,auto; ,auto; ,auto; ,auto; ,auto; " add.php:836
"@b: border="0",border="0",border="0",border="0",border="0",border="0",border="0"" add.php:836
"@n: anchor="1",anchor="1",anchor="1",anchor="1"" add.php:836
"@d2: null" add.php:836
"@/d: null" add.php:836
"@da: null" add.php:836
"@j: null" add.php:836
"@p: null" add.php:836
"@g: null" add.php:836

So there really are not matches. How to fix the script to replace all the specified tags and strings for short strings?

Note: The 3rd index '@im': /(img)/gi, was added just for testing purposes. "@im: null" add.php:836 console says clearly that the img tag was not found. But there is a lot of images in the source text. The last index: '@im': /;"><img/gi was not replaced but it is not in the log for unknown reason.

Edit: To reduce the code just short the pattern array: var editor = CKEDITOR.instances['edit'];

var hArray={ '@im': /img/gi }

In console: produced result: "@im: img,img,img,img,img,img,img" and the img string was successfully replaced. But using this: '@im': /;"><img/gi will not produce any results. Looks like there is some syntax error or something line that what prevents the match and .replace to finish the job.

Edit: What I have found is that this single html file works:

<body>
<script>
var str = '<img name=text>';
str = str.replace( /<img /gi ,'***');
// console.log( str );
alert(str);
</script>
</body>

console.log( str ); failed to print the str. This works also in my script but again if I use the hArray with this: '@im': /<img / so no change has been made.

John Boe
  • 3,501
  • 10
  • 37
  • 71
  • 1
    You should try to reduce your question to the minimum. It does not help to paste that much code. – crackmigg Mar 12 '16 at 15:05
  • Good idea mate, I have reduced the pattern array to the very basic pattern, see my edit. It works only for the shorten version `'@im': /img/gi`, but the `'@im': /;"> – John Boe Mar 12 '16 at 16:26

2 Answers2

3

Regex is not the right tool to parse HTML. There is a good answer about this at RegEx match open tags except XHTML self-contained tags, and while it is a bit pretentious, it does make the point clear. Unless this is a one-time job that does not need maintaining or is restricted to a single input that doesn't change substantially, Regex is not the right tool to parse HTML.


Then what is the right tool? Well, HTML is a special form of XML, so in theory you could use an XML parser. However, there's an even better way for javascript. You see, Javascript is designed to work together with HTML. So you can just treat your HTML input as a HTML page and process it like you normally would:

editor.on( 'paste', function( evt ) {
    var el = document.createElement('html');
    el.innerHTML = evt.data.datavalue
    //Now do whatever editing you have to do to replace in here using the normal DOM tools.
});
Nzall
  • 3,439
  • 5
  • 29
  • 59
  • My answer to you is your own words *"This is a one-time job that does not need maintaining or is restricted to a single input that doesn't change substantially."* I tried to search but I found no results because all wants the contents of the tag the always want to remove the <>. This is not my case. I need to find at least the left one <. This is crazy because it fails everytime even with `/\>img/ig` ... or even `/[<]img/gi` or `/ – John Boe Mar 12 '16 at 17:07
  • @John The fact that it's a "one time job" does not mean you *have* to use regex, or that regex somehow suddenly becomes a valid tool for it. Regex is still the wrong tool for it, it's what you might use after you have run out of/exhausted all other options. There is no good reason not to use a parser here, especially since there is such a superb HTML parser built into Javascript, and is practically for free, too. Use it. Stop trying to get it to work with regular expressions, you are wasting your time. Let it go. – Tomalak Mar 12 '16 at 17:55
  • Probably the correct answer is: *"this will never work."* The simplest code works `editor.on( 'paste', function( evt ) { evt.data.dataValue = evt.data.dataValue .replace(/img /, '@'); });` and the simplest code with angle bracked fails: `editor.on( 'paste', function( evt ) { evt.data.dataValue = evt.data.dataValue .replace(/ – John Boe Mar 12 '16 at 18:00
  • The `.replace()` function certainly contains no bug. Rule number one, it's never a bug, always a programmer error. Exceptions apply, but this this is not one of them. ;) – Tomalak Mar 12 '16 at 18:04
  • Ok, there is no bug in **.replace** and **.match**, they **work perfectly** if I put some testing code in separate html file outside of the event listener function .on. But **inside this code:** **`editor.on( 'paste', function( evt ) {}`** **some functions stop working correctly.** See this: `evt.data.dataValue = evt.data.dataValue.split("<").join("@£").split(">").join("@¥");` **works perfectly outside .on but fails inside it. Why?** This is CKEditor problem. – John Boe Mar 12 '16 at 19:01
0

The content of the variable evt.data.dataValue contains translated tags:

alert(evt.data.dataValue);

<p>&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;<br>&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="https://1.bp.blogspot.com/-RIsL-uwaO4/VstRPZ0U6dI/AAAAAAAAChw/MHWTQ09DRGQ/s1600/n%25C3%25A1let000.jpg" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="266" src="https://1.bp.blogspot.com/-RGIsL-uwaO4/VstRPZ0U6dI/AAAAAAAAChw/MHWTQ09DRGQ/s400/file0.jpg" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;i&gt;some text here.&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;/tbody&gt;&lt;/table&gt;<br>&lt;br /&gt;&lt;span class="answer"&gt;&lt;span class="answer"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;<br>&lt;br /&gt;<br>&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;<br>&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="https://4.bp.blogspot.com/-Nv8BBDRzK8/VstSBSdINlI/AAAAAAAACh4/UoCuxubTGlY/s1600/n%25C3%25A1let002.jpg" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="266" src="https://4.bp.blogspot.com/-NTv8BBDRzK8/VstSBSdINlI/AAAAAAAACh4/UoCuxubTGlY/s400/file2.jpg" width="400" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;i&gt;some text here.&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;/tbody&gt;&lt;/table&gt;<br>&lt;span class="answer"&gt;&lt;span class="answer"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;<br>&lt;br /&gt;<br>&lt;br /&gt;&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;<br>&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="https://2.bp.blogspot.com/-PVNoX7ffiw/VstXyi3a-dI/AAAAAAAACiI/-Ijv2cOzSwc/s1600/F4F-3-45kg-2s.gif" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" height="400" src="https://2.bp.blogspot.com/-PVWNoX7ffiw/VstXyi3a-dI/AAAAAAAACiI/file.gif" width="640" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;&lt;i&gt;&lt;span class="answer"&gt;&lt;span class="answer"&gt;some text here.&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;/tbody&gt;&lt;/table&gt;<br>&lt;span class="answer"&gt;&lt;span class="answer"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;<br>&lt;span class="answer"&gt;&lt;span class="answer"&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;<br>&lt;br /&gt;&lt;br /&gt;<br>&lt;div class="separator" style="clear: both; text-align: center;"&gt;<br>&lt;a href="https://3.bp.blogspot.com/-_mOBQG5AEbE/Vs9U3jodYWI/AAAAAAAACm0/TuIvD8_N0w/s1600/bounce%2Bf4f-3%2Bwildcat.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="https://3.bp.blogspot.com/-_mOBQG5AEbE/Vs9U3jodYWI/AAAAAAAACm0/TuIYvD8_N0w/s1600/files.jpg" /&gt;&lt;/a&gt;&lt;/div&gt;<br>&lt;br /&gt;<br>&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;<br>&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="https://2.bp.blogspot.com/-Wi3KwbjGO4/Vs9VBQNkd2I/AAAAAAAACm4/H0BWjNyHtsk/s1600/F4F-3-45kg-2s-low.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="https://2.bp.blogspot.com/-Wio3KwbjGO4/Vs9VBQNkd2I/AAAAAAAACm4/H0BWjNyHtsk/s1600/file.gif" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;some text here.&lt;/td&gt;&lt;/tr&gt;<br>&lt;/tbody&gt;&lt;/table&gt;<br>&lt;br /&gt;<br>&lt;table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"&gt;&lt;tbody&gt;<br>&lt;tr&gt;&lt;td style="text-align: center;"&gt;&lt;a href="https://1.bp.blogspot.com/-mztbZKi6uQ/Vs9fMJMdU1I/AAAAAAAACnI/pHx73lxSlTU/s1600/F4F-3-45kg-2s-low-2-right.gif" imageanchor="1" style="margin-left: auto; margin-right: auto;"&gt;&lt;img border="0" src="https://1.bp.blogspot.com/-mztbbZKi6uQ/Vs9fMJMdU1I/AAAAAAAACnI/pHx73lxSlTU/s1600/file.gif" /&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;<br>&lt;tr&gt;&lt;td class="tr-caption" style="text-align: center;"&gt;some text here.&lt;/td&gt;&lt;/tr&gt;<br>&lt;/tbody&gt;&lt;/table&gt;<br>some text here&lt;br /&gt;<br>&lt;br /&gt;<br>&lt;div class="separator" style="clear: both; text-align: center;"&gt;<br>&lt;a href="https://2.bp.blogspot.com/-ToAt8EbjaRM/Vs9hLgWFr9I/AAAAAAAACnU/6UZ65VW2nY/s1600/ttss.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="https://2.bp.blogspot.com/-ToAt8EbjaRM/Vs9hLgWFr9I/AAAAAAAACnU/6U8Z65VW2nY/s1600/filenamehere.gif" /&gt;&lt;/a&gt;&lt;/div&gt;<br>&lt;br /&gt;</p><p></p>

I need to get rid of the substitutions before I perform regex search!

This is code which successfully replaces tags when using CKEditor and paste from clipboard to textarea:

<script>
CKEditor_init();
var editor = CKEDITOR.instances['edit'];
var hArray={
'' : /&amp;/gi, // REMOVE html entity: @ 
'<' : /&lt;/gi, // decode html entity 
'>' : /&gt;/gi, // decode html entity 

'@a\1': /https\:\/\/(\d)\.bp\.blogspot\.com\//gi,
'@s\1': /src="https:\/\/(\d)\.bp\.blogspot\.com\//gi,
'@d1': /<div class="separator" style="clear: both; text-align: center;">/gi,
'@sw': /<span class="answer"><span class="answer"><br \/><\/span>/gi, 
'@sp': /<span class="answer"><span class="answer">/gi,
'@ac': /align="center" /gi,
'@al': /align="left"/gi,
'@ar': /align="right"/gi,
'@cp\1': /cellpadding=("?\d*"? )/gi,
'@cs\1': /cellspacing=("?\d*"? )/gi,
'@tb': /<tbody>/gi,
'@st': /style="/gi,
'@ml': /margin-left: /gi,
'@mr': /margin-right: /gi,
'@tc': /"text-align: center;"/gi,
'@t:': /text-align: center;"/gi,
'@tl': /"text-align: left;"/gi,
'@tr': /"text-align: right;"/gi,
'@sa': /<span class="answer">/gi,
'@c1': /class="tr-caption-container" /gi,
'@c2': /class="tr-caption" /gi,
'@/t': /<\/table>/gi,
'@t/': /<\/tbody>/gi,
'@/r': /<\/td><\/tr>/gi,
'@w\1': /width="(\d*)" /gi,
'@h\1': /height="(\d*)" /gi,
'@bs': /<br \/><\/span><\/span><br \/>/gi,
'@s/': /<\/span><\/span><br \/>/gi,
'@/s': /<\/span><\/span>/gi,
'@\\s': /<\/span>/gi,
'@ts': /<table /gi,
'@a/': /\/><\/a>/gi,
'@r/': /<tr><td /gi,
'@/b': /<br \/>/gi,
'@au': /auto; /gi,
'@b\1': /border="(\d*)"/gi,
'@n\1': /anchor="(\d*)"/gi,
'@d2': /<div class="separator"/gi,
'@/d': /<tr><td /gi,
'@da': /<\/a><\/div>/gi,
'@j/': /\.jpg" \/>/gi,
'@p/': /\.png" \/>/gi,
'@g/': /\.gif" \/>/gi,
'@j.': /\.jpg" /gi,
'@p.': /\.png" /gi,
'@g.': /\.gif" /gi,
'@im': /;"><img /gi,
'@sr': /src="'/gi,
'@s=': /src="/gi,
'@/a': /><a href=/gi,
'@d/': /<\/div><br>/gi,
'@b/': /<br>/gi, 
'@/p': /<p><\/p>/gi,
'@\\p': /<\/p>/gi,
'@p-': /<p>/gi,
'@/i': /><i>/gi,
'@\1': /\/s\d*0\//gi,

'&lt;': /</g , // encode html entity 
'&gt;': />/g   // endcode html entity 

};
editor.on( 'paste', function( evt ) {
    for (k in hArray) 
      evt.data.dataValue = evt.data.dataValue
            .replace( hArray[k], k );          
  });  
  </script>

slo

John Boe
  • 3,501
  • 10
  • 37
  • 71