簡體   English   中英

腳注丟失文本樣式的Indesign腳本

[英]Indesign Script for footnotes losing text styles

我在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有什么幫助嗎? 謝謝 :)

這是你的問題:

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

contents 僅為您提供純文本: String或SpecialCharacters枚舉器 ,其中“String”字面上將被視為Javascript字符串。

改為使用move方法(你也必須重寫你的match行,因為它也可以工作,並返回普通的Javascript字符串)。 move各地移動本地InDesign的文字,與包括所有格式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM