从选定的文本生成脚注

发布于 2024-10-16 04:35:06 字数 701 浏览 7 评论 0原文

我正在尝试使用 ExtendScript 编写 InDesign 脚本。我希望脚本剪切选定的文本,插入脚注并将文本粘贴到脚注正文中。我尝试过的:

 function makeFootnoteOfSelection(){
   var fnText = app.activeDocument.selection[0];
         // this should actually clone the selected text, not reference it, because the next statement zaps it from memory
   app.activeDocument.selection[0].remove();  // works
   var fNote = app.activeDocument.selection[0].footnotes.add();  // works, adds an empty footnote with a reference
   fNote.contents = fnText.contents;
         // this replaces the reference number, I was hoping to retain it and just add the text
         // fNote.contents += fnText.contents; also replaces the reference number
}

I am trying to script InDesign using ExtendScript. I want the script to cut the selected text, insert a footnote and paste the text into the footnote body. What I have tried:

 function makeFootnoteOfSelection(){
   var fnText = app.activeDocument.selection[0];
         // this should actually clone the selected text, not reference it, because the next statement zaps it from memory
   app.activeDocument.selection[0].remove();  // works
   var fNote = app.activeDocument.selection[0].footnotes.add();  // works, adds an empty footnote with a reference
   fNote.contents = fnText.contents;
         // this replaces the reference number, I was hoping to retain it and just add the text
         // fNote.contents += fnText.contents; also replaces the reference number
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

飘过的浮云 2024-10-23 04:35:06

InDesign CS5:

function makeFootnoteOfSelection(){

  // Reference the selection
  var fnText = app.activeDocument.selection[0];

  // Add an empty footnote where the selected text is
  var fNote = app.activeDocument.selection[0].footnotes.add();

  // Move the selected text at the end of the empty footnote
  fnText.move(LocationOptions.AFTER, fNote.insertionPoints[-1]);
}

InDesign CS4:

function makeFootnoteOfSelection(){

  // Reference the selection
  var fnText = app.activeDocument.selection[0];

  //  Position of the text end
  var endPoint = fnText.length - 1;

  // Add an empty footnote where the selected text is
  var fNote = app.activeDocument.selection[0].footnotes.add();

  // Duplicate the selected text at the end of the empty footnote
  fnText.duplicate(LocationOptions.AFTER, fNote.insertionPoints[-1]);

  // Delete the old Text
  fnText.characters.itemByRange(0, endPoint).contents = "";
}

InDesign CS5:

function makeFootnoteOfSelection(){

  // Reference the selection
  var fnText = app.activeDocument.selection[0];

  // Add an empty footnote where the selected text is
  var fNote = app.activeDocument.selection[0].footnotes.add();

  // Move the selected text at the end of the empty footnote
  fnText.move(LocationOptions.AFTER, fNote.insertionPoints[-1]);
}

InDesign CS4:

function makeFootnoteOfSelection(){

  // Reference the selection
  var fnText = app.activeDocument.selection[0];

  //  Position of the text end
  var endPoint = fnText.length - 1;

  // Add an empty footnote where the selected text is
  var fNote = app.activeDocument.selection[0].footnotes.add();

  // Duplicate the selected text at the end of the empty footnote
  fnText.duplicate(LocationOptions.AFTER, fNote.insertionPoints[-1]);

  // Delete the old Text
  fnText.characters.itemByRange(0, endPoint).contents = "";
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文