diff --git a/docs/guide.rst b/docs/guide.rst index e457e2a..2456af0 100644 --- a/docs/guide.rst +++ b/docs/guide.rst @@ -92,6 +92,22 @@ There is ``stlite`` directive to write Stlite app code into document. This supports multiline strings, comma-separated strings, or combinations. + .. rst:directive:option:: height + + Height of the stlite iframe. + + Accepts values with units (e.g., ``500px``, ``30rem``) or numeric values (treated as pixels). + + Example: + + .. code-block:: rst + + .. stlite:: + :height: 600px + + import streamlit as st + st.title("Custom Height Example") + Configuration ============= diff --git a/src/atsphinx/stlite/directives.py b/src/atsphinx/stlite/directives.py index 24611a4..e56f82e 100644 --- a/src/atsphinx/stlite/directives.py +++ b/src/atsphinx/stlite/directives.py @@ -46,10 +46,12 @@ class StliteDirective(SphinxDirective): # noqa: D101 option_spec = { "config": parsed_dict, "requirements": list_of_str, + "height": str, } DEFAULT_OPTIONS = { "config": None, "requirements": [], + "height": None, } def run(self): # noqa: D102 diff --git a/src/atsphinx/stlite/nodes.py b/src/atsphinx/stlite/nodes.py index de2a471..731c9e9 100644 --- a/src/atsphinx/stlite/nodes.py +++ b/src/atsphinx/stlite/nodes.py @@ -27,8 +27,18 @@ class stlite(nodes.Element, nodes.General): # noqa: D101 def visit_stlite(self: HTML5Translator, node: stlite) -> None: # noqa: D103 config = self.builder.config srcdoc = escape(srcdoc_template.render(app=node.attributes, config=config)) + + # Apply custom height if specified + style_attr = "" + if node.attributes.get("height"): + height = node.attributes["height"] + # Ensure px suffix if numeric value without unit + if height.isdigit(): + height = f"{height}px" + style_attr = f' style="height: {escape(height)};"' + self.body.append( - f'