//DESCRIPTION: convert footnotes to dynamic (cross-referenced) endnotes // Peter Kahrel -- www,kahrel.plus.com #target indesign; // Only CS4 and later if (parseInt (app.version) < 6) exit (); foot_to_end (app.documents[0], 'endnote___'); //----------------------------------------------------------------------------------------------- function foot_to_end (doc, stylename) { var endnote, endnote_link, cue; add_styles (stylename); var cr_format = doc.crossReferenceFormats.item (stylename); var p_style = doc.paragraphStyles.item (stylename); var story = find_story (doc); var footn = story.footnotes; for (var i = 0; i < footn.length; i++) { story.insertionPoints[-1].contents = '\r'; var endnote = footn[i].texts[0].move (LocationOptions.after, story.insertionPoints[-1]); endnote.applyParagraphStyle (p_style, false); var endnote_link = doc.paragraphDestinations.add (endnote.insertionPoints[0]); var cue = doc.crossReferenceSources.add (footn[i].storyOffset, cr_format); doc.hyperlinks.add (cue, endnote_link, {visible: false}); } delete_notemarkers (doc); doc.crossReferenceSources.everyItem().update(); } function find_story (doc) { app.findGrepPreferences = app.changeGrepPreferences = null; app.findChangeGrepOptions.includeFootnotes = false; app.findGrepPreferences.findWhat = '~F'; var fn = doc.findGrep (); if (fn.length > 0) return fn[0].parentStory; else exit (); } function delete_notemarkers (doc) { app.findGrepPreferences = app.changeGrepPreferences = null; app.findChangeGrepOptions.includeFootnotes = true; app.findGrepPreferences.findWhat = '~F'; doc.changeGrep (); } function add_styles (n) { try { var char_style = app.activeDocument.characterStyles.add ({name: n}); char_style.position = Position.superscript; } catch (_){}; try { var par_style = app.activeDocument.paragraphStyles.add ({name: n}); par_style.bulletsAndNumberingListType = ListType.numberedList; } catch (_){}; try { var cr = app.activeDocument.crossReferenceFormats.add ({name: n}); cr.appliedCharacterStyle = app.activeDocument.characterStyles.item (n); cr.buildingBlocks.add (BuildingBlockTypes.paragraphNumberBuildingBlock); } catch (_){} }