diff --git a/src/taipy/gui/builder/_element.py b/src/taipy/gui/builder/_element.py
index 8eff27339..ff43deed2 100644
--- a/src/taipy/gui/builder/_element.py
+++ b/src/taipy/gui/builder/_element.py
@@ -106,24 +106,59 @@ def __init__(self, *args, **kwargs):
class html(_Block):
"""A visual element defined as an HTML tag.
+ Use this class to integrate raw HTML to your page.
+
This element can be used as a block element.
"""
def __init__(self, *args, **kwargs):
"""Create a new `html` block.
- TODO
+ Arguments:
+ args (any[]): A list of one or two unnamed arguments:
+
+ - *args[0]* is the HTML tag name. If empty or None, this represents an HTML text
+ node.
+ - *args[1]* (optional) is the text of this element.
+ Note that special HTML characters (such as '<' or '&') do not need to be protected.
+ kwargs (dict[str, any]): the HTML attributes for this element.
+ These should be valid attribute names, with valid attribute values.
+
+ Examples:
+ - To generate `
`, use:
+ ```
+ html("br")
+ ```
+ - To generate `
This is a Taipy GUI element.
`, use: + ``` + with html("p"): + html(None, "This is a ") + html("b", "Taipy GUI") + html(None, " element.") + ``` """ super().__init__(*args, **kwargs) if not args: raise RuntimeError("Can't render html element. Missing html tag name.") - self._ELEMENT_NAME = args[0] + self._ELEMENT_NAME = args[0] if args[0] else None self._content = args[1] if len(args) > 1 else "" def _render(self, gui: "Gui") -> str: - open_tag_attributes = " ".join([f'{k}="{str(v)}"' for k, v in self._properties.items()]) - open_tag = f"<{self._ELEMENT_NAME} {open_tag_attributes}>" - return f"{open_tag}{self._content}{self._render_children(gui)}{self._ELEMENT_NAME}>" + if self._ELEMENT_NAME: + attrs = "" + if self._properties: + attrs = " " + " ".join([f'{k}="{str(v)}"' for k, v in self._properties.items()]) + return f"<{self._ELEMENT_NAME}{attrs}>{self._content}{self._render_children(gui)}{self._ELEMENT_NAME}>" + else: + return self._content class _Control(_Element): diff --git a/src/taipy/gui/gui.py b/src/taipy/gui/gui.py index 488bdf732..ab60fbeec 100644 --- a/src/taipy/gui/gui.py +++ b/src/taipy/gui/gui.py @@ -1192,6 +1192,8 @@ def _evaluate_holders(self, expr: str) -> t.List[str]: return self.__evaluator.evaluate_holders(self, expr) def _is_expression(self, expr: str) -> bool: + if self.__evaluator is None: + return False return self.__evaluator._is_expression(expr) # make components resettable diff --git a/tests/taipy/gui/builder/control/test_html.py b/tests/taipy/gui/builder/control/test_html.py index 66ed7e859..d16aa30e5 100644 --- a/tests/taipy/gui/builder/control/test_html.py +++ b/tests/taipy/gui/builder/control/test_html.py @@ -25,7 +25,7 @@ def test_html_builder(gui: Gui, test_client, helpers): 'This is a paragraph.',
'a text',
- "
",
- "This is bold text inside the paragrah.",
+ "
",
+ "This is bold text inside the paragrah.",
]
helpers.test_control_builder(gui, page, expected_list)