jmbuhr/quarto-molstar

Local files aren't moved with website building.

BradyAJohnston opened this issue · 8 comments

An issue I was running into while trying to get the snapshots working in #6 , was that when trialling it on a quarto blog, while the molstar.molj file was in the correct location with the original index.qmd document, upon actual rendering of the website with quarto render or quarto preview everything was copied to the docs folder, but the molstar.molj was left behind and thus broke the URL.

Is there a way to mark specific files inside of the Lua / Pandoc to be treated as assets by Quarto? I assume that would fix the problem. Similar to what is done with images and other assets already inside of Quarto.

I think the resources option under the project key would be one way to do this: https://quarto.org/docs/reference/projects/core.html

Ah yes that fixes it! Having

resources: molstar.molj

in the header YAML fixes it. Can be on a single document basis as well.

I think we'll need to put this into the docs as well, as currently local .pdb or .xtc files break as well for blog posts.

Ideally, we would do this automatically in the shortcode. Shortcodes do get the yaml metadata e.g.

local molstarMeta = pandoc.utils.stringify(meta['molstar'])

but I think they can't modify it.

Regular filters on the other hand could operate on the metadata, but this would require additional parsing for the shortcodes and their content, which feels a bit convoluted and I am not sure about the order of resource discovery and filters.
I will ask the quarto devs if they have a more elegant solution.

When we add automatic addition of resources it will only work for those explicitly mentioned in the shortcode. For snapshots such as molstar.molj we will have to ask the user to add the resources manually, unless we want to parse the snapshot files.

Oh, wait, actually, this won't we too hard. If .molj is really just plain text json, we can use https://quarto.org/docs/extensions/lua.html#json-encoding!

Would this run before or after the files are moved / rendered into another directory?

local molj = quarto.json.decode(readFile(url))

If after we still run into the same problem as before

For self-included filters one can specify if they should run before or after the quarto filter: https://quarto.org/docs/extensions/filters.html#activating-filters, but I am not sure if this is possible to specify for shortcodes and within an extension. And as it turns out my first instinct that resources would be handled by one of the quarto builtin lua filters is wrong anyways. It is handled by their typescript code: https://github.com/quarto-dev/quarto-cli/blob/aa8d33fa2b873e5f8e73ecfdc1582ee3c94236d0/src/command/render/render.ts via https://github.com/quarto-dev/quarto-cli/blob/aa8d33fa2b873e5f8e73ecfdc1582ee3c94236d0/src/command/render/resources.ts

I think the resources processing happens after pandoc's render, so after the filters.

The coresponding question to the quarto devs is at: quarto-dev/quarto-cli#1938

Looks like quarto.doc.addHtmlDependency should work to add resources at runtime as well :)