Because it’s been more than a week since I last opened myself up to scorn about my lack of scripting skillz, here’s a how-to for another semiautomated e-production task in BBEdit (or TextWrangler): renumbering navpoints in an NCX.
So, let’s say you have an NCX to which you need to add another navpoint, or from which you need to remove one. If the navMap has only four or five points, as in the screenshot below, renumbering by hand is no big deal.
If you’re looking at a book with, say, twenty points, or two hundred, though, forget it. How can we of the scriptless masses automate this vile task? Well, I’ve got it down to about half a minute.
With your NCX open, select Text > Remove Line Breaks.
- Under the window’s Text Options menu, turn off Soft Wrap Text, if it’s on. This makes it easier to see what you’re doing.
- Replace all
Now each navpoint is on its own line.
- Select all lines except the first one, and click Text > Add/Remove Line Numbers…
Fill out the dialog as shown and click “Number.” Now you have sequential numbers at the start of each line.
Hmm . . . See where this is going?
- Use a RegEx pattern to replace the playOrder values with the numbers you’ve just added. Depending on the source, some NCXs will use different patterns, but this is the pattern I have saved in my Find dialog:
- Viola! Your points are now renumbered.
You can either leave the list flat or reflow the XML to nest it again. If you’re using BBEdit 11, you may want to install Keith Bolland’s Reflow XML script and assign a shortcut to it; in pre-11 versions, Markup > Tidy > Reflow Document… will do it.
Go forth and use your powers for good.