View Single Post
Old 09-22-2011, 11:55 PM   #1
lindsayw
Author from pBook days
lindsayw is clearly one to watchlindsayw is clearly one to watchlindsayw is clearly one to watchlindsayw is clearly one to watchlindsayw is clearly one to watchlindsayw is clearly one to watchlindsayw is clearly one to watchlindsayw is clearly one to watchlindsayw is clearly one to watchlindsayw is clearly one to watchlindsayw is clearly one to watch
 
lindsayw's Avatar
 
Posts: 49
Karma: 10782
Join Date: Mar 2011
Location: Australia
Device: Kindle-3-Keyboard; 8" Android Tablet
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 >&quot; – replace these left double-quotes with >&ldquo;
2. Search-&-replace for (space)&quot; – replace these left double-quotes with (space)&ldquo;
3. Search-&-replace for &quot;(space) – replace these right double-quotes with &rdquo;(space)
4. Search-&-replace for &quot;< – replace these right double-quotes with &rdquo;<
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 &quot;& (where a &nbsp; or similar immediately follows the quote) – replace with &rdquo:&
6. Search-&-replace for ALL Apostrophe characters and replace them with &rsquo; ...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)&rsquo; – replace these with (space)&lsquo;

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.
lindsayw is offline   Reply With Quote