smartypants-1.6.0.3/0000755000175500010010000000000011173356153012265 5ustar MeNonesmartypants-1.6.0.3/COPYING0000700000175500010010000000564411123231464013312 0ustar MeNoneSmartyPants 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. *** Changes and additions made to create this distribution are released into the public domain. smartypants-1.6.0.3/lib/0000755000175500010010000000000011173356153013033 5ustar MeNonesmartypants-1.6.0.3/lib/smartypants.py0000700000175500010010000007075011123224303015756 0ustar MeNone#!/usr/bin/python r""" ============== smartypants.py ============== ---------------------------- SmartyPants ported to Python ---------------------------- Ported by `Chad Miller`_ Copyright (c) 2004, 2007 Chad Miller original `SmartyPants`_ by `John Gruber`_ Copyright (c) 2003 John Gruber Synopsis ======== A smart-quotes plugin for Pyblosxom_. The priginal "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 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 ``
``, ````, ````,
```` or ``

He said, "'Quoted' words in a larger quote."

str = re.sub(r""""'(?=\w)""", """“‘""", str) str = re.sub(r"""'"(?=\w)""", """‘“""", str) # Special case for decade abbreviations (the '80s): str = re.sub(r"""\b'(?=\d{2}s)""", r"""’""", str) close_class = r"""[^\ \t\r\n\[\{\(\-]""" dec_dashes = r"""–|—""" # Get most opening single quotes: opening_single_quotes_regex = re.compile(r""" ( \s | # a whitespace char, or   | # a non-breaking space entity, or -- | # dashes, or &[mn]dash; | # named dash entities %s | # or decimal entities &\#x201[34]; # or hex ) ' # the quote (?=\w) # followed by a word character """ % (dec_dashes,), re.VERBOSE) str = opening_single_quotes_regex.sub(r"""\1‘""", str) closing_single_quotes_regex = re.compile(r""" (%s) ' (?!\s | s\b | \d) """ % (close_class,), re.VERBOSE) str = closing_single_quotes_regex.sub(r"""\1’""", str) closing_single_quotes_regex = re.compile(r""" (%s) ' (\s | s\b) """ % (close_class,), re.VERBOSE) str = closing_single_quotes_regex.sub(r"""\1’\2""", str) # Any remaining single quotes should be opening ones: str = re.sub(r"""'""", r"""‘""", str) # Get most opening double quotes: opening_double_quotes_regex = re.compile(r""" ( \s | # a whitespace char, or   | # a non-breaking space entity, or -- | # dashes, or &[mn]dash; | # named dash entities %s | # or decimal entities &\#x201[34]; # or hex ) " # the quote (?=\w) # followed by a word character """ % (dec_dashes,), re.VERBOSE) str = opening_double_quotes_regex.sub(r"""\1“""", str) # Double closing quotes: closing_double_quotes_regex = re.compile(r""" #(%s)? # character that indicates the quote should be closing " (?=\s) """ % (close_class,), re.VERBOSE) str = closing_double_quotes_regex.sub(r"""”""", str) closing_double_quotes_regex = re.compile(r""" (%s) # character that indicates the quote should be closing " """ % (close_class,), re.VERBOSE) str = closing_double_quotes_regex.sub(r"""\1”""", str) # Any remaining quotes should be opening ones. str = re.sub(r'"', r"""“""", str) return str def educateBackticks(str): """ Parameter: String. Returns: The string, with ``backticks'' -style double quotes translated into HTML curly quote entities. Example input: ``Isn't this fun?'' Example output: “Isn't this fun?” """ str = re.sub(r"""``""", r"""“""", str) str = re.sub(r"""''""", r"""”""", str) return str def educateSingleBackticks(str): """ Parameter: String. Returns: The string, with `backticks' -style single quotes translated into HTML curly quote entities. Example input: `Isn't this fun?' Example output: ‘Isn’t this fun?’ """ str = re.sub(r"""`""", r"""‘""", str) str = re.sub(r"""'""", r"""’""", str) return str def educateDashes(str): """ Parameter: String. Returns: The string, with each instance of "--" translated to an em-dash HTML entity. """ str = re.sub(r"""---""", r"""–""", str) # en (yes, backwards) str = re.sub(r"""--""", r"""—""", str) # em (yes, backwards) return str def educateDashesOldSchool(str): """ Parameter: String. Returns: The string, with each instance of "--" translated to an en-dash HTML entity, and each "---" translated to an em-dash HTML entity. """ str = re.sub(r"""---""", r"""—""", str) # em (yes, backwards) str = re.sub(r"""--""", r"""–""", str) # en (yes, backwards) return str def educateDashesOldSchoolInverted(str): """ Parameter: String. Returns: The string, with each instance of "--" translated to an em-dash HTML entity, and each "---" translated to an en-dash HTML entity. 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.) """ str = re.sub(r"""---""", r"""–""", str) # em str = re.sub(r"""--""", r"""—""", str) # en return str def educateEllipses(str): """ Parameter: String. Returns: The string, with each instance of "..." translated to an ellipsis HTML entity. Example input: Huh...? Example output: Huh…? """ str = re.sub(r"""\.\.\.""", r"""…""", str) str = re.sub(r"""\. \. \.""", r"""…""", str) return str def stupefyEntities(str): """ Parameter: String. Returns: The string, with each SmartyPants HTML entity translated to its ASCII counterpart. Example input: “Hello — world.” Example output: "Hello -- world." """ str = re.sub(r"""–""", r"""-""", str) # en-dash str = re.sub(r"""—""", r"""--""", str) # em-dash str = re.sub(r"""‘""", r"""'""", str) # open single quote str = re.sub(r"""’""", r"""'""", str) # close single quote str = re.sub(r"""“""", r'''"''', str) # open double quote str = re.sub(r"""”""", r'''"''', str) # close double quote str = re.sub(r"""…""", r"""...""", str)# ellipsis return str def processEscapes(str): r""" Parameter: String. Returns: The string, 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 ------ ----- \\ \ \" " \' ' \. . \- - \` ` """ str = re.sub(r"""\\\\""", r"""\""", str) str = re.sub(r'''\\"''', r""""""", str) str = re.sub(r"""\\'""", r"""'""", str) str = re.sub(r"""\\\.""", r""".""", str) str = re.sub(r"""\\-""", r"""-""", str) str = re.sub(r"""\\`""", r"""`""", str) return str def _tokenize(str): """ Parameter: String containing HTML markup. Returns: Reference to an array of the tokens comprising the input string. Each token is either a tag (possibly with nested, tags contained therein, such as , or a run of text between tags. Each element of the array is a two-element array; the first is either 'tag' or 'text'; the second is the actual value. Based on the _tokenize() subroutine from Brad Choate's MTRegex plugin. """ pos = 0 length = len(str) tokens = [] depth = 6 nested_tags = "|".join(['(?:<(?:[^<>]',] * depth) + (')*>)' * depth) #match = r"""(?: ) | # comments # (?: <\? .*? \?> ) | # directives # %s # nested tags """ % (nested_tags,) tag_soup = re.compile(r"""([^<]*)(<[^>]*>)""") token_match = tag_soup.search(str) previous_end = 0 while token_match is not None: if token_match.group(1): tokens.append(['text', token_match.group(1)]) tokens.append(['tag', token_match.group(2)]) previous_end = token_match.end() token_match = tag_soup.search(str, token_match.end()) if previous_end < len(str): tokens.append(['text', str[previous_end:]]) return tokens if __name__ == "__main__": import locale try: locale.setlocale(locale.LC_ALL, '') except: pass from docutils.core import publish_string docstring_html = publish_string(__doc__, writer_name='html') print docstring_html # Unit test output goes out stderr. No worries. import unittest sp = smartyPants class TestSmartypantsAllAttributes(unittest.TestCase): # the default attribute is "1", which means "all". def test_dates(self): self.assertEqual(sp("1440-80's"), "1440-80’s") self.assertEqual(sp("1440-'80s"), "1440-‘80s") self.assertEqual(sp("1440---'80s"), "1440–‘80s") self.assertEqual(sp("1960s"), "1960s") # no effect. self.assertEqual(sp("1960's"), "1960’s") self.assertEqual(sp("one two '60s"), "one two ‘60s") self.assertEqual(sp("'60s"), "‘60s") def test_skip_tags(self): self.assertEqual( sp(""""""), """""") self.assertEqual( sp("""

