py2html pages are static HTML documents, but they can include fully interactive JavaScript through theDocumentation 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.
Script() method. Calling Script() appends a <script> tag to the current Parent object, and you can use it for inline code, external file references, or ES module imports. Unlike text content added through Label() or Button(), the JavaScript you supply is stored and rendered completely raw — no HTML escaping is applied.
Script() signature
| Parameter | Type | Description |
|---|---|---|
code | str | Inline JavaScript to embed inside the <script> tag. Stored raw, never HTML-escaped. |
src | str | URL or path to an external .js file. Rendered as the src attribute. |
**kwargs | any | Extra HTML attributes passed to the <script> tag (e.g., type, defer, async_). |
Inline JavaScript
Pass your JavaScript as a string to thecode parameter. The content is placed verbatim between the opening and closing <script> tags. This means you can use any JavaScript syntax, including template literals, regular expressions, and angle brackets, without worrying about HTML entity encoding.
Inline JavaScript is stored as a raw string and is never run through
py2html’s
escapeCharacters() method. Characters like <, >, &, and
" in your JavaScript will appear exactly as written in the output file.
Only use inline scripts from trusted sources.External script file
Use thesrc parameter to load a JavaScript file from a URL or a relative path. py2html HTML-escapes the src value itself (so the URL is safe to embed as an HTML attribute), but it generates no inline content between the tags.
Passing HTML attributes via kwargs
Any keyword argument beyondcode and src is rendered as an HTML attribute on the <script> tag. This covers common attributes like type, defer, and async.
defer=True renders as defer="True", and type="module" renders as type="module".