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.
Important
Beware of
--
, which should not or must not be in a HTML comment.Backslash escapes¶
If you need to use literal straight quotes (or plain hyphens and periods), for example, text like
6'2"
may become6‘2”
. To avoid such situation, you can use backslash escapes like6\'2\"
.See also
smartypants.process_escapes()
for a complete list of backslash escapes.