Add transformNotebook function to Vite Observable plugin #39
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Following #30, This PR adds a
transformNotebook
function to the Observable Vite plugin which allows you to transform the parsed notebook during build. A sample use case of this is to modify or remove the title heading, replacing it with something else.1 I'm sure there are many interesting and also some less reputable use-cases. It's niche, but when it's useful, it's seems useful.No-op sample usage:
My usage here: https://github.com/rreusser/notebooks/blob/276dd592e5bb0eb6943931e5c3b072cad2c652e9/vite.config.js#L41-L52
I was hesitant to tack on a bunch of escape hatches to the lovely vite plugin, but perhaps the additions are reasonable because 1) they add no complexity, and 2) are reasonable accommodations for the realities of working notebooks into a website.
Footnotes
The particular reason why removing the in-notebook title heading element was desirable for me is silly: I wanted the content to be 640px wide, but then the header was not full-bleed, and I didn't want to widen the
main
notebook element and then have to compensate by re-narrowing all cells except the header. I ended up using pseudo-elements transformed to make the header run off the page and look full-bleed, which worked, but it was a mess. I also wanted to add the author and date, which could have been accomplished by inserting it into the notebook, but it was easier to just move that to the page template and usetransformNotebook
to remove the heading. ↩