用于脚注丢失文本样式的Indesign脚本 [英] Indesign Script for footnotes losing text styles
问题描述
我正在InDesign 5中使用脚注。我设法将文本转换为脚注,但是我的问题是它们在此过程中失去了样式。
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.
这是xml输入的示例:
This is an example of the xml input :
....text@FOOTNOTES_BEGIN@<italic>Text</italic> More text@FOOTNOTES_END@
我是InDesign脚本的新手...我一直在寻找一个答案,尝试很多东西,但是我却无法做到。 :S
有帮助吗?谢谢:)
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 :)
推荐答案
这是您的问题:
fn.texts[0].insertionPoints[-1].contents = fnText;
内容
为您提供纯文本仅:一个String或SpecialCharacters枚举器,其中 String应该直接作为 Javascript 字符串使用。
contents
gets you the plain text only: a String or SpecialCharacters enumerator, where "String" is to be taken literally as a Javascript string.
使用 move
方法代替(并且您还必须重写 match
行,因为它也可以处理普通的Javascript字符串并返回)。 移动
移动本地InDesign文本,包括所有格式。
Use the 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.
这篇关于用于脚注丢失文本样式的Indesign脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!