Skip to main content
Participant
October 8, 2014
Question

Tagged text to footnotes after XML import

  • October 8, 2014
  • 0 replies
  • 219 views

Hi all,

I am close, I have found a solution on StackOverflow. However, guys there did not provide the final solution when all footnotes remain properly styled. Now I have the script below. It does the work properly but the styling is lost. It is possible to find that it have to move the founded part, not use it like the java String. Some guy recommended to change fn.texts[0].insertionPoints[-1].contents = fnText; to move instead contents. Of course, he has probably meant something more complicated. Any help very appreciated!

Application.prototype.main = function(){

if ( this.documents.length <= 0 ) return;

var tg = this.selection[0] || this.activeDocument;

if( 'appliedFont' in tg ) tg = tg.parent;

if( tg.constructor == TextFrame ){ tg = tg.parentStory ; }

if(! ('findGrep' in tg) ) return;

var fnPatterns = ["@FOOTNOTES_BEGIN@([\\s\\S]*?)@FOOTNOTES_END@", "@footnotes_begin@([\\s\\S]*?)@footnotes_end@"];

var count = 0;

for(patterCounter = 0; patterCounter < fnPatterns.length; patterCounter++){

    fnPattern = fnPatterns[patterCounter];

    var fnFinds = (function(){             

        this.findGrepPreferences = this.changeGrepPreferences = null;

            this.findGrepPreferences.findWhat = fnPattern;           

            var ret = tg.findGrep();

            this.findGrepPreferences = this.changeGrepPreferences = null;

        return ret;

    }).call(this);

    var fnFind, fnText, rg = new RegExp(fnPattern), ip, fnParent, fn, count;

    while( fnFind=fnFinds.pop() ){

        fnText = fnFind.contents.match(rg)[1];

        fnParent = fnFind.parent.getElements()[0];

        ip = fnFind.insertionPoints[0].index

        try {

            fnFind.remove();

            fn = fnParent.footnotes.add(LocationOptions.BEFORE, fnParent.insertionPoints[ip]);

            fn.texts[0].insertionPoints[-1].contents = fnText;

            ++count;

        }

            catch(_){}

    }

}

alert((count)? (count+" footnote(s) successfully added."): "No footnote added. Make sure you use the relevant pattern.");

}

app.doScript('app.main();', ScriptLanguage.javascript,

undefined, UndoModes.entireScript, app.activeScript.displayName);

This topic has been closed for replies.