vinayak-mehta / present

A terminal-based presentation tool with colors and effects.
https://present.readthedocs.io
Apache License 2.0
4.33k stars 164 forks source link

Add jupyter notebook support #6

Open vinayak-mehta opened 4 years ago

vinayak-mehta commented 4 years ago

Can reuse nbcommands code here. Colors could be an issue.

mmdbalkhi commented 3 years ago

Hi, maybe I can help. I think we should create another class for ipynb and read it with nbcommand. I was just looking at a question, with the nbcat we read, how can we show it as a presentation? For example, with this method؟ (sorry for writing a little ugly)

this method

mmdbalkhi commented 3 years ago

I tried with your library but it didn't work. I think it is easier to read it manually.

The code I wrote for this:


import nbformat
from nbcommands import terminal

def cat(file, *args, **kwargs):
    """Concatenate Jupyter notebooks to standard output."""
    # Source: https://github.com/jbn/nbmerge
    merged, metadata = None, []

    with open(file, "r") as file:
        nb = nbformat.read(file, as_version=4)

    metadata.append(nb.metadata)

    if merged is None:
        merged = nb
    else:
        merged.cells.extend(nb.cells)

    merged_metadata = {}
    for meta in reversed(metadata):
        merged_metadata.update(meta)
    merged.metadata = merged_metadata

    return display(merged.cells)

Which unfortunately was None output.

screenshot