Skip to content

Use nbformat to improve formatting of cell outputs #8

@audreyfeldroy

Description

@audreyfeldroy

Currently, the rendering of Jupyter notebook cell outputs is basic and doesn't correctly handle rich formats like HTML, images, or styled text. This leads to a poor representation of the notebook content on the blog.

To fix this, we should use the nbformat library, which is the standard for working with .ipynb files. It allows us to parse the notebook structure and correctly interpret the various output types.

Acceptance Criteria

  1. Update the notebook rendering logic in main.py.
  2. Use nbformat.reads() to parse the notebook content.
  3. Iterate through the notebook cells and their outputs.
  4. Implement logic to handle different output_type values (display_data, execute_result, stream, error).
  5. Prioritize rendering text/html data if available, falling back to text/plain.
  6. Handle rich media, such as images (e.g., image/png), by correctly embedding them in the final HTML.
  7. Add nbformat to the project dependencies in pyproject.toml and ensure dependencies are synced.

The issue will be considered resolved when cell outputs in the blog posts are rendered with the same fidelity as they appear in a Jupyter environment.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions