quarto-dev / quarto-dev/quarto-cli

quarto convert: support an option to retain empty code cells

Open
#11,690 0 comments 1 reaction 1 assignee View on GitHub

@cscheid is already working on this.

Since Dec 16, 2024.

convert engines-jupyter enhancement
Dominant language
JavaScript
Stars
6k
Forks
458
Avg merge
1d 9h
Merged PRs (30d)
41

Description

Discussed in https://github.com/quarto-dev/quarto-cli/discussions/11685

Originally posted by anandology December 14, 2024

Description

The quarto convert command when converting from qmd to ipynb, drops all the code cells which are empty. This may be fine in most use cases, there are cases where this is undesirable.

It would be nice to have an option to retain empty code cells as well.

Sample Use Case

I teach programming courses and I use quarto convert to generate ipynb files from qmd sources. These notebooks are used by the students of the course. The following is an example where empty cells are needed.

The following code creates a new function `square`.

```{python}
def square(x):
    return x*x
```

```{python}
square(4)
````

Can you try creating a new function `cube` to compute cube a of number 
in the following cell?

```{python}

```

Check if your `cube` function is working correctly by running the following examples.

```{python}
print(cube(2))
print(cube(3))
print(cube(4))
```

The issue

The third code cell in the above example gets dropped.

The work-around is to make the code cell not empty by adding a comment, but I would prefer to keep it empty.

The Code

The part of the code that drops empty cells is at:

https://github.com/quarto-dev/quarto-cli/blob/main/src/core/jupyter/jupyter.ts#L422

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.