Making 'Smart Quotes' in (x)html
Removing (x)html vertical single- and double-quotes, replacing them with sloping single- and double-quotes, similar to the ‘smart quotes’ used by Word Processors.
Consider the short extract: “Hello” he said, “How’s your ‘phantom’ illness?” – this includes left and right double-quotes; left and right single-quotes (citation) and a plain apostrophe.
In html, these all render in vertical quotes unless they are specifically coded otherwise.
Left double-quotes can occur only at the start of a line or after a space. Right double-quotes can occur only before a space or at the end of a line. In html, the start or end of a line can be determined by > or < characters. Citations, the only occurrence of left single-quotes, can start only after a space.
Use “global” Search-&-replace to modify all html files in a given folder.
1. Search-&-replace for >" – replace these left double-quotes with >“
2. Search-&-replace for (space)" – replace these left double-quotes with (space)“
3. Search-&-replace for "(space) – replace these right double-quotes with ”(space)
4. Search-&-replace for "< – replace these right double-quotes with ”<
5. Some right-quotes will have been missed, when an actual space does not immediately follow it in the html code, so Search-&-replace for "& (where a or similar immediately follows the quote) – replace with &rdquo:&
6. Search-&-replace for ALL Apostrophe characters and replace them with ’ ...this replaces ALL single-quotes with right-sloping characters.
7. Now you need to find and replace the left-sloping ones. Search-&-replace for (space)’ – replace these with (space)‘
This does rely on your html code being “tight” and predictable, with no variances. You can’t have, for instance: ....end of sentence.</div> on one line but: ...end of sentence. (line break or space) </div> on another. There are also occasional instances of periods outside a quote rather than inside, so an extra check would be required to catch them, but I didn’t bother because I knew the content well enough to know that they didn’t occur.
I modified a 40-document book, 150k words, in ten minutes! Whoopee! I am still proof-reading, of course, to be sure that all instances were changed, but the worst that could happen is that one or two single- or double-quotes would remain as plain vertical ones. And the sloping quotes provide a much better reading experience.
Last edited by lindsayw; 09-22-2011 at 11:58 PM.
|