Re: new plugin: smartypants.py, smart quotes for pyblosxom

Lance Weber <lance-kMc2rFPYsS/[email protected]>
Newsgroups gmane.comp.web.pyblosxom.user
Message-ID <[email protected]>
I took a quick look at the code but didn't install/run it because my 
current setup relies on the textile formatter and quotes have 
significance in several of the textile regex patterns. Some thoughts off 
the top of my head:

1) Any particular rationale for using numeric values in smarty_pants 
attributes as opposed to more descriptive string values such as "off", 
"on", "old", "invert" and "stupefy"?

2) Personally, I'd prefer a plugin that forced you to explicitly tag 
your text with regex's for special quote processing (like ^" ^') rather 
than globally munging my quotes. Hey, if you're anal^H^H^H^H 
perfectionist enough to want fancy quoting, using an extra marker 
character shouldn't be a big deal ;)



Chad Miller wrote:

>URL: http://wiki.chad.org/SmartyPantsPy
>
>It's my first plugin, so I'd love to get feedback.  Once I'm relatively
>sure that I'm doing the right things, I'll register it on the web-site.
>
>Please reply to me directly as I am not subscribed to the -users list.
>
>							- chad
>
>
>----
>smartypants.py
>
>SmartyPants ported to Python
>
>   Ported by [1]Chad Miller Copyright (c) 2004 Chad Miller
>
>   original [2]SmartyPants by [3]John Gruber Copyright (c) 2003 John
>   Gruber
>
>Synopsis
>
>   A smart-quotes plugin for [4]Pyblosxom.
>
>   The original "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 HTML
>   entities.
>
>   This software, smartypants.py, endeavours to be a functional port of
>   SmartyPants to Python, for use with [5]Pyblosxom.
>
>Description
>
>   SmartyPants can perform the following transformations:
>     * Straight quotes ( " and ' ) into "curly" quote HTML entities
>     * Backticks-style quotes (``like this'') into "curly" quote HTML
>       entities
>     * Dashes (-- and ---) into en- and em-dash entities
>     * Three consecutive dots (... or . . .) into an ellipsis entity
>
>   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.
>
>Backslash Escapes
>
>   If you need to use literal straight quotes (or plain hyphens and
>   periods), SmartyPants accepts the following backslash escape sequences
>   to force non-smart punctuation. It does so by transforming the escape
>   sequence into a decimal-encoded HTML entity:
>
>   (FIXME: table here.)
>
>   This is useful, for example, when you want to use straight quotes as
>   foot and inch marks: 6'2" tall; a 17" iMac.
>
>Options
>
>   For Pyblosxom users, the smartypants_attributes attribute is where you
>   specify configuration options.
>
>   Numeric values are the easiest way to configure SmartyPants' behavior:
>
>   "0"
>          Suppress all transformations. (Do nothing.)
>
>   "1"
>          Performs default SmartyPants transformations: quotes (including
>          ``backticks'' -style), em-dashes, and ellipses. "--" (dash
>          dash) is used to signify an em-dash; there is no support for
>          en-dashes.
>
>   "2"
>          Same as smarty_pants="1", except that it uses the old-school
>          typewriter shorthand for dashes: "--" (dash dash) for
>          en-dashes, "---" (dash dash dash) for em-dashes.
>
>   "3"
>          Same as smarty_pants="2", but inverts the shorthand for dashes:
>          "--" (dash dash) for em-dashes, and "---" (dash dash dash) for
>          en-dashes.
>
>   "-1"
>          Stupefy mode. Reverses the SmartyPants transformation process,
>          turning the HTML entities produced by SmartyPants into their
>          ASCII equivalents. E.g. "&#8220;" is turned into a simple
>          double-quote ("), "&#8212;" is turned into two dashes, etc.
>
>   The following single-character attribute values can be combined to
>   toggle individual transformations from within the smarty_pants
>   attribute. For example, to educate normal quotes and em-dashes, but
>   not ellipses or ``backticks'' -style quotes:
>
>   py['smartypants_attributes'] = "1"
>
>   "q"
>          Educates normal quote characters: (") and (').
>
>   "b"
>          Educates ``backticks'' -style double quotes.
>
>   "B"
>          Educates ``backticks'' -style double quotes and `single'
>          quotes.
>
>   "d"
>          Educates em-dashes.
>
>   "D"
>          Educates em-dashes and en-dashes, using old-school typewriter
>          shorthand: (dash dash) for en-dashes, (dash dash dash) for
>          em-dashes.
>
>   "i"
>          Educates em-dashes and en-dashes, using inverted old-school
>          typewriter shorthand: (dash dash) for em-dashes, (dash dash
>          dash) for en-dashes.
>
>   "e"
>          Educates ellipses.
>
>   "w"
>          Translates any instance of &quot; into a normal double-quote
>          character. This should be of no interest to most people, but of
>          particular interest to anyone who writes their posts using
>          Dreamweaver, as Dreamweaver inexplicably uses this entity to
>          represent a literal double-quote character. SmartyPants only
>          educates normal quotes, not entities (because ordinarily,
>          entities are used for the explicit purpose of representing the
>          specific character they represent). The "w" option must be used
>          in conjunction with one (or both) of the other quote options
>          ("q" or "b"). Thus, if you wish to apply all SmartyPants
>          transformations (quotes, en- and em-dashes, and ellipses) and
>          also translate &quot; entities into regular quotes so
>          SmartyPants can educate them, you should pass the following to
>          the smarty_pants attribute:
>
>Caveats
>
>Why You Might Not Want to Use Smart Quotes in Your Weblog
>
>   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 I 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 HTML entities 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 HTML
>   entities.
>
>   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.
>
>Algorithmic Shortcomings
>
>   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 single-quote, when in fact it should be a closing one. 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 use the proper HTML entity for closing single-quotes (&#8217;) by
>   hand.
>
>Bugs
>
>   To file bug reports or feature requests (other than topics listed in
>   the Caveats section above) please send email to:
>   [6]mailto:[email protected]
>
>   If the bug involves quotes being curled the wrong way, please send
>   example text to illustrate.
>
>To Do list
>
>     * Provide a function for use within templates to quote anything at
>       all.
>
>Version History
>
>   1.5_1.0: Tue, 09 Mar 2004 08:08:35 -0500
>
>          + Initial release
>
>Version Information
>
>   Version numbers will track the [7]SmartyPants version numbers, with
>   the addition of an underscore and the smartypants.py version on the
>   end.
>
>Authors
>
>   [8]John Gruber did all of the hard work of writing this software in
>   Perl for [9]Movable Type and almost all of this useful documentation.
>   [10]Chad Miller ported it to Python to use with [11]Pyblosxom.
>
>Additional SmartyPants Credits
>
>   Portions of the SmartyPants plug-in are based on Brad Choate's nifty
>   MTRegex plug-in. [12]Brad Choate also contributed a few bits of source
>   code to SmartyPants. Brad Choate is a fine hacker indeed.
>
>   [13]Jeremy Hedley and [14]Charles Wiltgen deserve mention for
>   exemplary beta testing of the original SmartyPants.
>
>   [15]Rael Dornfest ported SmartyPants to Blosxom.
>
>Copyright and License
>
>   [16]SmartyPants 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:
>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.
>
>References
>
>   1. http://web.chad.org/
>   2. http://daringfireball.net/projects/smartypants/
>   3. http://daringfireball.net/
>   4. http://roughingit.subtlehints.net/pyblosxom
>   5. http://roughingit.subtlehints.net/pyblosxom
>   6. mailto:[email protected]
>   7. http://daringfireball.net/projects/smartypants/
>   8. http://daringfireball.net/
>   9. http://www.movabletype.org/
>  10. http://web.chad.org/
>  11. http://roughingit.subtlehints.net/pyblosxom
>  12. http://bradchoate.com/
>  13. http://antipixel.com/
>  14. http://playbacktime.com/
>  15. http://raelity.org/
>  16. http://daringfireball.net/projects/smartypants/
>
>
>  
>



-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of
GenToo technologies. Learn everything from fundamentals to system
administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.