Skip to content

Commit

Permalink
fixes #76
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Jul 26, 2024
1 parent f7f9fb8 commit dccd1b7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/basic_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def mk_inp(): return Input(id='msg')
nid = 'notifications'

@rt('/')
async def get(request):
async def get():
cts = Div(
Div(id=nid),
Form(mk_inp(), id='form', ws_send=True),
Expand Down
6 changes: 4 additions & 2 deletions fasthtml/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# %% ../nbs/01_components.ipynb 2
from dataclasses import dataclass, asdict, is_dataclass, make_dataclass, replace, astuple, MISSING
from bs4 import BeautifulSoup
from bs4 import BeautifulSoup, Comment

from fastcore.utils import *
from fastcore.xml import *
Expand Down Expand Up @@ -145,4 +145,6 @@ def _parse(elm, lvl=0, indent=4):
if onlychild: return f'{tag_name}({inner})'
return f'{tag_name}(\n{spc}{inner}\n{" "*(lvl-1)*indent})'

return _parse(BeautifulSoup(html.strip(), 'html.parser'), 1)
soup = BeautifulSoup(html.strip(), 'html.parser')
for c in soup.find_all(string=risinstance(Comment)): c.extract()
return _parse(soup, 1)
1 change: 1 addition & 0 deletions fasthtml/components.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __getattr__(tag):
_re_h2x_attr_key = re.compile('^[A-Za-z_-][\\w-]*$')

def html2xt(html):
"""Convert HTML to an `xt` expression"""
...
def xt_html(tag: str, *c, id:str|None=None, cls:str|None=None, title:str|None=None, style:str|None=None, accesskey:str|None=None, contenteditable:str|None=None, dir:str|None=None, draggable:str|None=None, enterkeyhint:str|None=None, hidden:str|None=None, inert:str|None=None, inputmode:str|None=None, lang:str|None=None, popover:str|None=None, spellcheck:str|None=None, tabindex:str|None=None, translate:str|None=None, id:str|None=None, cls:str|None=None, title:str|None=None, style:str|None=None, accesskey:str|None=None, contenteditable:str|None=None, dir:str|None=None, draggable:str|None=None, enterkeyhint:str|None=None, hidden:str|None=None, inert:str|None=None, inputmode:str|None=None, lang:str|None=None, popover:str|None=None, spellcheck:str|None=None, tabindex:str|None=None, translate:str|None=None, hx_get:str|None=None, hx_post:str|None=None, hx_put:str|None=None, hx_delete:str|None=None, hx_patch:str|None=None, hx_trigger:str|None=None, hx_target:str|None=None, hx_swap:str|None=None, hx_include:str|None=None, hx_select:str|None=None, hx_indicator:str|None=None, hx_push_url:str|None=None, hx_confirm:str|None=None, hx_disable:str|None=None, hx_replace_url:str|None=None, hx_on:str|None=None, **kwargs): ...
def xt_hx(tag: str, *c, id:str|None=None, cls:str|None=None, title:str|None=None, style:str|None=None, accesskey:str|None=None, contenteditable:str|None=None, dir:str|None=None, draggable:str|None=None, enterkeyhint:str|None=None, hidden:str|None=None, inert:str|None=None, inputmode:str|None=None, lang:str|None=None, popover:str|None=None, spellcheck:str|None=None, tabindex:str|None=None, translate:str|None=None, id:str|None=None, cls:str|None=None, title:str|None=None, style:str|None=None, accesskey:str|None=None, contenteditable:str|None=None, dir:str|None=None, draggable:str|None=None, enterkeyhint:str|None=None, hidden:str|None=None, inert:str|None=None, inputmode:str|None=None, lang:str|None=None, popover:str|None=None, spellcheck:str|None=None, tabindex:str|None=None, translate:str|None=None, hx_get:str|None=None, hx_post:str|None=None, hx_put:str|None=None, hx_delete:str|None=None, hx_patch:str|None=None, hx_trigger:str|None=None, hx_target:str|None=None, hx_swap:str|None=None, hx_include:str|None=None, hx_select:str|None=None, hx_indicator:str|None=None, hx_push_url:str|None=None, hx_confirm:str|None=None, hx_disable:str|None=None, hx_replace_url:str|None=None, hx_on:str|None=None, **kwargs): ...
Expand Down
2 changes: 1 addition & 1 deletion fasthtml/xtend.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def Titled(title: str='FastHTML app', *args, target_id=None, id=None, cls=None,
"""An HTML partial containing a `Title`, and `H1`, and any provided children"""
...

def Socials(title, site_name, description, image, url, w=1200, h=630, twitter_site=None, creator=None, card='summary'):
def Socials(title, site_name, description, image, url=None, w=1200, h=630, twitter_site=None, creator=None, card='summary'):
"""OG and Twitter social card headers"""
...

Expand Down
16 changes: 13 additions & 3 deletions nbs/01_components.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"source": [
"#| export\n",
"from dataclasses import dataclass, asdict, is_dataclass, make_dataclass, replace, astuple, MISSING\n",
"from bs4 import BeautifulSoup\n",
"from bs4 import BeautifulSoup, Comment\n",
"\n",
"from fastcore.utils import *\n",
"from fastcore.xml import *\n",
Expand Down Expand Up @@ -479,13 +479,15 @@
" if onlychild: return f'{tag_name}({inner})'\n",
" return f'{tag_name}(\\n{spc}{inner}\\n{\" \"*(lvl-1)*indent})'\n",
"\n",
" return _parse(BeautifulSoup(html.strip(), 'html.parser'), 1)"
" soup = BeautifulSoup(html.strip(), 'html.parser')\n",
" for c in soup.find_all(string=risinstance(Comment)): c.extract()\n",
" return _parse(soup, 1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c2802e69",
"id": "8190a502",
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -538,6 +540,14 @@
"#|hide\n",
"import nbdev; nbdev.nbdev_export()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "814cf69a",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit dccd1b7

Please sign in to comment.