"SmartyPants" is a free web publishing plug-in for Movable Type, Blosxom, and BBEdit that easily translates plain ASCII punctuation characters into "smart" typographic punctuation characters.
smartquotes.py is an adaption of "SmartyPants" to Docutils.
John Gruber did all of the hard work of writing this software in Perl for Movable Type and almost all of this useful documentation. Chad Miller ported it to Python to use with Pyblosxom. Adapted to Docutils by Günter Milde.
Portions of the SmartyPants original work are based on Brad Choate's nifty MTRegex plug-in. Brad Choate also contributed a few bits of source code to this plug-in. Brad Choate is a fine hacker indeed.
Jeremy Hedley and Charles Wiltgen deserve mention for exemplary beta testing of the original SmartyPants.
Rael Dornfest ported SmartyPants to Blosxom.
SmartyPants license (3-Clause BSD license):
Copyright (c) 2003 John Gruber (http://daringfireball.net/) All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name "SmartyPants" nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
smartypants.py license (2-Clause BSD license):
smartypants.py is a derivative work of SmartyPants.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
This software is provided by the copyright holders and contributors "as is" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.
SmartyPants can perform the following transformations:
This means you can write, edit, and save your posts using plain old ASCII straight quotes, plain dashes, and plain dots, but your published posts (and final HTML output) will appear with smart quotes, em-dashes, and proper ellipses.
SmartyPants does not modify characters within <pre>, <code>, <kbd>, <math> or <script> tag blocks. Typically, these tags are used to display text where smart quotes and other "smart punctuation" would not be appropriate, such as source code or example markup.
If you need to use literal straight quotes (or plain hyphens and periods),
smartquotes
accepts the following backslash escape sequences to force
ASCII-punctuation. Mind, that you need two backslashes as Docutils expands it,
too.
Escape | Character |
---|---|
\\ | \ |
\\" | \" |
\\' | \' |
\\. | \. |
\\- | \- |
\\` | \` |
This is useful, for example, when you want to use straight quotes as foot and inch marks: 6\'2\" tall; a 17\" iMac.
For one thing, you might not care.
Most normal, mentally stable individuals do not take notice of proper typographic punctuation. Many design and typography nerds, however, break out in a nasty rash when they encounter, say, a restaurant sign that uses a straight apostrophe to spell "Joe's".
If you're the sort of person who just doesn't care, you might well want to continue not caring. Using straight quotes -- and sticking to the 7-bit ASCII character set in general -- is certainly a simpler way to live.
Even if you do care about accurate typography, you still might want to think twice before educating the quote characters in your weblog. One side effect of publishing curly quote characters is that it makes your weblog a bit harder for others to quote from using copy-and-paste. What happens is that when someone copies text from your blog, the copied text contains the 8-bit curly quote characters (as well as the 8-bit characters for em-dashes and ellipses, if you use these options). These characters are not standard across different text encoding methods, which is why they need to be encoded as characters.
People copying text from your weblog, however, may not notice that you're using curly quotes, and they'll go ahead and paste the unencoded 8-bit characters copied from their browser into an email message or their own weblog. When pasted as raw "smart quotes", these characters are likely to get mangled beyond recognition.
That said, my own opinion is that any decent text editor or email client makes it easy to stupefy smart quote characters into their 7-bit equivalents, and I don't consider it my problem if you're using an indecent text editor or email client.
One situation in which quotes will get curled the wrong way is when apostrophes are used at the start of leading contractions. For example:
'Twas the night before Christmas.
In the case above, SmartyPants will turn the apostrophe into an opening
secondary quote, when in fact it should be the RIGHT SINGLE QUOTATION MARK
character which is also "the preferred character to use for apostrophe"
(Unicode). I don't think this problem can be solved in the general case --
every word processor I've tried gets this wrong as well. In such cases, it's
best to inset the RIGHT SINGLE QUOTATION MARK
(’) by hand.
In English, the same character is used for apostrophe and closing secondary quote (both plain and "smart" ones). For other locales (French, Italean, Swiss, ...) "smart" secondary closing quotes differ from the curly apostrophe.
Il dit : "C'est 'super' !"
If the apostrophe is used at the end of a word, it cannot be distinguished from a secondary quote by the algorithm. Therefore, a text like:
.. class:: language-de-CH "Er sagt: 'Ich fass' es nicht.'"
will get a single closing guillemet instead of an apostrophe.
This can be prevented by use use of the RIGHT SINGLE QUOTATION MARK
in
the source:
- "Er sagt: 'Ich fass' es nicht.'" + "Er sagt: 'Ich fass’ es nicht.'"
educate_tokens()
generator as interface for Docutils.Class | smartchars |
Smart quotes and dashes |
Function | educate_tokens |
Return iterator that "educates" the items of text_tokens . |
Function | educateBackticks |
No summary |
Function | educateDashes |
Parameter: String (unicode or bytes). Returns: The text , with each instance of "--" translated to an em-dash character. |
Function | educateDashesOldSchool |
No summary |
Function | educateDashesOldSchoolInverted |
No summary |
Function | educateEllipses |
Parameter: String (unicode or bytes). Returns: The text , with each instance of "..." translated to an ellipsis character. |
Function | educateQuotes |
Parameter: - text string (unicode or bytes). - language (BCP 47 language tag.) Returns: The text , with "educated" curly quote characters. |
Function | educateSingleBackticks |
Parameter: String (unicode or bytes). Returns: The text , with `backticks' -style single quotes translated into HTML curly quote entities. |
Function | processEscapes |
No summary |
Function | smartyPants |
Main function for "traditional" use. |
Function | stupefyEntities |
Parameter: String (unicode or bytes). Returns: The text , with each SmartyPants character translated to its ASCII counterpart. |
Function | tokenize |
No summary |
Variable | default_smartypants_attr |
Undocumented |
Variable | options |
Undocumented |
Parameter: String (unicode or bytes).
Returns: The text
, with each instance of "--" translated to
an em-dash character.
Parameter: String (unicode or bytes).
Returns: The text
, with each instance of "--" translated to
an en-dash character, and each "---" translated to an em-dash character.
Parameter: String (unicode or bytes).
Returns: The text
, with each instance of "--" translated to
an em-dash character, and each "---" translated to an en-dash character. Two reasons why: First, unlike the en- and em-dash syntax supported by EducateDashesOldSchool(), it's compatible with existing entries written before SmartyPants 1.1, back when "--" was only used for em-dashes. Second, em-dashes are more common than en-dashes, and so it sort of makes sense that the shortcut should be shorter to type. (Thanks to Aaron Swartz for the idea.)
Parameter: String (unicode or bytes).
Returns: The text
, with each instance of "..." translated to
an ellipsis character.
Example input: Huh...? Example output: Huh…?
BCP 47
language tag.)Returns: The text
, with "educated" curly quote characters.
Example input: "Isn't this fun?" Example output: “Isn’t this fun?“;
Parameter: String (unicode or bytes).
Returns: The text
, with after processing the following backslash
escape sequences. This is useful if you want to force a "dumb" quote or other character to appear.
Escape Value ------ ----- \ \ " " ' ' . . - - ` `
Parameter: String (unicode or bytes).
Returns: The text
, with each SmartyPants character translated to
its ASCII counterpart.
Example input: “Hello — world.” Example output: "Hello -- world."
Parameter: String containing HTML markup. Returns: An iterator that yields the tokens comprising the input
string. Each token is either a tag (possibly with nested, tags contained therein, such as <a href="<MTFoo>">, or a run of text between tags. Each yielded element is a two-element tuple; the first is either 'tag' or 'text'; the second is the actual value.