quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.78k stars 309 forks source link

Converting custom Mime-Types to PDF and docx #919

Open divyansshhh opened 2 years ago

divyansshhh commented 2 years ago

Does quarto support converting custom mime-types to pdf? Maybe something like preprocessors in nbconvert?

Currently if I have a custom mime-type it just returns the object type in PDF and Docx formats.

jjallaire commented 2 years ago

Could you provide an example? Here is where we interrogate and choose between mime types for cell output: https://github.com/quarto-dev/quarto-cli/blob/254acfe257b08c7ee7b372060100c0a56c608391/src/core/jupyter/display-data.ts#L40

If there is a type not anticipated then we probably don't do anything with it. If you provide an example then I can see what we might be able to do better / what type of hooks we could provide to make it possible for users to handle explicitly.

divyansshhh commented 2 years ago

Let's say I have the geojson-extension which handles the rendering of application/geo+json mime-type in jupyter-lab.

Now what I want is that when such a mime-type is encountered, which isn't in the src/mime.ts, I should be able to write some code to process it differently. In this example, I might want to convert that into an image.

jjallaire commented 2 years ago

Okay, I see that. One issue I see here is that by using the geojson extension you are hard-binding your notebook to Jupyter Lab. If you open the notebook in VS Code, Pycharm, Classic Jupyter NB, Google Colab etc. then the Geojson doesn't display. Quarto falls into the same category. Ideally you would take the GeoJSON and render it w/ something like ipyleaflet, which would then work fine in all of the above environments including Quarto.

divyansshhh commented 2 years ago

geojson-extension was just an example. This would actually affect any mime-renderers written for jupyterlab. I was looking at the documentation for quarto, do you think a custom filter would help in this case?

divyansshhh commented 2 years ago

Also, I do agree that geojson wouldn't render on the other platforms but I am only concerned with jupyterlab.

jjallaire commented 2 years ago

Okay, I think what you want is a notebook filter, which will give you the raw JSON which you can manipulate as you wish using nbformat (e.g. replacing the geojson output with an image). See https://quarto.org/docs/authoring/filters.html#notebook-filters