Convert text to footnotes with " * " reference marker

Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Convert text to footnotes with " * " reference marker

Viewing 1 reply thread
  • Author
    Posts
    • #103956
      Aman Mittal
      Member

      Hi,

      I am trying to use the following script to convert all those text which have ” * ” to footnotes:

      var
      myDoc = app.activeDocument,
      mStory = app.selection[0].texts[0].parentStory,
      mEndNotes = myDoc.textFrames.add( {name:”EndNotes”} ),
      k, len, cIP, currPara, currFoot, mMarkers;

      app.findGrepPreferences = app.changeGrepPreferences = null;
      //———————————————
      // edit doc.footnoteOption here
      with (myDoc.footnoteOptions)
      {
      showPrefixSuffix = FootnotePrefixSuffix.PREFIX_SUFFIX_BOTH;
      prefix = “[“;
      suffix = “]”;
      separatorText = “\t”;
      markerPositioning = FootnoteMarkerPositioning.NORMAL_MARKER;
      }
      //————————————————————
      // move endnotes to a separate textFrame
      for (k=mStory.paragraphs.length – 1; k >=0; k–)
      {
      if (mStory.paragraphs[k].contents.search(/^\[\d+\]/) == 0)
      {
      currPara = mStory.paragraphs[k].move(LocationOptions.AT_BEGINNING, mEndNotes.parentStory);
      currPara.words[0].remove();
      }
      }
      //————————————–
      // create footnote markers
      app.findGrepPreferences.findWhat = “\*+”;
      mMarkers = mStory.findGrep();
      len = mMarkers.length;
      while (len–>0) {
      cIP = mMarkers[len].insertionPoints[0].index;
      mMarkers[len].remove();
      mStory.footnotes.add( LocationOptions.AFTER, mStory.insertionPoints[cIP] );
      }
      //——————————————————-
      // fill footnote contents with proper text
      for (k=0; k < mStory.footnotes.length; k++) {
      currFoot = mStory.footnotes[k];
      mEndNotes.paragraphs[0].texts[0].move(LocationOptions.AT_END, currFoot.texts[0]);
      if (mStory.footnotes[k].characters[-1].contents == “\r”) mStory.footnotes[k].characters[-1].remove();
      }

      mEndNotes.remove();

      However, the script does not seem to work. Could any one help me regarding the same? How do I make the script search * text references and put them as footnotes.

      Any help, would be greatly appreciated.

      Regards,

      Aman Mittal

    • #104071
      Aman Mittal
      Member

      Solved:

      var
      myDoc = app.activeDocument,
      mStory = app.selection[0].texts[0].parentStory,
      mEndNotes = myDoc.textFrames.add( {name:”EndNotes”} ),
      k, len, cIP, currPara, currFoot, mMarkers;

      app.findGrepPreferences = app.changeGrepPreferences = null;
      //———————————————
      // edit doc.footnoteOption here
      with (myDoc.footnoteOptions)
      {
      showPrefixSuffix = FootnotePrefixSuffix.PREFIX_SUFFIX_BOTH;
      prefix = “[“;
      suffix = “]”;
      separatorText = “\t”;
      markerPositioning = FootnoteMarkerPositioning.NORMAL_MARKER;
      }
      //————————————————————
      // move endnotes to a separate textFrame
      for (k=mStory.paragraphs.length – 1; k >=0; k–)
      {
      if (mStory.paragraphs[k].contents.search(/^\*+/) == 0)
      {
      currPara = mStory.paragraphs[k].move(LocationOptions.AT_BEGINNING, mEndNotes.parentStory);
      currPara.words[0].remove();
      }
      }
      //————————————–
      // create footnote markers
      app.findGrepPreferences.findWhat = “\\*+”;
      mMarkers = mStory.findGrep();
      len = mMarkers.length;
      while (len–>0) {
      cIP = mMarkers[len].insertionPoints[0].index;
      mMarkers[len].remove();
      mStory.footnotes.add( LocationOptions.AFTER, mStory.insertionPoints[cIP] );
      }
      //——————————————————-
      // fill footnote contents with proper text
      for (k=0; k < mStory.footnotes.length; k++) {
      currFoot = mStory.footnotes[k];
      mEndNotes.paragraphs[0].texts[0].move(LocationOptions.AT_END, currFoot.texts[0]);
      if (mStory.footnotes[k].characters[-1].contents == “\r”) mStory.footnotes[k].characters[-1].remove();
      }

      mEndNotes.remove();

Viewing 1 reply thread
  • You must be logged in to reply to this topic.
>