我正在使用InDesign 5中的脚注。我设法将我的文本转换为脚注,但我的问题是他们在这个过程中失去了风格。
这是我正在使用的脚本:
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);
脚注添加正确,它们只是失去了风格。在使用脚本之前,文本显示完美,但在脚本之后,脚注样式消失了。
这是xml输入的一个示例:
....text@FOOTNOTES_BEGIN@<italic>Text</italic> More text@FOOTNOTES_END@
我是InDesign脚本的新手......我一直在寻找答案,尝试了很多东西,但不知怎的,我不能这样做。 :S 有帮助吗?谢谢:))
答案 0 :(得分:2)
这是你的问题:
fn.texts[0].insertionPoints[-1].contents = fnText;
contents
为您提供纯文本 :a String or SpecialCharacters enumerator,其中“String”字面意思为 Javascript 字符串。< / p>
使用move
方法(并且您还必须重写match
行,因为它也可以处理并返回普通的Javascript字符串)。 move
移动原生InDesign文本,包含所有格式。