javascript - InDesign: How can I get paragraph contents with its characterStyles? -
i'm trying write custom export script indesign (i have cc 9.2, target cs6).
when process paragraph, can paragraphstyle , content. don't understand is: how can content and characterstyles of content?
i'm looking @ docs, don't understand how can descend paragraph , find characterstyles , text parts applied.
if, instance, have paragraph following:
my nice paragraph.
i want know "my "
, " paragraph."
have style1, while "nice"
have style2.
the end result should like:
[ { text: "my ", style: "style1" }, { text: "nice", style: "style2" }, { text: " paragraph.", style: "style1" } ]
how can obtain information?
use textstylerange property of paragraph.
a textstylerange 1 single continuous range of text same formatting. not matter indesign whether formatting 'local' or applied through character style.
obligatory caveats:
- textstyleranges see all local formatting, whether or not applied through char style.
- textstylerange formatting not see grep styles.
- the last text range in paragraph may (and will) happily contain final return, any , all text in following paragraphs still have exact same formatting. if retrieve textstyleranges per paragraph, check each returned text contents presence of text after paragraph return. if contain paragraph return, optionally clip off excess text, , exit loop current paragraph.
very minimal example code:
tsr = app.selection[0].paragraphs[0].textstyleranges; text = []; (i=0; i<tsr.length; i++) text.push ('text: "'+tsr[i].contents+'", style: "'+tsr[i].appliedcharacterstyle.name+'"'); alert (text.join ('\r'));
Comments
Post a Comment