Skip to content

Commit 9ab0b4d

Browse files
committed
fixes #604
1 parent 59b299e commit 9ab0b4d

File tree

4 files changed

+20
-16
lines changed

4 files changed

+20
-16
lines changed

fastcore/basics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ def __new__(cls, x=None, *rest):
818818
try: x = tuple(iter(x))
819819
except TypeError: x = (x,)
820820
return super().__new__(cls, x+rest if rest else x)
821-
821+
822822
def _op(self,op,*args):
823823
if not isinstance(self,fastuple): self = fastuple(self)
824824
return type(self)(map(op,self,*map(cycle, args)))

fastcore/xml.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,13 @@ def _to_attr(k,v):
105105
if isinstance(v,bool):
106106
if v==True : return str(k)
107107
if v==False: return ''
108-
if isinstance(v,str): v = escape(v, quote=True)
108+
if isinstance(v,str): v = escape(v, quote=False)
109109
elif isinstance(v, Mapping): v = json.dumps(v)
110110
else: v = str(v)
111111
qt = '"'
112-
if qt in v: qt = "'"
112+
if qt in v:
113+
qt = "'"
114+
if "'" in v: v = v.replace("'", "'")
113115
return f'{k}={qt}{v}{qt}'
114116

115117
# %% ../nbs/11_xml.ipynb

nbs/01_basics.ipynb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@
594594
"text/markdown": [
595595
"---\n",
596596
"\n",
597-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L101){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
597+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L102){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
598598
"\n",
599599
"### get_class\n",
600600
"\n",
@@ -606,7 +606,7 @@
606606
"text/plain": [
607607
"---\n",
608608
"\n",
609-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L101){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
609+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L102){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
610610
"\n",
611611
"### get_class\n",
612612
"\n",
@@ -784,7 +784,7 @@
784784
"text/markdown": [
785785
"---\n",
786786
"\n",
787-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L145){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
787+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L146){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
788788
"\n",
789789
"#### ignore_exceptions\n",
790790
"\n",
@@ -795,7 +795,7 @@
795795
"text/plain": [
796796
"---\n",
797797
"\n",
798-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L145){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
798+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L146){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
799799
"\n",
800800
"#### ignore_exceptions\n",
801801
"\n",
@@ -2777,7 +2777,7 @@
27772777
"text/markdown": [
27782778
"---\n",
27792779
"\n",
2780-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L496){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
2780+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L501){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
27812781
"\n",
27822782
"#### GetAttr\n",
27832783
"\n",
@@ -2788,7 +2788,7 @@
27882788
"text/plain": [
27892789
"---\n",
27902790
"\n",
2791-
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L496){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
2791+
"[source](https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L501){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n",
27922792
"\n",
27932793
"#### GetAttr\n",
27942794
"\n",
@@ -4286,7 +4286,7 @@
42864286
" try: x = tuple(iter(x))\n",
42874287
" except TypeError: x = (x,)\n",
42884288
" return super().__new__(cls, x+rest if rest else x)\n",
4289-
"\n",
4289+
" \n",
42904290
" def _op(self,op,*args):\n",
42914291
" if not isinstance(self,fastuple): self = fastuple(self)\n",
42924292
" return type(self)(map(op,self,*map(cycle, args)))\n",

nbs/11_xml.ipynb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@
229229
" ['body',\n",
230230
" (['div',\n",
231231
" ('Some text\\nanother line',\n",
232-
" ['input', (), {'name': 'me'}],\n",
232+
" ['input', (), {'name': \"jph's\"}],\n",
233233
" ['img', (), {'data': 1, 'src': 'filename'}]),\n",
234234
" {'class': 'myclass another', 'style': 'padding:1; margin:2'}],),\n",
235235
" {}]),\n",
@@ -240,7 +240,7 @@
240240
"source": [
241241
"samp = Html(\n",
242242
" Head(Title('Some page')),\n",
243-
" Body(Div('Some text\\nanother line', Input(name='me'), Img(src=\"filename\", data=1),\n",
243+
" Body(Div('Some text\\nanother line', Input(name=\"jph's\"), Img(src=\"filename\", data=1),\n",
244244
" cls=['myclass', 'another'],\n",
245245
" style={'padding':1, 'margin':2}))\n",
246246
")\n",
@@ -351,11 +351,13 @@
351351
" if isinstance(v,bool):\n",
352352
" if v==True : return str(k)\n",
353353
" if v==False: return ''\n",
354-
" if isinstance(v,str): v = escape(v, quote=True)\n",
354+
" if isinstance(v,str): v = escape(v, quote=False)\n",
355355
" elif isinstance(v, Mapping): v = json.dumps(v)\n",
356356
" else: v = str(v)\n",
357357
" qt = '\"'\n",
358-
" if qt in v: qt = \"'\"\n",
358+
" if qt in v:\n",
359+
" qt = \"'\"\n",
360+
" if \"'\" in v: v = v.replace(\"'\", \"'\")\n",
359361
" return f'{k}={qt}{v}{qt}'"
360362
]
361363
},
@@ -420,7 +422,7 @@
420422
" <div class=\"myclass another\" style=\"padding:1; margin:2\">\n",
421423
"Some text\n",
422424
"another line\n",
423-
" <input name=\"me\">\n",
425+
" <input name=\"jph's\">\n",
424426
" <img src=\"filename\" data=\"1\">\n",
425427
" </div>\n",
426428
" </body>\n",
@@ -469,7 +471,7 @@
469471
"output_type": "stream",
470472
"text": [
471473
"<!doctype html><html><head><title>Some page</title></head><body><div class=\"myclass another\" style=\"padding:1; margin:2\">Some text\n",
472-
"another line<input name=\"me\"><img src=\"filename\" data=\"1\"></div></body></html>\n"
474+
"another line<input name=\"jph's\"><img src=\"filename\" data=\"1\"></div></body></html>\n"
473475
]
474476
}
475477
],

0 commit comments

Comments
 (0)