Reply To: swap text with specific paragraph style

#88510

Your second example is well prepaired, thank you. Then: All Caps is set to ‘City’, but not to ‘Listing’.

So I decide to compare the acutal applied paragraph style with the style of the previous paragraph.

Try this one:

(function () {
  var curDoc = app.documents[0],
  allParas = curDoc.stories.everyItem().paragraphs.everyItem().getElements(),
  p,
  curPara,
  prevPara,
  pStyleName;

  for (p = 0; p < allParas.length; p++) {
    curPara = allParas[p];
    prevPara = allParas[p-1];
    pStyleName = curPara.appliedParagraphStyle.name;
    if (pStyleName == "COMPANY NAME" && (prevPara.appliedParagraphStyle.name == "LISTING TYPE" || prevPara.appliedParagraphStyle.name == "Listing type no space")) {
      allParas[p].appliedParagraphStyle = "COMPANY NAME - No space above";
    }
    else if (pStyleName == "LISTING TYPE" && allParas[p-1].appliedParagraphStyle.name == "CITY") {
      allParas[p].appliedParagraphStyle = "Listing type no space";
    }
  }
}());

Kai

This article was last modified on September 20, 2016

Comments (0)

Loading comments...