Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HTMLExporter] Initialize resources before widget filtering #2118

Merged
merged 2 commits into from
Mar 1, 2024

Commits on Mar 1, 2024

  1. [HTMLExporter] Initialize resources before widget filtering

    `WidgetsDataTypeFilter` is responsible for outputting appropriate
    widgets code where needed. If `resources` is passed to it, it looks inside
    for `path` and `name` parameters to figure out where to find metadata. The
    default `name` is `"Notebook"`, set in [`Exporter._init_resources`](https://github.com/jupyter/nbconvert/blob/fec19fa4d538495c3c02b85708878287463412ae/nbconvert/exporters/exporter.py#L314).
    However, in `HTMLExporter`, `resources` is passed to `WidgetsDataTypeFilter`
    [here](https://github.com/jupyter/nbconvert/blob/fec19fa4d538495c3c02b85708878287463412ae/nbconvert/exporters/html.py#L260),
    *before* `Exporter.init_resources` is called (indirectly [here](https://github.com/jupyter/nbconvert/blob/fec19fa4d538495c3c02b85708878287463412ae/nbconvert/exporters/html.py#L266)).
    
    This works ok as long as the default behavior for setting `name` is not
    needed - so all commandline conversions work. But when used programmatically
    (like [here](https://github.com/yuvipanda/notebooksharing.space/blob/f37fda886b8e565a82b1bf3f4851ad89e2b00e47/nbss/app.py#L250),
    for notebooksharing.space), this causes widgets to not be rendered, as the `text/plain` mime type is
    chosen each time.
    
    This PR explicicly calls `_init_resources` before instantiating
    `WidgetsDataTypeFilter`, so the defaulting behavior of `_init_resources`
    is exercised.
    yuvipanda committed Mar 1, 2024
    Configuration menu
    Copy the full SHA
    e041cc1 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1647991 View commit details
    Browse the repository at this point in the history