Convert text to footnotes with " * " reference marker
Learn / Forums / InDesign Add-ons (Scripts, Scripting, and Plug-ins) / Convert text to footnotes with " * " reference marker
- This topic has 1 reply, 1 voice, and was last updated 5 years, 9 months ago by Aman Mittal.
-
AuthorPosts
-
-
May 24, 2018 at 4:29 am #103956Aman MittalMember
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
-
May 27, 2018 at 10:51 pm #104071Aman MittalMember
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();
-
-
AuthorPosts
- You must be logged in to reply to this topic.