Răsfoiți Sursa

allow other tags than div in ui.html

Peter Kleynjan 1 an în urmă
părinte
comite
8c23ccafb8

+ 4 - 3
nicegui/elements/html.py

@@ -3,14 +3,15 @@ from .mixins.content_element import ContentElement
 
 
 class Html(ContentElement):
 class Html(ContentElement):
 
 
-    def __init__(self, content: str = '') -> None:
+    def __init__(self, content: str = '', tag: str = "div" ) -> None:
         """HTML Element
         """HTML Element
 
 
-        Renders arbitrary HTML onto the page.
+        Renders arbitrary HTML onto the page, wrapped in the specified tag. 
         `Tailwind <https://tailwindcss.com/>`_ can be used for styling.
         `Tailwind <https://tailwindcss.com/>`_ can be used for styling.
         You can also use `ui.add_head_html` to add html code into the head of the document and `ui.add_body_html`
         You can also use `ui.add_head_html` to add html code into the head of the document and `ui.add_body_html`
         to add it into the body.
         to add it into the body.
 
 
         :param content: the HTML code to be displayed
         :param content: the HTML code to be displayed
+        :param tag: the HTML tag to wrap the content in (default: div)
         """
         """
-        super().__init__(tag='div', content=content)
+        super().__init__(tag=tag, content=content)

+ 7 - 0
website/documentation/content/html_documentation.py

@@ -8,4 +8,11 @@ def main_demo() -> None:
     ui.html('This is <strong>HTML</strong>.')
     ui.html('This is <strong>HTML</strong>.')
 
 
 
 
+@doc.demo('Producing in-line elements', '''
+    Use the `tag` parameter to produce something other than a div.
+''')
+def demo_inline() -> None:
+    ui.html('This is rendered as a paragraph.', tag='p')
+
+
 doc.reference(ui.html)
 doc.reference(ui.html)