27 lines
618 B
Typst
27 lines
618 B
Typst
#let state-use-pyscript = state("state-use-pyscript", false)
|
|
#let state-pyscript-version = state("state-pyscript-version", none)
|
|
#let state-pyscript-headers = state("state-pyscript-headers", (:))
|
|
|
|
#let pyscript(
|
|
repl: false,
|
|
body
|
|
) = {
|
|
show raw.where(block: true, lang: "python"): it => {
|
|
state-use-pyscript.update(x => true)
|
|
it
|
|
let script = it.text;
|
|
if repl {
|
|
script = "import code\n" + script + "\ncode.interact(local=globals())"
|
|
}
|
|
html.elem(
|
|
"script",
|
|
attrs: (
|
|
type: "py",
|
|
terminal: "",
|
|
worker: "",
|
|
),
|
|
script
|
|
)
|
|
}
|
|
body
|
|
}
|