Skip to content

Instantly share code, notes, and snippets.

@milligramme
Created July 2, 2014 11:49
Show Gist options
  • Select an option

  • Save milligramme/0c6b93b785bbeaff8c9f to your computer and use it in GitHub Desktop.

Select an option

Save milligramme/0c6b93b785bbeaff8c9f to your computer and use it in GitHub Desktop.
(function () {
var doc = app.documents.add();
var c_style = doc.characterStyles.item("cyan").isValid ?
doc.characterStyles.item("cyan") :
doc.characterStyles.add({name:"cyan"});
c_style.fillColor = doc.colors.item('Cyan');
var p_style = doc.paragraphStyles.item("test").isValid ?
doc.paragraphStyles.item("test") :
doc.paragraphStyles.add({name:"test"});
var nsg_style = p_style.nestedGrepStyles.add();
nsg_style.grepExpression = "\\\d{3}";
nsg_style.appliedCharacterStyle = c_style;
var tf = doc.textFrames.add({geometricBounds: [10,10,90,120], contents:"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod 333 incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla 333. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."});
tf.parentStory.appliedParagraphStyle = p_style;
var para = tf.parentStory.paragraphs;
var tsr = tf.parentStory.textStyleRanges;
// alert([para.length, tsr.length]); // => 1
var reg = new RegExp(para[0].appliedParagraphStyle.nestedGrepStyles[0].grepExpression);
x = para[0].contents.split(reg)
alert(x.join("☗☗☗"));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment