nytimes / ice

track changes with javascript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IceCopyPastePlugin, before/afterPasteClean

jamienk opened this issue · comments

I'm not sure how to use these callbacks?

I have

{
   name: 'IceCopyPastePlugin',
   settings: {
   pasteType : 'formattedClean',
   preserve: 'p,a[href]',
   beforePasteClean : function (ev)
   {
      //do something here?
   }
}

...can I manipulate the pasted contents inside the before/afterPasteClean function?

Yes, both callbacks receive the html before and after it was pasted, and expects that you return some modified version of the html. Let me know if you have any more questions.

Got it -- I'm using this (from http://sujeetgholap.github.io/typesmart.js/) to make pasted quotes turn "smart":

afterPasteClean : function (ev)
{
    ev=ev+' ';//this turns it into a string, sometimes it's not a string?

    // Strategy :
    // 1) First replace all quotes following whitespace into opening ones.
    // 2) Then all those which are after any character into closing ones.
    // 3) Then remaining into opening ones.
    newev=ev.replace(/(\s)'/g, "$1\u2018") // Opening singles
        .replace(/(\s)"/g, "$1\u201c") // Opening doubles
        // After one or more whitespace.
        .replace(/(.)'/g, "$1\u2019") // Closing singles
        .replace(/(.)"/g, "$1\u201d") // Closing doubles
        .replace(/'/g, "\u2018") // Opening singles
        .replace(/"/g, "\u201c"); // Opening doubles

    return newev;   
}