Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversion from ipynb to qmd removes first text cell(s) #12042

Open
MartinSchobben opened this issue Feb 7, 2025 · 1 comment
Open

Conversion from ipynb to qmd removes first text cell(s) #12042

MartinSchobben opened this issue Feb 7, 2025 · 1 comment
Labels
bug Something isn't working convert Related to quarto convert command jupyter

Comments

@MartinSchobben
Copy link

Bug description

I noticed that text disappeared when converting a Jupyter Notebook to a
Quarto Notebook. It appears to only happen to text cells that occur
before the first code cell.

Steps to reproduce

To showcase this I will convert an qmd file to an ipynb file and
back again. Check source files in this GitHub
repo
.

This is the starting point:

---
title: "My Document"
format: html
jupyter: python3
keep-ipynb: true
---

## Introduction

Here I place some text.

## Results

::: {.cell execution_count=3}
``` {.python .cell-code}
import os
```
:::


Some more text.

::: {.cell execution_count=4}
``` {.python .cell-code}
1 + 1
```

::: {.cell-output .cell-output-display execution_count=4}
```
2
```
:::
:::
!quarto convert input-document.qmd
Converted to input-document.ipynb

The output ipynb is as expected, see
here.

Here one can see that some text is missing when I now convert this
back to a qmd file.

!quarto convert input-document.ipynb --output output-document.qmd
Converted to output-document.qmd

---
title: My Document
format: html
jupyter: python3
keep-ipynb: true
---

::: {.cell execution_count=7}
``` {.python .cell-code}
import os
```
:::


Some more text.

::: {.cell execution_count=8}
``` {.python .cell-code}
1 + 1
```

::: {.cell-output .cell-output-display execution_count=8}
```
2
```
:::
:::

Expected behavior

No response

Actual behavior

No response

Your environment

! lsb_release -a
No LSB modules are available.
Distributor ID: Linuxmint
Description:    Linux Mint 21.2
Release:    21.2
Codename:   victoria
! code --version
1.97.0
33fc5a94a3f99ebe7087e8fe79fbe1d37a251016
x64

Quarto check output

!quarto --version
1.6.40
!quarto check
Quarto 1.6.40
[✓] Checking environment information...
      Quarto cache location: /home/nicola/.cache/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.4.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.46.3: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.6.40
      Path: /opt/quarto/bin

(|) Checking tools....................[✓] Checking tools....................OK
      TinyTeX: (external install)
      Chromium: (not installed)

(|) Checking LaTeX....................(/) Checking LaTeX....................[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /home/nicola/.TinyTeX/bin/x86_64-linux
      Version: 2024

(|) Checking basic markdown render....(/) Checking basic markdown render....(-) Checking basic markdown render....(\) Checking basic markdown render....(|) Checking basic markdown render....(/) Checking basic markdown render....[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.12.9 (Conda)
      Path: /home/nicola/miniconda3/envs/quarto-cli/bin/python
      Jupyter: 5.7.2
      Kernels: python3, 02_floodmapping, pangeo-workflow-examples, floodmapping, 04_l-band-sar, mrs-env, tuw_education_notebooks, 01_classification, classification, microwave-remote-sensing

(|) Checking Jupyter engine render....(/) Checking Jupyter engine render....(-) Checking Jupyter engine render....(\) Checking Jupyter engine render....(|) Checking Jupyter engine render....(/) Checking Jupyter engine render....(-) Checking Jupyter engine render....(\) Checking Jupyter engine render....(|) Checking Jupyter engine render....(/) Checking Jupyter engine render....(-) Checking Jupyter engine render....(\) Checking Jupyter engine render....(|) Checking Jupyter engine render....(/) Checking Jupyter engine render....(-) Checking Jupyter engine render....[✓] Checking Jupyter engine render....OK

(|) Checking R installation...........(/) Checking R installation...........[✓] Checking R installation...........OK
      Version: 4.4.2
      Path: /usr/lib/R
      LibPaths:
        - /home/nicola/R/x86_64-pc-linux-gnu-library/4.4
        - /usr/local/lib/R/site-library
        - /usr/lib/R/site-library
        - /usr/lib/R/library
      knitr: 1.45
      rmarkdown: 2.25

(|) Checking Knitr engine render......(/) Checking Knitr engine render......(-) Checking Knitr engine render......(\) Checking Knitr engine render......(|) Checking Knitr engine render......(/) Checking Knitr engine render......(-) Checking Knitr engine render......[✓] Checking Knitr engine render......OK
@MartinSchobben MartinSchobben added the bug Something isn't working label Feb 7, 2025
@mcanouil
Copy link
Collaborator

mcanouil commented Feb 7, 2025

Thanks, I can reproduce on main ().
Anything before the first code cell is not converted back to qmd.

Code

---
title: "Reproducible Quarto Document"
format: html
engine: jupyter
---

## Introduction

This is a reproducible Quarto document with references.

```{python}
import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]

plt.plot(x, y)
plt.show()
```

![An image]({{< placeholder 600 400 >}}){#fig-placeholder}

## Lipsum

{{< lipsum 1 >}}

## Conclusion

```{python}
print("Bye!")
```

The end after @fig-placeholder.

It produces the following Notebook:

Notebook

{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "---\n",
        "title: \"Reproducible Quarto Document\"\n",
        "format: html\n",
        "engine: jupyter\n",
        "---\n",
        "\n",
        "## Introduction\n",
        "\n",
        "This is a reproducible Quarto document with references."
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "import matplotlib.pyplot as plt\n",
        "\n",
        "x = [1, 2, 3, 4, 5]\n",
        "y = [1, 4, 9, 16, 25]\n",
        "\n",
        "plt.plot(x, y)\n",
        "plt.show()"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "![An image]({{< placeholder 600 400 >}}){#fig-placeholder}\n",
        "\n",
        "## Lipsum\n",
        "\n",
        "{{< lipsum 1 >}}\n",
        "\n",
        "## Conclusion"
      ]
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": [
        "print(\"Bye!\")"
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "The end after @fig-placeholder."
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "name": "python3",
      "language": "python",
      "display_name": "Python 3 (ipykernel)",
      "path": "/Users/mcanouil/Projects/quarto/quarto-playground/.venv/share/jupyter/kernels/python3"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 4
}

For short what is happening is that the first Jupyter cell containing YAML header and text content is not converted back as such. Only the YAML header is taken.

InputOutput
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "---\n",
        "title: \"Reproducible Quarto Document\"\n",
        "format: html\n",
        "engine: jupyter\n",
        "---\n",
        "\n",
        "## Introduction\n",
        "\n",
        "This is a reproducible Quarto document with references."
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "---\n",
        "title: \"Reproducible Quarto Document\"\n",
        "format: html\n",
        "engine: jupyter\n",
        "jupyter: python3\n",
        "---\n",
      ]
    },

Side note: @MartinSchobben don't use "here" as text for links. Text used for links should be meaningful to the readers especially if they are using assistive technologies.
WCAG blog post about using meaningful text for links

@mcanouil mcanouil added jupyter convert Related to quarto convert command labels Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working convert Related to quarto convert command jupyter
Projects
None yet
Development

No branches or pull requests

2 participants