work on pyscript/typst api
This commit is contained in:
parent
84bf7ce78c
commit
fe4b003971
3 changed files with 62 additions and 56 deletions
|
|
@ -26,22 +26,12 @@
|
|||
// TODO DOCUMENT THIS!
|
||||
|
||||
#let pyscript-show(it) = {
|
||||
let metadata = if it.lang != "python" {
|
||||
none
|
||||
} else {
|
||||
parse-pep723(it.text)
|
||||
let metadata = parse-pep723(it.text)
|
||||
if metadata == none {
|
||||
metadata = (:)
|
||||
}
|
||||
if metadata != none and "pyscript" in metadata.at(
|
||||
"tool", default: (:)
|
||||
) and metadata.at(
|
||||
"tool", default: (:)
|
||||
).at(
|
||||
"pyscript", default: (:)
|
||||
).at(
|
||||
"run", default: true
|
||||
) {
|
||||
state-use-pyscript.update(x => true)
|
||||
context {
|
||||
state-use-pyscript.update(x => true)
|
||||
context {
|
||||
let config = metadata.at("tool", default: (:)).at("pyscript", default: (:))
|
||||
|
||||
let pyscript-config = (:)
|
||||
|
|
@ -67,10 +57,24 @@
|
|||
let attrs = (
|
||||
type: "py"
|
||||
)
|
||||
if true { // TODO: pygame ?
|
||||
let default_val_terminal = true
|
||||
let default_val_worker = true
|
||||
let default_val_canvas = none
|
||||
// TODO: canvas: can only be used once by page, need inserting canvas html tag and pyscript hook to link it to pyodide
|
||||
if config.at("pygame", default: false) {
|
||||
default_val_terminal = false
|
||||
default_val_worker = false
|
||||
default_val_canvas = "canvas"
|
||||
}
|
||||
if config.at("terminal", default: true) {
|
||||
attrs.insert("terminal", "")
|
||||
}
|
||||
if config.at("worker", default: true) {
|
||||
attrs.insert("worker", "")
|
||||
}
|
||||
if config.at("canvas", default: default_val_canvas) not in (none, false) {
|
||||
attrs.insert("canvas", config.at("canvas", default: default_val_canvas))
|
||||
}
|
||||
|
||||
if pyscript-config != (:) {
|
||||
attrs.insert("config", json.encode(pyscript-config))
|
||||
|
|
@ -80,47 +84,28 @@
|
|||
if config.at("repl", default: false) {
|
||||
script = "import code\n" + script + "\ncode.interact(banner='', local=globals())"
|
||||
}
|
||||
|
||||
if not config.at("hide-code", default: false) { //and not config.at("hide-meta", default: false) {
|
||||
it
|
||||
let displayed-code = it.text;
|
||||
if config.at("hide-meta", default: false) {
|
||||
displayed-code = displayed-code.replace(get-pep723(displayed-code), "").trim("\n")
|
||||
}
|
||||
|
||||
if not config.at("hide-code", default: false) {
|
||||
raw(
|
||||
displayed-code,
|
||||
block: true,
|
||||
lang: "python",
|
||||
align: it.align,
|
||||
syntaxes: it.syntaxes,
|
||||
theme: it.theme,
|
||||
tab-size: it.tab-size,
|
||||
)
|
||||
}
|
||||
/* Don't work, will require some way of unsetting show rule of something
|
||||
} else if not config.at("hide-code", default: false) and config.at("hide-meta", default: false) {
|
||||
let meta-lines = get-pep723(it.text).split("\n")
|
||||
let code-lines = it.text.split("\n")
|
||||
let meta-line-0 = none
|
||||
for i in range(code-lines.len()) {
|
||||
let match = true
|
||||
for j in range(meta-lines.len()) {
|
||||
if (i + j) >= code-lines.len() or meta-lines.at(j) != code-lines.at(i + j) {
|
||||
match = false
|
||||
break
|
||||
}
|
||||
if match {
|
||||
meta-line-0 = i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
show raw.line: it => {
|
||||
if meta-line-0 == none {
|
||||
it
|
||||
} else if it.number > meta-line-0 and it.number <= meta-line-0 + meta-lines.len() {
|
||||
none
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}
|
||||
it
|
||||
}*/
|
||||
|
||||
html.elem(
|
||||
"script",
|
||||
attrs: attrs,
|
||||
script
|
||||
)
|
||||
}} else {
|
||||
it
|
||||
}
|
||||
//raw(block: true, lang: "json", json.encode(metadata))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue