<script type="module" src="https://cdn.jsdelivr.net/npm/zero-md@3?register"></script>
nb
Create FastHTML from a NB
= Path('../example_nbs/')
example_nb_dir with open(example_nb_dir/'explaining_xt_components.ipynb', 'r') as f: xt_nb = json.load(f)
strip_list
strip_list (l, val='\n')
render_md
render_md (c)
render_md_cell
render_md_cell (cell)
# show(Div(*map(render_md_cell,[o for o in xt_nb['cells'][:3] if o['cell_type']=='markdown'])))
get_nb_lang
get_nb_lang (nb)
render_code_source
render_code_source (cell, lang='python')
# show(Div(*map(render_code_source,[o for o in xt_nb['cells'][:10] if o['cell_type']=='code'])))
render_code_output
render_code_output (cell, lang='python')
= Path('../example_nbs/')
nbs_dir with open(nbs_dir/'00_core.ipynb', 'r') as f: nb = json.load(f)
# render_code_output(nb['cells'][9])
# show(Div(*map(render_code_output,[o for o in xt_nb['cells'][:20] if o['cell_type']=='code'])))
render_nb
render_nb (fpath, wrapper=functools.partial(<function ft_hx at 0x7f08d34869e0>, 'main'), cls='container', md_cell_wrapper=functools.partial(<function ft_hx at 0x7f08d34869e0>, 'div'), md_fn=<function render_md_cell>, code_cell_wrapper=<function Card>, cd_fn=<function render_code_source>, out_fn=<function render_code_output>, **kwargs)
Type | Default | Details | |
---|---|---|---|
fpath | Path to Jupyter Notebook | ||
wrapper | partial | functools.partial(<function ft_hx at 0x7f08d34869e0>, ‘main’) | Wraps entire rendered NB, default is for pico |
cls | str | container | cls to be passed to wrapper, default is for pico |
md_cell_wrapper | partial | functools.partial(<function ft_hx at 0x7f08d34869e0>, ‘div’) | Wraps markdown cell |
md_fn | function | render_md_cell | md cell -> rendered html |
code_cell_wrapper | function | Card | Wraps Source Code (body) + Outputs (footer) |
cd_fn | function | render_code_source | code cell -> code source rendered html |
out_fn | function | render_code_output | code cell -> code output rendered html |
kwargs |
Todo
- Quarto stuff rendered?
- Implement default for Markdown based on FastHTML’s default