smartypants() is the core of smartypants module.
Processing attributes, which tells smartypants() what to convert
See also
class for instantiation of module attribute Attr.
flag for double quotes (``backticks'') and single quotes (`single') to curly ones.
See also
flag for old-school typewriter dashes (--) to en-dashes and dashes (---) to em-dashes.
See also
flag for double quotes (``backticks'') to curly ones.
See also
flag for dashes (--) to em-dashes.
See also
flag for dashes (...) to ellipses.
See also
Output HTML named entities instead of numeric character references, for example, from “ to “.
See also
flag for inverted old-school typewriter dashes (--) to em-dashes and dashes (---) to en-dashes.
See also
flag for normal quotes (") and (') to curly ones.
See also
Output ASCII equivalents instead of numeric character references, for example, from — to --.
See also
suppress all transformations. (Do nothing.)
Output Unicode characters instead of numeric character references, for example, from “ to left double quotation mark (“) (U+201C).
See also
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 “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 convert " entities into regular quotes so SmartyPants can educate them.
Convert a list of skipped tags into regular expression
The default tags are tags_to_skip.
>>> f = _tags_to_skip_regex
>>> print(f(['foo', 'bar']).pattern)
<(/)?(foo|bar)[^>]*>
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.
Convert ``backticks''-style double quotes in text into HTML curly quote entities.
>>> print(convert_backticks("``Isn't this fun?''"))
“Isn't this fun?”
Convert -- in text into em-dash HTML entities.
>>> quote = 'Nothing endures but change. -- Heraclitus'
>>> print(convert_dashes(quote))
Nothing endures but change. — Heraclitus
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)
Convert -- and --- in text into em-dash and en-dash HTML entities, respectively.
Two reasons why:
>>> 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)
Convert ... in text into ellipsis HTML entities
>>> print(convert_ellipses('Huh...?'))
Huh…?
Convert numeric character references to, if mode is
>>> print(convert_entities('‘', 0))
‘
>>> print(convert_entities('‘SmartyPants’', 1))
‘SmartyPants’
>>> print(convert_entities('“Hello — world.”', 2))
"Hello -- world."
Convert quotes in text into HTML curly quote entities.
>>> print(convert_quotes('"Isn\'t this fun?"'))
“Isn’t this fun?”
Convert `backticks'-style single quotes in text into HTML curly quote entities.
>>> print(convert_single_backticks("`Isn't this fun?'"))
‘Isn’t this fun?’
Processe 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 function
>>> print(smartypants('"foo" -- bar'))
“foo” — bar
>>> print(smartypants('"foo" -- bar', Attr.d))
"foo" — bar
Skipped HTML elements
See also