PerfectPrepText: A smart way to style local formatting
One of the most popular free scripts for InDesign, preptext.jsx, was written by our own InDesignSecrets contributor Theunis DeJong, aka “Jongware.” He wrote it a few years ago, seemingly on the fly, in response to a plea for help from an InDesign user on the Adobe InDesign User-to-User forum. Preptext.jsx applies character styles to text with local formatting (bolds, italics, superscripts, and a few others) so you can retain the formatting when you apply your own paragraph styles or when you export to EPUB. It goes through the active story in just a few seconds, seeking out locally-styled text, creating the character styles (yes!) for you as needed and applying them throughout.
The problem is that preptext.jsx sometimes does too good of a job, creating and applying character styles to every instance of bold (or italic, or all-small caps, etc.) text, even if it’s not locally-formatted; that is, even if the formatting is part of the paragraph style applied to the text. Jongware says that’s because his script is designed to be run before you apply any InDesign styles, like when you first import a Word file and opt to delete styles but retain local formatting (you’ll find this option in the Word Import Options dialog box). But sometimes I forget, and need to run it after.
For example, I’ll often want to run Jongware’s script at this point, when I have some basic paragraph styles already applied ? Headline and Body ? but haven’t yet built up any character styles. The italic and small caps etc. you see in the sample are all locally formatted.
After I run preptext.jsx, it looks the same, except now we have a bunch of character styles (yay!) that have been applied to the locally-formatted text (yay!)
BUT: Take a look at my insertion point in the headline in the second screen shot. Do you see how the script created and applied the Bold character style to it? Even though the bold text wasn’t locally formatted?the Head paragraph style uses a bold typeface? That’s a potential problem. What if you edit the Head style so it used a non-Bold typeface? This text would still be bold, because of the character style applied to it.
Even if you never need to edit the paragraph styles, this “double-hit” of style sheets makes editing EPUBs or HTML files exported from affected files very difficult. Look at how the headline text in this exported file has both paragraph style classes and span (character style) classes for the same bit of text, “An Introduction to”:
Just as in the live InDesign file, if you decide that you want your CSS for the Head style to not be bold, you’d have to remember to go back to the HTML file and strip out all the superfluous span classes affecting the Head paragraphs too.
I asked my friend and über-scripter Peter Kahrel if he could help me out. Peter’s no longer doing freelance scripting, but in his off-hours, over a period of a few days (and a few versions he sent over), he came up with a solution! I’m calling it PerfectPrepText. It doesn’t replace Jongware’s wonderful preptext.jsx, it’s more of a prologue and epilogue to it.
How PerfectPrepText Fixes the Problem
Peter’s add-on to Jongware’s script deconstructs the story temporarily; first removing (he calls it “neutralizing”) the paragraph styles, then runs preptext.jsx (you need to have the preptext.jsx script at the same level as Peter’s somewhere in your InDesign scripts folder), then reasserts the original paragraph styles. I asked Peter to give me two versions of his script, the first called PerfectPrepText_Ask.jsx that asks what step you want to do, like this:
The steps would be:
- Run PerfectPrepText_Ask.jsx to neutralise the styles
- Run preptext.jsx (or any other style mapper) to create and apply character styles, and optionally do other things to the text while in this weird limbo state
- Run PerfectPrepText_Ask.jsx again to restore the styles?it remembers what gets applied where, somehow
And then for the rest of us who would prefer not to have a heart attack seeing all our styling “neutralised” in Step 1, Peter made an “unattended mode” version called PerfectPrepText_Do.jsx that zips through all three steps on its own. It still requires that you have the preptext.jsx script in your scripts folder (at the same level) but you don’t need to run it yourself.
I ran PerfectPrepText, and here’s the “After” on the same bit of text I started with at the top. All the character styles were created and applied to the locally-formatted text only. Notice how the word “Introduction” in the headline (where my cursor is) has no character style applied to it. Yay!
And the proper styling goes all the way through to EPUB/HTML export, too ? no extraneous <span> classes in the <p> class:
Peter doesn’t have a Donate button on his web site, but he said he just wanted to help support InDesignSecrets. Thank you Peter! And I have to mention that if you need more oomph, David’s PowerStyles plug-in does the same intelligent creation/application of character styles to locally-formatted text, plus it has many other useful text styling features. If you haven’t checked out the free trial yet, you really should ? it’s pretty cool.
Meanwhile, you can download PerfectPrepText.zip from our web site ? it contains three files: The _Ask and _Do versions of PerfectPrepText, and preptext.jsx (Thank you Jongware!)