Indesign Script para notas al pie que pierden estilos de texto

I'm working with footnotes in InDesign 5 . I managed to convert my text to footnotes, but my problem is that they lose the style in the process.

This is the script I'm using :

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);

The footnotes are added correctly, they just lose their style. Before using the script, text is shown perfect, but after the script, the footnote styles are gone.

This is an example of the xml input :

....text@FOOTNOTES_BEGIN@<italic>Text</italic> More text@FOOTNOTES_END@

I'm a newbie with InDesign scripting... I'd been looking for an answer, trying lots of stuffs, but somehow I just can't do it. :S Any help? Thanks :)

preguntado el 27 de noviembre de 13 a las 06:11

Is your middle name "Martin"? This question is sorprendentemente similar a stackoverflow.com/questions/20235029/… -

He works with me lol! -

1 Respuestas

Este es tu problema:

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

contents gets you the plain text , solamente: a String or SpecialCharacters enumerator, where "String" is to be taken literally as a Javascript cadena.

Use el move method instead (and you have to rewrite your match line as well, since it also works on, and returns, plain Javascript strings). move moves native InDesign text around, with all formatting included.

respondido 28 nov., 13:22

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.