2013-11-27 68 views
0

我正在InDesign 5中使用脚注。我设法将我的文本转换为脚注,但我的问题是他们在这个过程中失去了风格。脚本丢失文字样式的Indesign脚本

这是我使用的脚本:

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 = ["@[email protected]([\\s\\S]*?)@[email protected]", "@[email protected]([\\s\\S]*?)@[email protected]"]; 
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); 

脚注正确添加,他们刚刚失去了自己的风格。在使用该脚本之前,文本显示完美,但在脚本之后,脚注样式不见了。

这是XML输入的例子:

[email protected][email protected]<italic>Text</italic> More [email protected][email protected] 

我与InDesign中的脚本一个新手...我一直在寻找一个答案,尝试很多东西的,但不知为什么我就是不行。 :S 有什么帮助吗?谢谢:)

+0

是你的中间名“马丁”?这个问题*惊人地*类似于http://stackoverflow.com/questions/20235029/indesign-script-for-footnotes-losing-text-styles – usr2564301

+0

他与我合作哈哈! –

回答

1

这里是你的问题:

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

contents让你的纯文本只有a String or SpecialCharacters enumerator,其中 “串” 是从字面上理解为的Javascript字符串。

改为使用move方法(并且您还必须重写您的match行,因为它也适用于并返回纯Javascript字符串)。 move移动原生InDesign文本,并包含所有格式。