Skip to content

Commit a5d6263

Browse files
committed
fixes #681
1 parent 9e63413 commit a5d6263

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

fastcore/xml.py

+1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ def to_xml(elm, lvl=0, indent=True, do_escape=True):
213213
# %% ../nbs/09_xml.ipynb
214214
@patch
215215
def __html__(self:FT): return to_xml(self, indent=False)
216+
FT.__str__ = FT.__html__
216217

217218
# %% ../nbs/09_xml.ipynb
218219
def highlight(s, lang='html'):

nbs/09_xml.ipynb

+28-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@
480480
"source": [
481481
"#| export\n",
482482
"@patch\n",
483-
"def __html__(self:FT): return to_xml(self, indent=False)"
483+
"def __html__(self:FT): return to_xml(self, indent=False)\n",
484+
"FT.__str__ = FT.__html__"
484485
]
485486
},
486487
{
@@ -690,6 +691,32 @@
690691
"print(to_xml(P('hi', value=Div('ho'))))"
691692
]
692693
},
694+
{
695+
"cell_type": "markdown",
696+
"id": "e698c66a",
697+
"metadata": {},
698+
"source": [
699+
"FT components also stringify with `to_xml`:"
700+
]
701+
},
702+
{
703+
"cell_type": "code",
704+
"execution_count": null,
705+
"id": "a4f4e350",
706+
"metadata": {},
707+
"outputs": [
708+
{
709+
"name": "stdout",
710+
"output_type": "stream",
711+
"text": [
712+
"<div>ho</div>\n"
713+
]
714+
}
715+
],
716+
"source": [
717+
"print(Div('ho'))"
718+
]
719+
},
693720
{
694721
"cell_type": "markdown",
695722
"id": "5ad30d7c",

0 commit comments

Comments
 (0)