He said "Let's write some code." This code here if True:\n\tprint "Okay" is python code.

"""), """

He said “Let’s write some code.” This code here if True:\n\tprint "Okay" is python code.

""") def test_ordinal_numbers(self): self.assertEqual(sp("21st century"), "21st century") # no effect. self.assertEqual(sp("3rd"), "3rd") # no effect. def test_educated_quotes(self): self.assertEqual(sp('''"Isn't this fun?"'''), '''“Isn’t this fun?”''') unittest.main() __author__ = "Chad Miller " __version__ = "1.5_1.6: Fri, 27 Jul 2007 07:06:40 -0400" __url__ = "http://wiki.chad.org/SmartyPantsPy" __description__ = "Smart-quotes, smart-ellipses, and smart-dashes for weblog entries in pyblosxom" smartypants-1.6.0.3/PKG-INFO0000644000175500010010000000200611173356153013360 0ustar MeNoneMetadata-Version: 1.0 Name: smartypants Version: 1.6.0.3 Summary: SmartyPants: a smart-quotes plugin. Home-page: http://web.chad.org/projects/smartypants.py/ Author: Hao Lian Author-email: me@hao{no-spam}lian.org License: BSD Description: This module encapsulates Chad Miller's SmartyPants module so that it's available on PyPI. For more information, consult * http://web.chad.org/projects/smartypants.py/ * http://daringfireball.net/projects/smartypants/ The first two version numbers are Chad Miller's. The last two are mine. Platform: any Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Programming Language :: Python Classifier: Operating System :: OS Independent Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Topic :: Software Development :: Documentation Classifier: Topic :: Text Processing :: Filters smartypants-1.6.0.3/README0000700000175500010010000000007011123232045013117 0ustar MeNoneConsult . smartypants-1.6.0.3/setup.py0000700000175500010010000000245211173355732013775 0ustar MeNone#!/usr/bin/env python """\ SmartyPants: a smart-quotes plugin. This module encapsulates Chad Miller's SmartyPants module so that it's available on PyPI. For more information, consult * http://web.chad.org/projects/smartypants.py/ * http://daringfireball.net/projects/smartypants/ The first two version numbers are Chad Miller's. The last two are mine. """ # All of this is adapted from markdown2's setup.py. from distutils.core import setup doclines = __doc__.split("\n") classifiers = """\ Development Status :: 5 - Production/Stable Intended Audience :: Developers License :: OSI Approved :: BSD License Programming Language :: Python Operating System :: OS Independent Topic :: Software Development :: Libraries :: Python Modules Topic :: Software Development :: Documentation Topic :: Text Processing :: Filters """ setup( name = 'smartypants', version = '1.6.0.3', author = 'Chad Miller', maintainer = 'Hao Lian', maintainer_email = "me@hao{no-spam}lian.org", url = 'http://web.chad.org/projects/smartypants.py/', license = 'BSD', platforms = ['any'], py_modules = ['smartypants'], package_dir = {'': 'lib'}, #scripts=[script], description = doclines[0], classifiers = filter(None, classifiers.split("\n")), long_description = "\n".join(doclines[2:]), )