Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nishad12323/py2html/llms.txt
Use this file to discover all available pages before exploring further.
Parent is the central class in py2html. Every HTML document you build starts with a Parent instance — it holds an ordered list of element descriptors (self.tags) and provides methods to add elements, configure document-level properties, and render the final HTML string. All element-creation methods (Button, Frame, Link, etc.) are also defined on this class and are documented separately on the Elements page.
Constructor
Parent()
Creates a new, empty HTML document object. No arguments are required.
| Attribute | Type | Initial value | Purpose |
|---|---|---|---|
self.html | str | "" | Scratch buffer written to during rendering |
self.tags | list | [] | Ordered list of element descriptor dicts |
Configuration Methods
config(**kwargs)
Sets document-level properties in a single call. Currently supports two keyword arguments: title and style. Any combination may be supplied; omitted keys are left unchanged.
Sets the document title, stored as
self.title. The value is coerced to str
before storing, so integers and other types are accepted.Sets a document-level style string, stored as
self.style. Must be a str
— passing any other type raises ValueError.None
Raises: ValueError — if style is provided but is not a str.
config() stores title and style as instance attributes but does not
automatically inject <style> tags into the rendered output. Use a
CustomTag or Script element to embed stylesheet content.title(title)
A convenience method that sets self.title to str(title). Equivalent to calling config(title=...) with a single argument.
The document title. Coerced to
str before being stored.None
config(title=...) and title() both write to the same self.title
attribute, so the last call wins if you use both.Dunder Methods
__call__(*args, escape=True, sep=" ")
Makes a Parent instance callable. Joining all positional args with sep, it calls TextNode() internally and appends the resulting text node to self.tags.
One or more strings to join and insert as a text node.
When
True (default), HTML-special characters in the joined text are escaped
via escapeCharacters(). Set to False to insert raw HTML.The separator used when joining multiple positional arguments.
self.tags — i.e., self.tags[-1] (a dict).
__getitem__(index)
Retrieves the tag descriptor at the given index from self.tags.
Zero-based integer index into
self.tags.dict — the tag descriptor at self.tags[index].
Raises: IndexError — if index < 0 or index >= len(self.tags).
Negative indexing is not supported. Passing
-1 raises IndexError.
Use page[len(page.tags) - 1] to access the last element explicitly.__delitem__(index)
Deletes the tag descriptor at the given index from self.tags, removing that element from the rendered output.
Zero-based integer index of the tag to remove.
None
Raises: IndexError — if index < 0 or index >= len(self.tags).
__str__()
Returns the fully rendered, prettified HTML string for the document. Equivalent to calling page.getHTML(format=True, insideframe=False).
Returns: str — the complete HTML document, including <html>, <head>, and <body> wrappers, formatted by BeautifulSoup’s prettify().
Utility Method
escapeCharacters(text)
Converts a raw string into HTML-safe text and applies py2html’s lightweight inline markup syntax. This method is called automatically by every element method that accepts a text or content argument — you rarely need to call it directly.
The input value. Coerced to
str before processing.str — the escaped and markup-processed string.
The method performs the following transformations in order:
| Input token | HTML output |
|---|---|
& | & |
< | < |
> | > |
" | " |
' | ' |
\n | <br> |
\t | |
[c … c] | <center> … </center> |
[xs … xs] | <span style='font-size: 0.6rem;'> … </span> |
[xxs … xxs] | <span style='font-size: 0.4rem;'> … </span> |
[l … l] | <span style='font-size: 1.2rem;'> … </span> |
[xl … xl] | <span style='font-size: 1.5rem;'> … </span> |
[xxl … xxl] | <span style='font-size: 2rem;'> … </span> |
[xxxl … xxxl] | <span style='font-size: 3rem;'> … </span> |
[s … s] | <span style='font-size: 0.8rem;'> … </span> |
[m … m] | <span style='font-size: 1rem;'> … </span> |
[` … `] | <code> … </code> |
[``` … ```] | <pre><code> … </code></pre> |
[* … *] | <strong> … </strong> |
[_ … _] | <em> … </em> |