-
Notifications
You must be signed in to change notification settings - Fork 497
Assets: allow passing direct HTML content into asset
kwarg (for Pluto support)
#2726
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
base: master
Are you sure you want to change the base?
Conversation
Marking this as draft since it still needs docs and tests :) I'll wait to hear what you think before I continue Plugin ideaI'd also love your input on what a good user-facing API would be, and how to make this an easy plugin to use. My idea right now (but I have not looked into the plugin system much, so I'm not fully aware of what is possible): Adding notebooks to your siteYou store your Pluto
Then, to include notebook content in a Documenter page, I was thinking to use HTML Custom Elements. E.g.
SetupAnd your make.jl file looks like: # ... usual imports
pluto_assets = PlutoDocumenter.generate()
makedocs(;
assets=[pluto_assets..., more...],
...
) |
Allowing raw HTML head content seems fine to me. Regardless of the result of the discussion below, I think it's worth having this -- this seems like a useful thing other people can use to hack stuff together. For the Pluto case, I have one question though -- do you want it to be included in every page? I guess ideally it would get added into the I think the at-raw block is a good MVP. In the longer term, my two cents would be to try to turning this into a plugin package (DocumenterPluto?) that then defines a custom block. Something like this:
That might take care of the unnecessary duplication and the need to manually pass the asset -- the at-pluto block is present, then we add the Pluto stuff into We don't have a really great plugin API (contributions very welcome!), but in DocumenterMermaid I hacked something similar together in this way (here: https://github.com/JuliaDocs/DocumenterMermaid.jl/blob/main/src/DocumenterMermaid.jl):
In the Pluto case, you want this to be in the HEAD. What might work is, instead of pushing a block to the page AST, you just push the |
Thanks! I added docs, but I'm not sure how to write the test. I thought to check if |
Thanks for the ideas! The
This sounds like a good approach! How can I do this selectively for different pages, so that only the pages with Pluto notebooks load the assets? |
I don't think HTMLWriter allows for per-page assets? It seems like this rendering happens here: Documenter.jl/src/html/HTMLWriter.jl Lines 1048 to 1049 in 90a1a0e
and the nav node doesn't actually hold the page struct, only its key, so it's not possible to do it that way either. What solution were you thinking of for dynamic HEAD injection @mortenpi? Of course the way you select the page is a bit simpler: see e.g here, but you can replace |
I mean specifically for writing tests for this PR: I'm wondering what to write in test/htmlwriter.jl so that I can check the output HTML contents. |
The best option would probably to test this as part of the examples tests.
I'd add it to one example build, and then grep-check if it appears in the generated HTML.
No. We'd have to add support for that 🙂 Just thinking out loud: |
This PR should be ready now 👍 |
Hi! 👋
I am working on adding easy Pluto support to Documenter via a plugin 😊 I am not yet sure about the user-facing API, but I got an implementation working where Pluto is embedded inside Documeter pages (alongside existing content).
Demo
Here is a WIP demo of the Pluto notebook embedded in Documenter.jl. Note that you can "Edit or run this notebook" with binder!
https://dashing-custard-e9c5cc.netlify.app/
The code for this demo is here: https://github.com/fonsp/Documenter.jl-Pluto-embed-test
No
<iframe>
I currently do the embedding without
<iframe>
, but with a Custom Element. This is also used in other Pluto-embedding web sites like Computational Thinking. The benefit is better performance, better scrolling, accessibility and other UA features, and your notebook content can be indexed by search engines.For this embedding to work, I need to place content in the
<head>
of the Documenter.jl output HTML. I saw that there is an existingHTMLAsset
system, but unfortunately this is hard to use in our case: the<head>
content of Pluto notebooks contains more asset types than just JS, CSS and ICO. We also don't have the<head>
content in a Julia format: the<head>
is generated dynamically by our bundler. So to useHTMLAsset
, we would first need a DOM parser to parse the head content, then convert it intoHTMLAsset
objects...Changes
This PR adds the ability to add raw HTML content as an element of the
assets
kwarg, using the new typeRawHTMLHeadContent
. This gives plugins more flexibility in loading<head>
content.Take a look at the code changes for the implemented new types.
I'm also happy to hear other ideas for implementing this goal!
Existing solutions
There are some existing solutions for Pluto in Documenter: