SmartyPants

2.0.2 · active · verified Thu Apr 16

SmartyPants is a Python library that converts plain ASCII punctuation in text to "smart" typographic HTML entities. It transforms straight quotes to "curly" quotes, backticks-style quotes, -- and --- to en- and em-dashes, and three consecutive dots to an ellipsis entity. The current version is 2.0.2, and it is actively maintained with recent fixes for Python 3.12+ compatibility.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of the smartypants function to convert ASCII punctuation to typographic entities, and how to use attributes to control conversions.

import smartypants

text = '"SmartyPants" is smart, so is <code>smartypants</code> -- a Python port...'
processed_text = smartypants.smartypants(text)
print(processed_text)

# Example with attributes
from smartypants import Attr
attrs = Attr.q | Attr.d # Enable quotes and dashes
processed_text_with_attrs = smartypants.smartypants(text, attrs)
print(processed_text_with_attrs)

view raw JSON →