SMARTYPANTS(1)
SMARTYPANTS(1) โจ smartypants โจ ๐
NAME
smartypants - smartypants Documentation
IMPORTANT: As of 2016-12-28, smartypants is looking for new maintainer to take over, please contact project owner on Bitbucket. ๐ซถ
Contents: okay bestie, here's the whole lineup โ keep scrolling for the full tour ๐ซ
INTRODUCTION
smartypants is a Python fork of SmartyPants. ๐โจ
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. ๐ No cap.
smartypants does not modify contents in some HTML element, see Skipped HTML Elements. 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. ๐ง
Quick usage
To use it as a module: ๐
import smartypants
text = '"SmartyPants" is smart, so is <code>smartypants</code> -- a Python port'
print(smartypants.smartypants(text))
To use the command-line script smartypants:
echo '"SmartyPants" is smart, so is <code>smartypants</code> -- a Python port' | smartypants
Both produce:
“SmartyPants” is smart, so is <code>smartypants</code> — a Python port
Installation
smartypants package on PyPI can be installed via pip: โจ
pip install smartypants
If you want to install latest development code, you can run:
pip install hg+https://bitbucket.org/livibetter/smartypants.py
or:
pip install hg+ssh://hg@bitbucket.org/livibetter/smartypants.py
USAGE
Typically, you import smartypants and call the smartypants.smartypants() to convert a text, for example: ๐
import smartypants
text = '"SmartyPants" is smart, so is <code>smartypants.py</code> -- a Python port'
print(smartypants.smartypants(text))
It results:
“SmartyPants” is smart, so is <code>smartypants.py</code> — a Python port
Attributes
smartypants.smartypants() accepts processing attributes, which tells it what need to be converted. ๐ง โจ
SEE ALSO: smartypants.Attr for a list of attributes.
To use these attributes, simply using bitwise OR operator, that is A | B:
from smartypants import Attr
attrs = Attr.q | Attr.d
smartypants.smartypants(text, attrs)
attrs = Attr.set1 | Attr.w
smartypants.smartypants(text, attrs)
Skipped HTML elements
Elements
By default, there are a few HTML elements that smartypants.smartypants() do not try to be smart with them: ๐
โโ๏ธ
tags_to_skip = ['pre', 'samp', 'code', 'tt', 'kbd', 'script', 'style', 'math']
If you need to change, for example, adding additional tags and remove one of them:
>>> from smartypants import tags_to_skip as tags
>>> tags.append('a')
>>> tags.remove('code')
>>> tags
['pre', 'samp', 'tt', 'kbd', 'script', 'style', 'math', 'a']
The smartypants.tags_to_skip is compiled into a regular expression for being used by smartypants.smartypants(). You could actually overwrite smartypants._tags_to_skip_regex() and return with your own regular expression. ๐ช
Comments
HTML comments are always skipped since they are not rendered in browsers. ๐ฌ๐ซ
>>> from smartypants import smartypants as sp
>>> print(sp('<!-- <span>"foobar"</span> -->'))
<!-- <span>"foobar"</span> -->
IMPORTANT: Beware of --, which should not or must not be in a HTML comment. ๐ฌ
>>> from smartypants import smartypants as sp
>>> print(sp('<!-- <span>"foo--bar"</span> -->'))
<!— <span>”foo—bar”</span> —>
Backslash escapes
If you need to use literal straight quotes (or plain hyphens and periods), for example, text like 6'2" may become 6โ2โ. To avoid such situation, you can use backslash escapes like 6\'2\". ๐ช
SEE ALSO: smartypants.process_escapes() for a complete list of backslash escapes.
DEVELOPMENT
smartypants is hosted on Bitbucket, you can clone the repository or file an issue report from there. ๐งโโ๏ธ
Contributing
You are welcome to contribute whatever you can. Coding, documenting, reporting issues, requesting features, even correcting typos. ๐ซถโจ
Testing
If you want to contribute to the source code, be sure that you check your modification can pass tests. Normally, if you use Unix-like system, you should be able to run all tests with: ๐งช
make test
It will test DOC8, PEP8, pyflakes, unittest, and package installation:
make test_isort
make test_doc8
make test_pep8
make test_pyflakes
make test_test
make test_setup
NOTE: They will all be tested with both Python 2 and Python 3. You may need to overridePY2_CMDand/orPY3_CMD. ๐๐
If make isn't available, setup.py can be used:
python setup.py isort
python setup.py pep8
python setup.py pyflakes
python setup.py test
For manual package installation test:
python setup.py sdist
pip install --user --upgrade dist/smartypants-<x.y.z>.tar.gz
Building
Package
You should be able to build the package with either of:
make
NOTE: make builds source tarball, zip, and win32 setup.
or:
python setup.py sdist
Documentation
You should be able to build the documentation with either of:
make doc
or:
python setup.py build_sphinx
Reporting
Please head over to Issues and create an issue for a bug report or feature request. ๐โจ
๐ REFERENCE ๐
๐ smartypants module ๐
smartypants() is literally the core of the smartypants module, bestie โ the main character function, fr.
smartypants.Attr = <smartypants._Attr object>โ the processing attributes object that tellssmartypants()what to convert. iykwim.- SEE ALSO:
_Attr
- SEE ALSO:
๐
class smartypants._Attr ๐
Class for instantiation of module attribute Attr. Itโs giving โsettings drawerโ energy.
B = 6โ flag for double quotes (``backticks'') and single quotes (`single') to curly ones.- SEE ALSO:
convert_backticks()andconvert_single_backticks()
- SEE ALSO:
D = 24โ flag for old-school typewriter dashes (--) to en-dashes and dashes (---) to em-dashes.- SEE ALSO:
convert_dashes_oldschool()
- SEE ALSO:
b = 2โ flag for double quotes (``backticks'') to curly ones.- SEE ALSO:
convert_backticks()
- SEE ALSO:
d = 8โ flag for dashes (--) to em-dashes.- SEE ALSO:
convert_dashes()
- SEE ALSO:
defaultproperty โ default value of attributes, same value asset1.e = 64โ flag for dashes (...) to ellipses.- SEE ALSO:
convert_ellipses()
- SEE ALSO:
h = 512โ output HTML named entities instead of numeric character references, for example, from“to“.- SEE ALSO:
convert_entities()
- SEE ALSO:
i = 40โ flag for inverted old-school typewriter dashes (--) to em-dashes and dashes (---) to en-dashes.- SEE ALSO:
convert_dashes_oldschool_inverted()
- SEE ALSO:
q = 1โ flag for normal quotes (") and (') to curly ones.- SEE ALSO:
convert_quotes()
- SEE ALSO:
s = 768โ output ASCII equivalents instead of numeric character references, for example, from—to--.- SEE ALSO:
convert_entities()
- SEE ALSO:
set0 = 0โ suppress all transformations. (Do nothing.) The โgirl, not todayโ setting ๐.set1 = 75โ equivalent toq | b | d | e.set2 = 91โ equivalent toq | b | D | e.- For old school en- and em- dash.
set3 = 107โ equivalent toq | b | i | e.- For inverted old school en & em- dash.
u = 256โ output Unicode characters instead of numeric character references, for example, from“to left double quotation mark (โ) (U+201C).- SEE ALSO:
convert_entities()
- SEE ALSO:
w = 128โ flag for dashes (") to ASCII double quotes (").- 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
woption must be used in conjunction with one (or both) of the other quote options (qorb). Thus, if you wish to apply all SmartyPants transformations (quotes, en- and em-dashes, and ellipses) and also convert"entities into regular quotes so SmartyPants can educate them.
- 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
๐ธ smartypants._tags_to_skip_regex(tags=None) ๐ธ
Convert a list of skipped tags into a regular expression. Very โmake it make senseโ of you.
The default tags are tags_to_skip.
>>> f = _tags_to_skip_regex
>>> print(f(['foo', 'bar']).pattern)
<(/)?(foo|bar)[^>]*>
๐ฆ smartypants._tokenize(text) ๐ฆ
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 <a href="<MTFoo>">) 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. Respect the lineage, periodt.
๐ smartypants.convert_backticks(text) ๐
Convert ``backticks''-style double quotes in text into HTML curly quote entities.
>>> print(convert_backticks("``Isn't this fun?''"))
“Isn't this fun?”
๐ฅ smartypants.convert_dashes(text) ๐ฅ
Convert -- in text into em-dash HTML entities.
>>> quote = 'Nothing endures but change. -- Heraclitus'
>>> print(convert_dashes(quote))
Nothing endures but change. — Heraclitus
โญ smartypants.convert_dashes_oldschool(text) โญ
Convert -- and --- in text into en-dash and em-dash HTML entities, respectively.
>>> quote = 'Life itself is the proper binge. --- Julia Child (1912--2004)'
>>> print(convert_dashes_oldschool(quote))
Life itself is the proper binge. — Julia Child (1912–2004)
๐ smartypants.convert_dashes_oldschool_inverted(text) ๐
Convert -- and --- in text into em-dash and en-dash HTML entities, respectively.
Two reasons why:
- First, unlike the en- and em-dash syntax supported by
convert_dashes_oldschool(), 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.)
>>> quote = 'Dare to be naรฏve. -- Buckminster Fuller (1895---1983)'
>>> print(convert_dashes_oldschool_inverted(quote))
Dare to be naรฏve. — Buckminster Fuller (1895–1983)
๐ง smartypants.convert_ellipses(text) ๐ง
Convert ... in text into ellipsis HTML entities. Suspenseful icon behavior โจ.
>>> print(convert_ellipses('Huh...?'))
Huh…?
๐ smartypants.convert_entities(text, mode) ๐
Convert numeric character references to, if mode is:
0: Unicode characters1: HTML named entities2: ASCII equivalents
>>> print(convert_entities('‘', 0))
โ
>>> print(convert_entities('‘SmartyPants’', 1))
‘SmartyPants’
>>> print(convert_entities('“Hello — world.”', 2))
"Hello -- world."
๐ smartypants.convert_quotes(text) ๐
Convert quotes in text into HTML curly quote entities.
>>> print(convert_quotes('"Isn\'t this fun?"'))
“Isn’t this fun?”
๐ smartypants.convert_single_backticks(text) ๐
Convert `backticks'-style single quotes in text into HTML curly quote entities.
>>> print(convert_single_backticks("`Isn't this fun?'"))
‘Isn’t this fun?’
๐ซถ smartypants.process_escapes(text) ๐ซถ
Process the following backslash escape sequences in text. This is useful if you want to force a โdumbโ quote or other character to appear.
Escape Value Character
\\ \ \
\" " "
\' ' '
\. . .
\- - -
\` ` `
>>> print(process_escapes(r'\\'))
\
>>> print(smartypants(r'"smarty" \"pants\"'))
“smarty” "pants"
๐ smartypants.smartypants(text, attr=None) ๐
SmartyPants function. The main event, no cap.
>>> print(smartypants('"foo" -- bar'))
“foo” — bar
>>> print(smartypants('"foo" -- bar', Attr.d))
"foo" — bar
๐ smartypants.tags_to_skip ๐
smartypants.tags_to_skip = ['pre', 'samp', 'code', 'tt', 'kbd', 'script', 'style', 'math']
Skipped HTML elements.
SEE ALSO: Skipped HTML elements.
๐ฐ๏ธ HISTORY ๐ฐ๏ธ
For changelog, please see Changes.
๐ SmartyPants ๐
Perl SmartyPants or original SmartyPants.
In 2002, John Gruber started the SmartyPants for Movable Type, written in Perl.
Rael Dornfest ported SmartyPants to Blosxom. Portions of the SmartyPants are based on Brad Choateโs nifty MTRegex plug-in. Jeremy Hedley and Charles Wiltgen deserve mention for exemplary beta testing of SmartyPants.
๐ฆ smartypants.py ๐ฆ
smartypants.py, Python [port of] SmartyPants.
In 2004, Chad Miller ported it to Python to use with Pyblosxom.
Brad Choate also contributed a few bits of source code to the Python port. Brad Choate is a fine hacker indeed. It was later packaged for PyPI by Hao Lian.
๐ smartypants ๐
smartypants, Python [fork of] SmartyPants.
Since August 2013, smartypants has been managed by Yu-Jie Lin after contacted Chad Miller and Hao Lian. Lin took over the project manager role and the package ownership on PyPI. It has since then also officially supported Python 3.
At this point, smartpants is heading towards as a fork of SmartyPants. The .py part is dropped from the project name, .py or โportโ sometimes is still used. For instance, to avoid confused with SmartyPants.
Nevertheless, the project name is smartypants.
๐ CHANGES
NOTE: Releases without timestamps mean they will be released in the future.
Development means it's current changes in development repository.
๐ Releases 2.0 and greater
๐ ๏ธ Development
- use
re.matchinstead ofre.searchto improve performance on large strings
๐ Release 2.0.0 (2016-12-28T06:18:42Z)
- drop Pyblosxom support
- drop str-type attr
- use
Attr.defaultinstead ofdefault_smartypants_attr
- use
- drop
fooBarXyzfunctions, such assmartyPants,educateQuotes, andprocessEscapes - add
Attr.uandAttr.hfor Unicode characters and HTML named entities outputs, respectively. Thestupefy_entitieshas becomeconvert_entitiesto support all three types of conversions. (#6) Makefile- do not build
bdist_wininst --plat-name win32per PEP 527#bdist-dmg-bdist-msi-and-bdist-wininst - do not make
sdist --format=zip, it would get a duplicate warning on PyPI - test packages build in
test_setuptarget - rename target
install_testtotest_setup
- do not build
๐ฑ Releases 1.7 and greater
๐ธ Release 1.8.6: 2014-07-19T11:20:52Z
Makefile- add
LC_ALL=Ctest for locale setting onsetup.pywrt #5 - change virtualenv invocation method in
install_testtarget
- add
- fix
UnicodeDecodeErroron openingsmartypants.py, which includes Unicode characters, when runningsetup.pywith Python 3 and specific locales (#5, patch by Benoรฎt Monin)
๐ Release 1.8.5: 2014-07-03T01:56:03Z
- fix requirement of Wheel, now optional (#4)
๐ Release 1.8.4: 2014-06-29T04:39:59Z
- add missing
COPYINGandCHANGES.rstto package (#3) - add
bdist_wheelto the building process for Python Wheel format - add
test_doc8target - fix
install_teston missing of Wheel package - fix argparse
versionoption breaks CLI on Python 3
๐ Release 1.8.3: 2013-11-08T03:03:43Z
- fix
_tokenizecan not handle HTML comment properly
This fix includes pull request #1 with modification for handling -- appears in a comment, which makes the comment not a comment
โจ Release 1.8.2: 2013-08-28T11:38:42Z
- deprecate
fooBarXyzfunctions, such aseducateQuotesandprocessEscapes - fix
---being converted ineducateDashes
The Perl doesn't do such, and it's possibly a mistaken in version v1.5_1.5 (eed4a8a16f11)
If you want the same behavior with default attributes, you need to use Attr.q | Attr.b | Attr.i | Attr.e
setup.py- add
build_sphinxandupload_sphinxcommands
- add
Makefile- add
docfor documentation generation - add
upload_docfor uploading to PyPI - add
cleanfor cleaning up built files
- add
- add documentation generation
๐ฆ Release 1.8.1: 2013-08-20T02:27:35Z
- fix deprecated
smartyPantsreturns nothing (#2) - add test file for deprecated stuff
๐ Release 1.8.0: 2013-08-18T11:47:27Z
- deprecate str-type
attrwith:- redesign
attrinput with newAttrobject"-1"now isAttr.s("s")
_str_attr_to_int()to handle str-type before the removal
- redesign
- deprecate function name
smartyPants, nowsmartypants - remove
tags_to_skip_regexand addtags_to_skipas a list of skipped HTML with a helper function to compile a regular expression - command-line
- add
--version - add
--skipfor skipped elements
- add
- add
Makefile:test_pep8,test_pyflakes, andtest_test(unittest) targetsinstall_testtarget for checking package installationtesttarget for all tests above
- add
style,samp, andttto be skipped HTML elements
๐ Release 1.7.1: 2013-08-14T06:45:59Z
- fix
README-PyPI.rstmissing while installing
๐ Release 1.7.0: 2013-08-14T05:51:20Z
- deprecate Pyblosxom support
- remove HBS language translation added in 1.5_1.7.
- fix
convert_quotalways enabled
It was always turned on. To have same effect of previous 1 attr, equivalent attrs are qbdew. Now 1 means qbde
- add Python 3 support
- add unittest and checks
- add CLI script
๐ Releases 1.6
The following releases were made by Hao Lian:
๐ง Release 1.6.0.3: 2009-04-21
smartypants.py exactly the same as 1.5_1.6
๐ง Release 1.6.0.2: 2008-12-20
smartypants.py exactly the same as 1.5_1.6
โญ Releases 1.5
The following releases were made by Chad Miller:
๐ Release 1.5_1.7: Fri, 09 Aug 2013 07:34:16 -0400
- Add HBS language translation. Patch by by Vera Djuraskovic from Webhostinggeeks.com
- Add Python3 support
๐ฌ Release 1.5_1.6: Fri, 27 Jul 2007 07:06:40 -0400
- Fixed bug where blocks of precious unalterable text was instead interpreted. Thanks to Le Roux and Dirk van Oosterbosch
๐ฏ Release 1.5_1.5: Sat, 13 Aug 2005 15:50:24 -0400
- Fix bogus magical quotation when there is no hint that the user wants it, e.g., in "21st century". Thanks to Nathan Hamblen
- Be smarter about quotes before terminating numbers in an en-dash'ed range
๐ซ Release 1.5_1.4: Thu, 10 Feb 2005 20:24:36 -0500
- Fix a date-processing bug, as reported by jacob childress
- Begin a test-suite for ensuring correct output
- Removed import of "string", since I didn't really need it (This was my first every Python program. Sue me!)
๐ซง Release 1.5_1.3: Wed, 15 Sep 2004 18:25:58 -0400
- Abort processing if the flavour is in forbidden-list. Default of [ "rss" ] (Idea of Wolfgang SCHNERRING.)
- Remove stray virgules from en-dashes. Patch by Wolfgang SCHNERRING
๐ฅ Release 1.5_1.2: Mon, 24 May 2004 08:14:54 -0400
- Some single quotes weren't replaced properly. Diff-tesuji played by Benjamin GEIGER
๐ Release 1.5_1.1: Sun, 14 Mar 2004 14:38:28 -0500
- Support upcoming pyblosxom 0.9 plugin verification feature
๐ Release 1.5_1.0: Tue, 09 Mar 2004 08:08:35 -0500
- Initial release
โ๏ธ COPYRIGHT
๐๏ธ SmartyPants
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
smartypants is a derivative work of SmartyPants.
Copyright (c) 2017, Leo Hemsted Copyright (c) 2013, 2014, 2015, 2016 Yu-Jie Lin Copyright (c) 2004, 2005, 2007, 2013 Chad Miller
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.
๐๏ธ Doc nav vibes (the little links at the bottom)
- Index
- Module Index
- Search Page
๐ AUTHOR
Yu-Jie Lin
ยฉ๏ธ COPYRIGHT
2013, Yu-Jie Lin
okay bestie that's genuinely the whole thing ๐ you made it to the end, iconic behavior fr fr. This page is SMARTYPANTS(1), coming at you as version 2.0, dated Mar 27, 2026 โ screenshot it, cite it, frame it, whatever, just remember where you got it ๐ซถโจ
๐ฆ where this page comes from
- alpine 3.24: smartypants-doc 2.0.1-r6 ยท BSD-3-Clause AND BSD-2-Clause
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms