mkdocs-jupyter icon indicating copy to clipboard operation
mkdocs-jupyter copied to clipboard

Images not getting exported to the correct location

Open thesteve0 opened this issue 9 months ago • 4 comments

Greetings - trying to get my images to show up in my mkdocs rendered pages. I saw https://github.com/danielfrg/mkdocs-jupyter/issues/53

And I did a little research. It looks like nbconvert has the ability to encode the image as part of the build process https://nbconvert.readthedocs.io/en/latest/config_options.html#exporter-options

HTMLExporter.embed_images : Bool
    Default: False
    Whether or not to embed images as base64 in markdown cells.

Perhaps we could expose this flag as a setting for the plugin?

The other option would be to add something in https://github.com/danielfrg/mkdocs-jupyter/blob/main/src/mkdocs_jupyter/nbconvert2.py that:

  1. Looks for image links in the notebook
  2. If present, grab the image and put it in the same directory where index.html will get written
  3. Rewrite the paths in the html to point to the new location

This solution would have the benefit of clearly organizing which images go with which notebook.

The HTMLExporter option seems like the easiest and least intrusive.

thesteve0 avatar Feb 04 '25 05:02 thesteve0

Yeah i think we should just support the nbconvert options. Are you able to make a quick PR? should be easy to test.

danielfrg avatar Feb 04 '25 15:02 danielfrg

Hhhhmmmm, don't really have much knowledge about mkdocs plugins or nbconvert. Here is me thinking through it a bit with some questions at the end

So it seems like we would add the options to the mkdocs.yaml under the plugin part for this plugin.

My first guess is that this is a dict with entries like {HTMLExporter.attribute: value,} Probably should be the same in the mkdocs.yaml as well.

I see some of the plugin options from mkdocs.yaml are passed into the constructor for nb2html https://github.com/danielfrg/mkdocs-jupyter/blob/303343f063ac8be739657d10dae326011a173e59/src/mkdocs_jupyter/nbconvert2.py#L38

So we we would have a init parameter called HTMLExporter_options

But when I look at all the options, some of those are things that we handle explicitly as a separate init parameter.

For example:

HTMLExporter.exclude_input : Bool
    Default: False
    This allows you to exclude code cell inputs from all templates if set to True.

Seems to correspond to this parameter

https://github.com/danielfrg/mkdocs-jupyter/blob/303343f063ac8be739657d10dae326011a173e59/src/mkdocs_jupyter/nbconvert2.py#L46

Questions:

  1. Does the dict idea make the most sense
  2. Is this the line where the mkdocs.yaml configuration is passed to the HTMLExporter? https://github.com/danielfrg/mkdocs-jupyter/blob/303343f063ac8be739657d10dae326011a173e59/src/mkdocs_jupyter/nbconvert2.py#L119
  3. Where in that file would I actually write the code to do this?

thesteve0 avatar Feb 04 '25 18:02 thesteve0

Hey @danielfrg any updates on this?

thesteve0 avatar Feb 08 '25 01:02 thesteve0

Ping

thesteve0 avatar Mar 13 '25 17:03 thesteve0