Copy link to clipboard
Copied
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
.contents.search(/^\[\d+\]/) == 0) {
currPara = mStory.paragraphs
.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
; mEndNotes.paragraphs[0].texts[0].move(LocationOptions.AT_END, currFoot.texts[0]);
if (mStory.footnotes
.characters[-1].contents == "\r") mStory.footnotes .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.
I have attached a snap for better clarity, as well.
Any help, would be greatly appreciated.
Regards,
Aman Mittal
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
...Copy link to clipboard
Copied
Hi Aman,
how do you know where the footnote text starts and ends?
Regards,
Uwe
Copy link to clipboard
Copied
All the footnotes start with " * " followed by a tab or space and end with a paragraph break.
Copy link to clipboard
Copied
Only one paragraph for one footnote?
And will it be always that the footnote text follows the * for the footnote marker in the main text as next paragraph?
Regards,
Uwe
Copy link to clipboard
Copied
Hi Uwe,
Firstly, thank you for taking interest in the topic and for being such a great sport.
Regarding the paragraphs, footnotes might contain more than one paragraph. however, if we are not able to find a solution which could cater to more than one paragraph then I would have to bring everything under a single paragraph.
Yes, the footnote text will always follow * as the foot note marker. Although, the above script can help in placing the [1], [2],.. footnote markers however, it does not seem to work for " * " markers when I change the GrepSearch for it.
Regards,
Aman
Copy link to clipboard
Copied
Hi Aman,
if the footnote's text would have its own paragraph style, then we could identify the text perfectly.
Important note on the Find code: Add the footnotes from the end of the found text to the beginning, because you are shuffling paragraphs around and the found text index will change if you move text after the first found entry.
Regards,
Uwe
Copy link to clipboard
Copied
Hi Uwe,
I understand your points. I am new to scripting thing so any idea where I should start to include your suggestions?
Regards,
Aman
Copy link to clipboard
Copied
Hi,
Maybe simpler [and cooler) to tell us Jarek [Jump_Over] wrote this code 4 years ago and play it replacing each * by an incremental numbering!
Best,
Michel, from FRIdNGE
Copy link to clipboard
Copied
Hi Michel,
Thank you for replying to the thread. I know that Jarek wrote this code and I had already talked to him regarding the same. He is right now pre-occupied with things so he could not help me with the script as I had asked for some other changes as well. However, this one change was in the pipeline so I though of consulting with other experts, here.
Regards,
Aman
Copy link to clipboard
Copied
Hey Uwe (Laubender​),
How are you? I hope the message finds your in good health and stead. I apologize for replying so late and you might have forgotten about the above discussion.
In brief, we talked about using Jump_Over​ Convert Text To Footnotes script having the restriction of converting just one paragraph break to a footnote. And, you had raised a relevant quesion of those notes which might have many paragraph break and told me that we could apply those through the script as well, if we hook the notes with a unique style.
With regard to the above discussion, If I am able to distinguish the notes with a particular paragraph style so that it takes into consideration more than one paragraph break into consideration for converting text to footnotes, then, how would we change the script to do the same?
I would be grateful to you if could assist me regarding the same, if you ever find spare time and consider this to be a fun activity. Hope to hear from you soon.
Regards,
Aman Mittal
Copy link to clipboard
Copied
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
{
currPara = mStory.paragraphs
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
mEndNotes.paragraphs[0].texts[0].move(LocationOptions.AT_END, currFoot.texts[0]);
if (mStory.footnotes
}
mEndNotes.remove();