Once you have assembled aDocumentation 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 document with the desired elements, py2html offers several output methods to render the document to a string, write it to a file on disk, or pipe it to any writable stream. All rendering passes through the same internal getHTML() method, which walks self.tags in order and builds the final HTML string.
getHTML()
__str__, save(), and saveToFile().
When
True, the raw HTML is passed through BeautifulSoup’s prettify()
method, producing an indented, human-readable output. When False (default),
the HTML is returned as a compact single-line string.When
False (default), the output is wrapped in a complete
<html><head><title>…</title></head><body>…</body></html> skeleton.
When True, only the inner element HTML is returned — useful when embedding
the output inside another document or a Frame.str — the rendered HTML.
format=True depends on the beautifulsoup4 package. This is listed as a
dependency of py2html (import bs4 at the top of the module), so it should
already be present in your environment. If prettify() raises an exception
for any reason, the unformatted HTML is returned instead.saveToFile()
"w"), truncating any existing content. Output is not pretty-printed — it is the compact form returned by getHTML() with no arguments.
Path to the output file, e.g.,
"index.html" or "/var/www/html/page.html".
The file is created if it does not exist; existing files are overwritten.None
saveToFile() uses Python’s built-in open() in text mode. Ensure the
target directory exists and your process has write permission before calling
this method.save()
saveToFile(), the output is pretty-printed via getHTML(format=True).
Any object that implements a
.write(str) method. Typical uses include an
open() file handle, sys.stdout, or io.StringIO.None
escapeCharacters()
text or content — you rarely need to invoke it directly.
The input value. Coerced to
str via str(text) before processing, so
integers, floats, and other stringifiable types are accepted.str — the escaped, markup-processed string ready for insertion into HTML.
The following transformations are applied in order:
| Input token | HTML output | Notes |
|---|---|---|
& | & | Must be first to avoid double-escaping |
< | < | |
> | > | |
" | " | |
' | ' | |
\n | <br> | Newline to line break |
\t | | Tab to four non-breaking spaces |
[c … c] | <center> … </center> | Center alignment |
[xs … xs] | <span style='font-size: 0.6rem;'> | Extra-small text |
[xxs … xxs] | <span style='font-size: 0.4rem;'> | Extra-extra-small text |
[l … l] | <span style='font-size: 1.2rem;'> | Large text |
[xl … xl] | <span style='font-size: 1.5rem;'> | Extra-large text |
[xxl … xxl] | <span style='font-size: 2rem;'> | Extra-extra-large text |
[xxxl … xxxl] | <span style='font-size: 3rem;'> | Triple extra-large text |
[s … s] | <span style='font-size: 0.8rem;'> | Small text |
[m … m] | <span style='font-size: 1rem;'> | Medium (base) text |
[` … `] | <code> … </code> | Inline code |
[``` … ```] | <pre><code> … </code></pre> | Code block |
[* … *] | <strong> … </strong> | Bold |
[_ … _] | <em> … </em> | Italic |