Skip to content

Releases: nalgeon/codapi-js

0.10.2

18 Dec 21:28
Compare
Choose a tag to compare

Fixed the case where the external template (e.g. main.py) was served as binary by the web server and treated as such by the widget. Now the templates are always treated as plain text, regardless of the content type provided by the server.

0.10.1

16 Dec 18:49
Compare
Choose a tag to compare

Fixed (another) classless Chroma bug, which was not fixed in 0.9.2.

0.10.0

16 Dec 08:22
Compare
Choose a tag to compare

Code cells

Now you can create code cells — snippets that depend on each other. To do this, use a depends-on attribute that points to the other snippet ID. This results in Jupyter notebook-like behavior and eliminates the need for code duplication.

For example, here are the thee snippets (create, insert and select), where each depends on the previous one:

➀ Create:

```sql
create table employees (
  id integer primary key,
  name varchar(50),
  department varchar(10),
  salary integer
);
```

<codapi-snippet id="create.sql" sandbox="postgres" editor="basic">
</codapi-snippet>

➁ Insert:

```sql
insert into employees
(id, name, department, salary)
values
(11, 'Diane', 'hr', 70),
(12, 'Bob', 'hr', 78),
(21, 'Emma', 'it', 84);
```

<codapi-snippet id="insert.sql" sandbox="postgres" editor="basic" depends-on="create.sql">
</codapi-snippet>

➂ Select:

```sql
select * from employees;
```

<codapi-snippet id="select.sql" sandbox="postgres" editor="basic" depends-on="insert.sql">
</codapi-snippet>

This is how the snippets work:

  • When you run the insert snippet, it automatically creates the table before inserting the data.
  • When you run the select snippet, it automatically creates the table and inserts the records before selecting the data.

The dependencies do not have to be linear, they can form any (acyclic) graph. For example:

create ← insert-1 ← select
       ↖ insert-2 ↙

0.9.2

15 Dec 17:27
Compare
Choose a tag to compare
  • Improved innerHTML / innerText handling to reduce the number of false positives from security scanners (namely CWE-79).
  • Improved error reporting.
  • Fixed classless Chroma bug introduced in 0.9.1.

0.9.1

12 Dec 07:38
Compare
Choose a tag to compare

For editor = basic, remove double line feeds only in special cases (currently for the Chroma syntax highlighter).

0.9.0

11 Dec 21:04
Compare
Choose a tag to compare

The widget now supports sending binary files to the server. They are encoded as data URLs.

0.8.0

08 Dec 15:42
Compare
Choose a tag to compare

Changed the "Sample output" logic introduced in 0.5.0.

Fallback output

⚠️ This is an experimental feature that may be removed in future releases.

Now you can define the default code output (e.g. what happens if the reader clicks Run without changing the code). The widget will show this output if the Codapi server is down.

The default output will also be displayed in the RSS feed, which can be useful for readers who consume content through an RSS reader without ever visiting the actual page.

To use the fallback output, add an output attribute to the codapi-snippet and add an element with a default output after the snippet:

<pre>msg = "hello world"
print(msg)</pre>

<codapi-snippet sandbox="python" editor="basic" output>
</codapi-snippet>

<pre>hello world</pre>

0.7.2

06 Dec 22:18
Compare
Choose a tag to compare

The codapi-toolbar element now supports the actions attribute.

0.7.1

01 Dec 08:33
Compare
Choose a tag to compare

The snippet now replaces non-breaking spaces with regular spaces before executing the code.

0.7.0

01 Dec 08:24
Compare
Choose a tag to compare

Snippet initialization changes:

  • Non-standard @prev selector. For example, selector = @prev .code selects an element of class code within the previous sibling element.
  • Optional init-delay attribute. Delays snippet initialization by a specified number of milliseconds. ⚠️ This is an experimental feature that may be removed in future releases.
  • Snippet load event. Fires when the snippet completes its initialization.