diff --git a/lona/html/__init__.py b/lona/html/__init__.py
index 50d34ffe..f2555955 100644
--- a/lona/html/__init__.py
+++ b/lona/html/__init__.py
@@ -125,13 +125,13 @@
from lona.html.nodes.scripting import NoScript, Script, Canvas
from lona.html.nodes.forms.select2 import Select2, Option2
from lona.html.nodes.web_components import Template, Slot
+from lona.html.parsing import NodeHTMLParser, parse_html
from lona.html.nodes.forms.select import Select, Option
from lona.html.nodes.demarcating_edits import Ins, Del
from lona.html.nodes.svg_and_mathml import Math, SVG
from lona.events.event_types import * # NOQA: F403
from lona.html.nodes.sectioning_root import Body
from lona.html.nodes.raw_nodes import RawHTML
-from lona.html.parsing import NodeHTMLParser
from lona.html.widgets import HTML as HTML1
from lona.html.parsing import HTML as HTML2
from lona.compat import get_client_version
diff --git a/lona/html/parsing.py b/lona/html/parsing.py
index 5043b35e..ed38d183 100644
--- a/lona/html/parsing.py
+++ b/lona/html/parsing.py
@@ -198,8 +198,12 @@ def handle_endtag(self, tag):
self.set_current_node(self._node.parent)
-def html_string_to_node_list(html_string, use_high_level_nodes=True,
- node_classes=None):
+def parse_html(
+ html_string: str,
+ use_high_level_nodes: bool = True,
+ node_classes: Dict[str, AbstractNode] | None = None,
+ flat: bool = True,
+) -> AbstractNode | List[AbstractNode]:
root_node = Node()
nodes = []
@@ -221,6 +225,9 @@ def html_string_to_node_list(html_string, use_high_level_nodes=True,
node.remove()
nodes.append(node)
+ if flat and len(nodes) == 1:
+ return nodes[0]
+
return nodes
@@ -230,6 +237,8 @@ def HTML(
node_classes: Dict[str, AbstractNode] | None = None,
) -> AbstractNode:
+ # TODO: remove HTML parsing in 2.0
+
_nodes: List[AbstractNode] = []
for node in nodes:
@@ -243,10 +252,11 @@ def HTML(
# html string
elif '<' in node or '>' in node:
- parsed_nodes = html_string_to_node_list(
+ parsed_nodes = parse_html(
html_string=node,
use_high_level_nodes=use_high_level_nodes,
node_classes=node_classes or {},
+ flat=False,
)
if len(nodes) > 1:
diff --git a/lona/html/widgets.py b/lona/html/widgets.py
index 8c12f29e..ec61d23c 100644
--- a/lona/html/widgets.py
+++ b/lona/html/widgets.py
@@ -1,5 +1,5 @@
-from lona.html.parsing import html_string_to_node_list
from lona.html.text_node import TextNode
+from lona.html.parsing import parse_html
from lona.html.widget import Widget
@@ -22,10 +22,11 @@ def __init__(self, *nodes, use_high_level_nodes=True, node_classes=None):
self.nodes.append(HTML(node))
else:
- self.nodes = html_string_to_node_list(
+ self.nodes = parse_html(
html_string=node,
use_high_level_nodes=use_high_level_nodes,
node_classes=node_classes or {},
+ flat=False,
)
else: