fonsp/PlutoUtils.jl

Pluto to HTML without a browser

fonsp opened this issue Β· 10 comments

fonsp commented

Not too difficult, just some Julia code that produces roughly the same HTML as the JS code (have a look at the .html export). You can use https://github.com/yurivish/Hyperscript.jl or just Markdown.withtag to write it

fonsp commented

@shashi is on it

It would be great if this export function also supported only exporting the main part of the document, that would make it easy to include in a full HTML page with e.g. Franklin.jl.

fonsp commented

@shashi is writing it in Franklin, I think this is what he is going for!

Here is another potential use case for this feature:

Over at ParticleFilters.jl we would like to use Pluto as an "executable documentation" for our repo. Currently we are using Jupyter notbooks for this which has the benefit that users can view the notebook directly in the browser (of course only the static, non-interactive version) without the need to download or run anything.

Of course a 1-click deploy to project binder would solve this issue, however, for our use case it would be totally sufficient to just programmatically export the notebook to static HTML.
Ideally, I am envisioning to export the notebook to HTML automatically through the CI job that also builds the documentation (i.e. as part of docs/make.jl).

Why don't we do this with a headless chromium browser like the tests do?
(Sketching this up - be right back!!)

A solution can be the following script.

Steps:

  1. Open pluto without password (use startup.jl from binder template)
  2. Save url
  3. mkdir test_whatever
  4. npm i puppeteer
  5. save the below as 'export.js'
  6. node export.js http://localhost:1234/ /path/to/your/notebook /path/to/html/folder/you/want/it/saved/in/

Note argument 1 (pluto) url has trailing slash, argument 2 is your notebook, argument 3 is a folder
also requires your notebook to be ready in 5 seconds. I'll sketch something smarter up if it works for you

πŸŽ‰ πŸŽ‰ πŸŽ‰ πŸŽ‰

const puppeteer = require('puppeteer');
const url = process.argv[2];
const file = process.argv[3];
const dir = process.argv[4];


(async () => {
  const browser = await puppeteer.launch();
  const page = await browser.newPage();
  const client = await page.target().createCDPSession();
  await client.send('Page.setDownloadBehavior', {
    behavior: 'allow', downloadPath: dir || './'
  });
  const goto = `${url}open?path=${encodeURIComponent(file)}`;
  await page.goto(goto);
  console.log(goto)

  await page.waitFor(5000);
  await page.click('#at_the_top .toggle_export');
  await page.waitFor(5000);
  await page.click("aside#export a:nth-child(3)")

  await browser.close();
})();

@lassepe does this work?

fonsp commented

We'll build something equivalent to HTML export into pluto soonish

Would be great to have this in the next two weeks for use in a class that I am teaching in Julia! Also @mossr could probably benefit for his course materials: https://github.com/sisl/AA120Q

@fonsp I believe you had something like a Github Action to deploy Pluto notebooks?

@VarLad github action for deploying Pluto notebooks would be awesome. Do you know if it's a thing now?

fonsp commented