Releases: nalgeon/codapi-js
0.19.8
0.19.7
0.19.6
0.19.5
0.19.4
0.19.3
Fixed depends-on
ordering for even more complex dependencies like this:
<pre><code>print("init")</code></pre>
<codapi-snippet id="init" editor="basic">
</codapi-snippet>
<pre><code>print("step a")</code></pre>
<codapi-snippet id="a" editor="basic">
</codapi-snippet>
<pre><code>print("step b")</code></pre>
<codapi-snippet id="b" editor="basic" depends-on="a">
</codapi-snippet>
<pre><code>print("main")</code></pre>
<codapi-snippet id="main" sandbox="python" editor="basic" depends-on="init b">
</codapi-snippet>
Which results in the following output:
init
step a
step b
main
0.19.2
Fixed depends-on
ordering for non-linear dependencies like this:
<pre><code>package main</code></pre>
<codapi-snippet id="package" editor="basic">
</codapi-snippet>
<pre><code>import "fmt"</code></pre>
<codapi-snippet id="import" editor="basic">
</codapi-snippet>
<pre><code>func main() { fmt.Println("hello") }</code></pre>
<codapi-snippet sandbox="go" editor="basic" depends-on="package import">
</codapi-snippet>
Code after resolving dependencies:
package main
import "fmt"
func main() { fmt.Println("hello") }
0.19.1
0.19.0
This release introduces three output-related features:
- Auto-tail output.
- Manual tail.
- Empty placeholder.
Auto-tail output
Suppose you have two code snippets where the second depends on the first:
a = 42
print("a =", a)
<codapi-snippet id="s-1" sandbox="python" editor="basic">
</codapi-snippet>
b = a * 2
print("b =", b)
<codapi-snippet sandbox="python" editor="basic" depends-on="s-1">
</codapi-snippet>
When you run the second snippet, it outputs the following:
a = 42
b = 84
It's probably not what you expect, because the code in the second snippet only prints b
. But that's how snippet dependencies worked until now.
Now you can force the snippet to ignore the output of its dependencies and print only its own output. Use the output-tail
attribute to do this:
<codapi-snippet sandbox="python" editor="basic" depends-on="s-1" output-tail>
</codapi-snippet>
Now it will only print b = 84
.
Auto-tail only works for some languages (namely JS, Lua, PHP, Python, R, Ruby, TypeScript, Shell, and SQL). The language is inferred from the sandbox
attribute by default, but you can set it manually with the syntax
attribute.
For other languages, you'll need to use the manual tail (see below).
Manual tail
You can use output-tail
to manually suppress some output and only show the tail. This works for both snippets with dependencies and regular snippets.
Suppose you use a third-party package to do some work and display the result:
import chatty
res = chatty.work()
print("res =", res)
For reasons beyond your control, chatty.work()
prints a lot of stuff to stdout. You'd like to hide it from the reader and only show the result. To do this, add the output-tail
attribute and print the horizontal rule separator (---
) to mark the "tail":
import chatty
res = chatty.work()
print("---")
print("res =", res)
<codapi-snippet sandbox="python" editor="basic" output-tail>
</codapi-snippet>
This snippet ignores everything before and including ---
and only shows res = ...
.
Empty output placeholder
Suppose you have a snippet that doesn't print anything:
res = work()
<codapi-snippet sandbox="python" editor="basic">
</codapi-snippet>
Previously, this snippet showed a blank output when run. It looked a bit confusing, and the reader might think that something was wrong.
Now, if the output is empty, the snippet will display a short reassuring ok
message.