From 3b94f50dfb66185d7c1d50ce63b024ce51580dc5 Mon Sep 17 00:00:00 2001 From: Daniel Roy Greenfeld Date: Thu, 3 Oct 2024 14:51:18 +0100 Subject: [PATCH] Use picocss for defaults --- nb2fasthtml/core.py | 8 ++++---- nbs/00_core.ipynb | 10 +++++----- nbs/01_app.ipynb | 31 +++---------------------------- nbs/index.ipynb | 14 +------------- test_pico.py | 4 ++-- 5 files changed, 15 insertions(+), 52 deletions(-) diff --git a/nb2fasthtml/core.py b/nb2fasthtml/core.py index 542599a..271ee64 100644 --- a/nb2fasthtml/core.py +++ b/nb2fasthtml/core.py @@ -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 @@ -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): @@ -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) diff --git a/nbs/00_core.ipynb b/nbs/00_core.ipynb index 8c303f7..f384e2f 100644 --- a/nbs/00_core.ipynb +++ b/nbs/00_core.ipynb @@ -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" ] @@ -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" ] }, { @@ -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", @@ -232,7 +232,7 @@ "## Todo\n", "\n", "+ Quarto stuff rendered?\n", - "+ Strip out FrankenUI" + "+ Implement default for Markdown based on FastHTML's default" ] }, { diff --git a/nbs/01_app.ipynb b/nbs/01_app.ipynb index 2e5c0dd..96aa4f4 100644 --- a/nbs/01_app.ipynb +++ b/nbs/01_app.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "2ed14f10", "metadata": {}, "outputs": [], @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": null, "id": "607ba651", "metadata": {}, "outputs": [], @@ -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, diff --git a/nbs/index.ipynb b/nbs/index.ipynb index 4fd2a8e..f3fa411 100644 --- a/nbs/index.ipynb +++ b/nbs/index.ipynb @@ -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, diff --git a/test_pico.py b/test_pico.py index 9465491..242c3c1 100644 --- a/test_pico.py +++ b/test_pico.py @@ -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/') @@ -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)