77 PlutoBlock
88
99MarkdownAST element produced by the `@pluto` expander. Holds the parsed
10- attributes of one ```` ```@pluto ```` code block:
10+ attributes of one ```` ```@pluto ```` code block.
11+
12+ The only recognised special key is:
1113
1214- `notebook :: Union{String, Nothing}` — path to a local `.jl` file, relative to
1315 the Documenter source root. When set, the plugin runs the notebook headlessly
1416 and copies both the `.jl` and the generated `.plutostate` into the build
15- output.
16- - `url :: Union{String, Nothing}` — URL of a hosted notebook file
17- (`pluto_notebookfile`).
18- - `state :: Union{String, Nothing}` — URL of a hosted `.plutostate` file.
19- - `binder :: Union{String, Nothing}` — optional Binder launch URL.
20- - `disable_ui :: Bool` — whether to hide Pluto's UI chrome (default `true`).
17+ output, then exposes them to the frontend as `window.pluto_notebookfile` and
18+ `window.pluto_statefile`.
2119
22- Exactly one of `notebook` or `url` must be set. When `url` is set, `state` is
23- required too.
20+ Every other key must start with `pluto_` and is forwarded verbatim to the
21+ frontend as `window.<key> = <value>;` in the launch-parameters script. Typical
22+ keys for pre-hosted notebooks are `pluto_notebookfile` and `pluto_statefile`;
23+ see Pluto's frontend for the full list (`pluto_disable_ui`, `pluto_binder_url`,
24+ `pluto_recording_url`, …).
2425
25- The resolved URLs used by the frontend (`window.pluto_notebookfile`,
26- `window. pluto_statefile`) are filled in by the builder step before domify runs .
26+ Exactly one of the following must hold: `notebook` is set, *or* both
27+ `pluto_notebookfile` and ` pluto_statefile` are set .
2728"""
2829mutable struct PlutoBlock <: Documenter.AbstractDocumenterBlock
29- notebook :: Union{String, Nothing}
30- url :: Union{String, Nothing}
31- state :: Union{String, Nothing}
32- binder :: Union{String, Nothing}
33- disable_ui :: Bool
34- # Filled in by the builder: final URLs the rendered <script> will point at.
35- # For a local `notebook`, these become build-relative paths.
30+ notebook :: Union{String, Nothing}
31+ pluto_params :: Dict{String, Any}
32+ # Filled in by the builder for local notebooks: build-root-relative paths
33+ # that domify turns into page-relative hrefs.
3634 resolved_notebook :: Union{String, Nothing}
3735 resolved_state :: Union{String, Nothing}
3836end
3937
40- function PlutoBlock (; notebook= nothing , url= nothing , state= nothing , binder= nothing , disable_ui= true )
41- PlutoBlock (notebook, url, state, binder, disable_ui, nothing , nothing )
42- end
38+ PlutoBlock (; notebook= nothing , pluto_params= Dict {String,Any} ()) =
39+ PlutoBlock (notebook, pluto_params, nothing , nothing )
4340
4441abstract type PlutoExpander <: Documenter.Expanders.ExpanderPipeline end
4542Selectors. order (:: Type{PlutoExpander} ) = 7.9
@@ -57,36 +54,36 @@ function Selectors.runner(::Type{PlutoExpander}, node, page, doc)
5754 return
5855end
5956
60- # The block body is TOML. Keys accepted (case-insensitive, snake-cased):
61- # notebook | url | state | binder | disable_ui
57+ # The block body is TOML. `notebook` is special; every other key must start
58+ # with `pluto_` and is forwarded as-is to `window.<key>` in the launch script.
6259function _parse_pluto_block (code:: AbstractString )
6360 raw = isempty (strip (code)) ? Dict {String,Any} () : TOML. parse (code)
64- # Normalise keys to lowercase so `Notebook=` and `notebook=` both work.
65- kv = Dict {String,Any} (lowercase (k) => v for (k, v) in raw)
66-
67- notebook = get (kv, " notebook" , nothing )
68- url = get (kv, " url" , nothing )
69- state = get (kv, " state" , nothing )
70- binder = get (kv, " binder" , nothing )
71- disable_ui = get (kv, " disable_ui" , true )
7261
73- if notebook === nothing && url === nothing
74- error (" `@pluto` block must set either `notebook = \" path/to/notebook.jl\" ` or `url = \" …\" ` + `state = \" …\" `." )
62+ notebook = nothing
63+ pluto_params = Dict {String,Any} ()
64+ for (k, v) in raw
65+ if k == " notebook"
66+ v isa AbstractString || error (" `@pluto`: `notebook` must be a string." )
67+ notebook = String (v)
68+ elseif startswith (k, " pluto_" )
69+ pluto_params[k] = v
70+ else
71+ error (" `@pluto`: unknown key `$k `. Use `notebook = \" …\" ` or a key starting with `pluto_`." )
72+ end
7573 end
76- if notebook != = nothing && url != = nothing
77- error (" `@pluto` block sets both `notebook` and `url`; use exactly one." )
74+
75+ # Default: hide Pluto's UI chrome in docs builds.
76+ get! (pluto_params, " pluto_disable_ui" , true )
77+
78+ has_urls = haskey (pluto_params, " pluto_notebookfile" ) && haskey (pluto_params, " pluto_statefile" )
79+ if notebook === nothing && ! has_urls
80+ error (" `@pluto` block must set either `notebook = \" path/to/notebook.jl\" ` or both `pluto_notebookfile` and `pluto_statefile`." )
7881 end
79- if url != = nothing && state === nothing
80- error (" `@pluto` block with `url` must also set `state = \" …plutostate \" ` ." )
82+ if notebook != = nothing && ( haskey (pluto_params, " pluto_notebookfile " ) || haskey (pluto_params, " pluto_statefile " ))
83+ error (" `@pluto` block sets `notebook` together with `pluto_notebookfile`/`pluto_statefile`; use one or the other ." )
8184 end
8285
83- PlutoBlock (;
84- notebook = notebook isa AbstractString ? String (notebook) : nothing ,
85- url = url isa AbstractString ? String (url) : nothing ,
86- state = state isa AbstractString ? String (state) : nothing ,
87- binder = binder isa AbstractString ? String (binder) : nothing ,
88- disable_ui = Bool (disable_ui),
89- )
86+ return PlutoBlock (; notebook, pluto_params)
9087end
9188
9289# Documenter's search-index and link-check phases flatten pages to plain text
0 commit comments