Tuesday, May 1, 2012

Using GREP to eliminate warnings—and reveal errors—in BBEdit

If you're making changes directly to your XHTML documents, it's a good idea to check their syntax before compiling and finishing your EPUB files. This helps weed out the most common and difficult-to-find errors: typos.

In BBEdit, choose Markup > Check > Document Syntax to see if your XHTML file is valid. BBEdit will quickly sift through and alert you to any problems.

If you export EPUB from InDesign, you may get a lot of warnings about spaces being recommended before trailing spaces.

spaceWarnings

They're quite right: if you have a all-in-one element like the img element or link element, you are allowed to write this:

<img src="image.jpg" alt="image description"/>

But it's recommended that you add a space before that trailing slash (after the last attribute and value):

space before a closing bracket

The problem, and it's minor but annoying, is that all those warnings hide the real problems. (The errors are there, but you have to scroll down to find them. And you don't get that satisfying "No errors were found" message.) One temporary solution is to uncheck the Warnings box as shown in the above screenshot.

The other, more permanent, solution is to add the missing space so you don't get any warnings. I use GREP for this:

Search for (\S)/> (that is, any instance of a closing slash and closing bracket without a preceding space. Another way to interpret that GREP would be that you're finding anything that's NOT a space followed by a closing slash and closing bracket.)

And replace it with \1 /> (whatever came before the closing slash and bracket, a space, and the closing slash and bracket)

Now when you check syntax, you'll only see the real errors (here, a classic one for me: mismatched p's and div's):

errorsonly



I know this is a tiny and minor thing, but I hope it will be helpful to a few, and maybe even get folks who are interested in but scared of GREP to start with something small.

No comments:

Post a Comment

More of my books