Created
December 23, 2023 02:34
-
-
Save lxl66566/30e309e696169829524ee04503b526db to your computer and use it in GitHub Desktop.
typst content.at() will always check 'default' even if the given field exists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#let get_text(knt) = { | |
let temp = knt.at("body", default: false) | |
if temp == false { temp = knt.at("text") } | |
temp | |
} | |
#let get_text2(knt) = { | |
knt.at("body", default: knt.at("text", default: "anything")) | |
} | |
#let get_text3(knt) = { | |
knt.at("body", default: knt.at("text")) | |
// error: content does not contain field "text" and no default value was specified | |
} | |
#get_text([*20*]) | |
#get_text([20]) | |
#get_text2([*20*]) | |
#get_text2([20]) | |
#get_text3([*20*]) | |
#get_text3([20]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There may be no simple way to fix that because
default
has been calculated into aValue
before the functionat
is called.I think
knt.at("body").or(something_default)
(actuallyor_else
) is "the rust way", and it can avoid this problem caused by evaluation strategy.