My preferred options for SmartyPants in Python
smartypants.smartypants(…, Attr.default | Attr.u)
I wanted to add curly quotes and dashes to some text in Python, so I looked at the smartypants library. This is the code I used:
import smartypants
text = '"hello world"'
attrs = smartypants.Attr.default | smartypants.Attr.u
print(smartypants.smartypants(text, attrs)) # “hello world”
I set two processing attributes that control the behaviour, which you combine with bitwise OR:
Attr.defaultis the default set of attributes, which converts curly quotes, backticks, dashes, and ellipsesAttr.ureturns Unicode characters instead of numeric character references, for example“hello world”instead of“hello world”. You can include UTF-8 in HTML files, and the Unicode characters are easier to read in non-HTML contexts.