Getting started¶
Go from an empty environment to escaping and unescaping your first HTML.
Install turbohtml from PyPI:
$ pip install turbohtml
Open a Python prompt and escape some text for safe inclusion in an HTML page:
import turbohtml
print(turbohtml.escape("5 > 3 & 2 < 4"))
5 > 3 & 2 < 4
By default escape escapes quotation marks too, which you want inside an attribute value:
print(turbohtml.escape('name="O\'Brien"'))
name="O'Brien"
Reverse the process: turn HTML character references back into text:
print(turbohtml.unescape("Tom & Jerry, café"))
Tom & Jerry, café
Stay with the string helpers below, or continue to Tokenizing a document to break whole documents into tokens.
Linkify plain text¶
One more string-in, string-out helper rounds out the getting-started toolkit: turbohtml.clean.linkify() finds the
URLs in a run of text and wraps each one in an anchor, leaving the surrounding characters untouched. It is the quickest
way to turn a plain message into clickable HTML:
from turbohtml.clean import linkify
print(linkify("Visit https://example.com today"))
Visit <a href="https://example.com" rel="nofollow">https://example.com</a> today
Every generated link carries rel="nofollow" by default, so untrusted text stays safe to publish. With the string
helpers in hand, continue to Tokenizing a document to break whole documents into tokens.