Search code examples
adobe-indesign

Reverse character formation in indesign


So what I'm doing right now is surfing the text to find the following mark for footnotes: .15 and I'd like to change it to 15. where 15 becomes superscript. Is there a way to do this using a keybind and possibly GREP? I can apply a new paragraph style that involves grep, just not sure how to make it swap the locations. Also, I can't auto-search this, because there's other instances where .15 shouldn't be swapped. So I just wanna select the format .number and have that selection swap to number. and change number to superscript.


Solution

  • Slighty modified:

    #target indesign
    app.findGrepPreferences = app.changeGrepPreferences = null;
    app.findGrepPreferences.findWhat = "(\\.)(\\d+)";
    app.changeGrepPreferences.changeTo = "$2$1";
    var 
        mTarget = app.activeDocument,
        mFound = mTarget.findGrep(),
        cText;
    //
    while (cText = mFound.pop())
        if (checkCondition(cText)) 
            doJob(cText);
    
    alert ("No more found. Done.");
    app.findGrepPreferences = app.changeGrepPreferences = null;
    //
    function checkCondition (testText) {
        if (testText.appliedParagraphStyle.name == "pstyle")
        return true;
        else return false;
        }
    function doJob (testText) {
        testText.showText();
        if (!confirm("Replace?")) return;
        testText.changeGrep();
        testText.characters.itemByRange(0,-2).position = Position.SUPERSCRIPT;
        }
    

    It is asking before change ("No" means go to next).

    Watch condition set ==> applied paraStyle.name == "pstyle"