Skip to content

Commit

Permalink
Use picocss for defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
pydanny committed Oct 3, 2024
1 parent 2511f2d commit 3b94f50
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 52 deletions.
8 changes: 4 additions & 4 deletions nb2fasthtml/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

# %% ../nbs/00_core.ipynb 4
from fasthtml.common import *
from fasthtml.components import Zero_md
from pathlib import Path
import json

Expand All @@ -20,7 +19,8 @@ def strip_list(l, val='\n'):

# %% ../nbs/00_core.ipynb 7
def render_md(c):
return Zero_md(Script(c, type="text/markdown"))
# TODO default to FastHTML's implementation
return c

# %% ../nbs/00_core.ipynb 8
def render_md_cell(cell):
Expand Down Expand Up @@ -54,8 +54,8 @@ def render_code_output(cell,lang='python'):

# %% ../nbs/00_core.ipynb 16
def render_nb(fpath, # Path to Jupyter Notebook
wrapper=Div, #Wraps entire rendered NB
cls='', # cls to be passed to wrapper
wrapper=Main, #Wraps entire rendered NB, default is for pico
cls='container', # cls to be passed to wrapper, default is for pico
md_cell_wrapper=Div, # Wraps markdown cell
md_fn=render_md_cell, # md cell -> rendered html
code_cell_wrapper=Card, # Wraps Source Code (body) + Outputs (footer)
Expand Down
10 changes: 5 additions & 5 deletions nbs/00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
"source": [
"#| export\n",
"from fasthtml.common import *\n",
"from fasthtml.components import Zero_md\n",
"from pathlib import Path\n",
"import json"
]
Expand Down Expand Up @@ -96,7 +95,8 @@
"source": [
"#| export\n",
"def render_md(c):\n",
" return Zero_md(Script(c, type=\"text/markdown\"))"
" # TODO default to FastHTML's implementation\n",
" return c"
]
},
{
Expand Down Expand Up @@ -204,8 +204,8 @@
"source": [
"#| export\n",
"def render_nb(fpath, # Path to Jupyter Notebook\n",
" wrapper=Div, #Wraps entire rendered NB\n",
" cls='', # cls to be passed to wrapper\n",
" wrapper=Main, #Wraps entire rendered NB, default is for pico\n",
" cls='container', # cls to be passed to wrapper, default is for pico\n",
" md_cell_wrapper=Div, # Wraps markdown cell\n",
" md_fn=render_md_cell, # md cell -> rendered html\n",
" code_cell_wrapper=Card, # Wraps Source Code (body) + Outputs (footer)\n",
Expand All @@ -232,7 +232,7 @@
"## Todo\n",
"\n",
"+ Quarto stuff rendered?\n",
"+ Strip out FrankenUI"
"+ Implement default for Markdown based on FastHTML's default"
]
},
{
Expand Down
31 changes: 3 additions & 28 deletions nbs/01_app.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "2ed14f10",
"metadata": {},
"outputs": [],
Expand All @@ -22,7 +22,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"id": "607ba651",
"metadata": {},
"outputs": [],
Expand All @@ -41,34 +41,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "python3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
}
},
"nbformat": 4,
Expand Down
14 changes: 1 addition & 13 deletions nbs/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "python3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.8"
}
},
"nbformat": 4,
Expand Down
4 changes: 2 additions & 2 deletions test_pico.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

hdrs = (Script(type="module", src="https://cdn.jsdelivr.net/npm/zero-md@3?register"),)

app = FastHTML(hdrs=hdrs)
app, rt = fast_app()

nbs_dir = Path('example_nbs/')

Expand All @@ -22,7 +22,7 @@ def index_route():
relative_path = file_path.relative_to(nbs_dir)
route = f'/{relative_path.with_suffix("")}'
links.append(Li(A(str(relative_path), href=route)))
return Div(Ul(*links))
return Main(Ul(*links))

app.add_route('/', index_route)

Expand Down

0 comments on commit 3b94f50

Please sign in to comment.