Skip to content

Commit 39e2d4b

Browse files
committed
fixes #820
1 parent ea1e7a8 commit 39e2d4b

2 files changed

Lines changed: 78 additions & 5 deletions

File tree

fastcore/xml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ def showtags(s):
252252

253253
FT._repr_markdown_ = highlight
254254

255-
# %% ../nbs/09_xml.ipynb #1d8a28b1
255+
# %% ../nbs/09_xml.ipynb #b1a1fbd4
256256
def __getattr__(tag):
257257
if tag.startswith('_') or tag[0].islower(): raise AttributeError
258-
tag = _fix_k(tag)
258+
tag = re.sub(r'(?<=[a-z0-9])(?=[A-Z])', '-', _fix_k(tag)).lower()
259259
def _f(*c, target_id=None, **kwargs): return ft(tag, *c, target_id=target_id, **kwargs)
260260
return _f

nbs/09_xml.ipynb

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,18 +1008,82 @@
10081008
{
10091009
"cell_type": "code",
10101010
"execution_count": null,
1011-
"id": "1d8a28b1",
1011+
"id": "b1a1fbd4",
10121012
"metadata": {},
10131013
"outputs": [],
10141014
"source": [
10151015
"#| export\n",
10161016
"def __getattr__(tag):\n",
10171017
" if tag.startswith('_') or tag[0].islower(): raise AttributeError\n",
1018-
" tag = _fix_k(tag)\n",
1018+
" tag = re.sub(r'(?<=[a-z0-9])(?=[A-Z])', '-', _fix_k(tag)).lower()\n",
10191019
" def _f(*c, target_id=None, **kwargs): return ft(tag, *c, target_id=target_id, **kwargs)\n",
10201020
" return _f"
10211021
]
10221022
},
1023+
{
1024+
"cell_type": "code",
1025+
"execution_count": null,
1026+
"id": "9cbf8947",
1027+
"metadata": {},
1028+
"outputs": [],
1029+
"source": [
1030+
"from fastcore.xml import Foo_bar,Foo_Bar,BarBaz,BarBAZ"
1031+
]
1032+
},
1033+
{
1034+
"cell_type": "markdown",
1035+
"id": "90b74b67",
1036+
"metadata": {},
1037+
"source": [
1038+
"Any `_` is converted to `-`:"
1039+
]
1040+
},
1041+
{
1042+
"cell_type": "code",
1043+
"execution_count": null,
1044+
"id": "6ea4ee4f",
1045+
"metadata": {},
1046+
"outputs": [
1047+
{
1048+
"name": "stdout",
1049+
"output_type": "stream",
1050+
"text": [
1051+
"<foo-bar></foo-bar>\n",
1052+
"<foo-bar></foo-bar>\n"
1053+
]
1054+
}
1055+
],
1056+
"source": [
1057+
"print(Foo_bar())\n",
1058+
"print(Foo_Bar())"
1059+
]
1060+
},
1061+
{
1062+
"cell_type": "markdown",
1063+
"id": "4933785e",
1064+
"metadata": {},
1065+
"source": [
1066+
"Mixed case is converted too:"
1067+
]
1068+
},
1069+
{
1070+
"cell_type": "code",
1071+
"execution_count": null,
1072+
"id": "29f14461",
1073+
"metadata": {},
1074+
"outputs": [
1075+
{
1076+
"name": "stdout",
1077+
"output_type": "stream",
1078+
"text": [
1079+
"<bar-baz></bar-baz>\n"
1080+
]
1081+
}
1082+
],
1083+
"source": [
1084+
"print(BarBaz())"
1085+
]
1086+
},
10231087
{
10241088
"cell_type": "markdown",
10251089
"id": "df973d4e",
@@ -1040,7 +1104,16 @@
10401104
]
10411105
}
10421106
],
1043-
"metadata": {},
1107+
"metadata": {
1108+
"solveit": {
1109+
"default_code": false,
1110+
"mode": "learning",
1111+
"use_fence": false,
1112+
"use_thinking": false,
1113+
"use_tools": true,
1114+
"ver": 2
1115+
}
1116+
},
10441117
"nbformat": 4,
10451118
"nbformat_minor": 5
10461119
}

0 commit comments

Comments
 (0)