How can I remove italic and bold styling from all footnote references in an InDesign document using ExtendScript?

StackOverflow https://stackoverflow.com/questions/11038591

Pregunta

I'm trying to remove bold and italic styling from footnote references in an InDesign document using ExtendScript. By footnote references, I mean the little number that appears in the main text. That is, I want to strip the italic and boldness from that little number, not from the actual footnote. Here is my attempt. It does exactly the opposite of what I want, meaning it strips the actual footnote from its italic and boldness, but does not strip the little number in the main text.

var document = app.activeDocument,
    stories = document.stories,
    nbStories = stories.length,
    story,
    footnotes,
    nbFootnotes,
    footnote,
    texts,
    nbTexts,
    text,
    i,
    j,
    k;
  for (i = 0; i < nbStories; i += 1) {
    story = stories[i];
    footnotes = story.footnotes;
    nbFootnotes = footnotes.length;
    for (j = 0; j < nbFootnotes; j += 1) {
      footnote = footnotes[j];
      texts = footnote.texts;
      nbTexts = texts.length;
      for (k = 0; k < nbTexts; k += 1) {
        text = texts[k];
        text.fontStyle = "Regular";
      }
    }
  }

How can I achieve exactly the opposite? (i.e strip only the little number in the main text but not the actual footnote)

¿Fue útil?

Solución

Rather than looping through all the stories, I may recommend you to use GREP via scripting. The footnote marker pattern is "~F". This will catch both in the text markers and thos in the bottom caption. To specifically target in the text footnote markers you can restreign teh pattern to only consider markers which follow any character. Once that done, you get an array of footnote markers onto which you can call changeGrep to get your markers stylized as you wished. You have to set a "note" character style to get this snippet working.

function editFootNotesMarkers()

{ var allresults, result, doc, characterStyle;

if ( !app.documents.length){ return; }
doc = app.activeDocument;

characterStyle = doc.characterStyles.itemByName ("note");
if ( !characterStyle.isValid){ return; }

app.findGrepPreferences.findWhat = "(?<=.)~F";
app.changeGrepPreferences.appliedCharacterStyle = characterStyle;

doc.changeGrep();

alert('done');

}

editFootNotesMarkers();

Of course that can be achieved without any scripting ;)

Loic

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top