object.eval with additional newline
See original GitHub issueHi
I am using Scriban with a custom object that contains basically labels.
Lets say I have the object Labels = { Label1: “L1”, Label2: “L2”}
I can use {{ Labels.Label1 }} and are getting the correct value “L1”
As we want some custom labels which are not known at runtime, we have a local object custom: [ {key: “Labels.Label1”, value: “C1”} ]
Now I have a function that looks into the custom array and tries to find an entry, and if nothing is found, it evaluates the given “item” using object.eval.
When I call
“Labels.Label1” | label “:”
I get “L1:” back, note that the colon is directly behind “L1”
When I call
“Labels.Label2” | label “:” I get “L21:” back, note that the colon is in a new line behind “L2”
Why is this happenng?
{{func byKey(label)
ret label.key == key
end}}
{{func label(item, suffix = "")
key = item
labelObject = custom | array.filter @byKey
if labelObject.size == 1
ret (labelObject[0].label) + suffix
else
ret (item | asString) + suffix
end
end
}}
Issue Analytics
- State:
- Created a year ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How can I write an `eval` command containing a new line ...
Since you're using bash : eval $'alias df5=df\ndf5 -h'. The $'...' is a "C string", and bash would expand the \n within it...
Read more >javascript - is there a way to use newlines in xdmp.eval()
I tried using a '+' sign to generate a strng over more then one line, swapping single and double quotes but no luck....
Read more >Solved: Add Line Breaks with Eval
Solved: This might be a silly question, but has anyone figured out how to add line breaks to text that has been evaluated...
Read more >Python eval(): Evaluate Expressions Dynamically
This function can be handy when you're trying to dynamically evaluate Python expressions from any input that comes as a string or a...
Read more >[Solved] Issue searching for newline character with StrFind
It works fine, except sometimes, with the return (line break) ... I just run a new test, replacing the star by another character,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We will try to put something together on your basis. Thanks so far
Thanks for the explanation, but what I see is an output, but I don’t see why it is failing. Eval is working fine in the case as I showed above, so a reproducible small program is necessary because I’m missing something here. You are mentioning a newline problem with eval, I don’t see this correctly explained.
Note, this editor allows to enter html text 😉