Skip to content

--- as slide separation markers confuses Jupyter's cell detection #8998

Description

@anhi

Bug description

When using inline python code, for some reason, only some of the expressions are evaluated. I can't see any logic to which expressions work and which don't.

Steps to reproduce

---
title: Test
subtitle: test
format: revealjs
engine: jupyter
---

### test

- `{python} 1`

---


### test

- `{python} 2`

---


### test

- `{python} 3`

Expected behavior

A presentation with three slides, showing 1, 2, and 3.

Actual behavior

A presentation with three slides, the first showing "1", the second "{python} 2", the third "3".

Your environment

  • IDE: VSCode, OS: MacOS Ventura

Quarto check output

Quarto 1.4.551
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.1.11: OK
      Dart Sass version 1.69.5: OK
      Deno version 1.37.2: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.4.551
      Path: /Applications/quarto/bin

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

[✓] Checking LaTeX....................OK
      Using: Installation From Path
      Path: /Library/TeX/texbin
      Version: 2023

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.11.8
      Path: /tmp/env/bin/python3
      Jupyter: 5.7.1
      Kernels: julia-1.10, julia-1.8, julia-1.9, julia-1.8.5-_4-threads_-1.8, python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........OK
      Version: 4.3.3
      Path: /opt/homebrew/Cellar/r/4.3.3/lib/R
      LibPaths:
        - /opt/homebrew/lib/R/4.3/site-library
        - /opt/homebrew/Cellar/r/4.3.3/lib/R/library
      knitr: 1.45
      rmarkdown: 2.25

[✓] Checking Knitr engine render......OK

Activity

  1. added
    bug
    on Mar 7, 2024
  2. cderv commented on Mar 7, 2024

    @cderv
    Member

    Thanks.

    This is it seems an issue with how the intermediate ipynb is formatted due to the --- slide delimiter

    Intermediate ipynb
    {
     "cells": [
      {
       "cell_type": "raw",
       "id": "430ab9f1",
       "metadata": {},
       "source": [
        "---\n",
        "title: Test\n",
        "subtitle: test\n",
        "format: revealjs\n",
        "slide-level: 0\n",
        "engine: jupyter\n",
        "keep-md: true\n",
        "keep-ipynb: true\n",
        "---"
       ]
      },
      {
       "cell_type": "markdown",
       "id": "914d822a",
       "metadata": {
        "user_expressions": [
         {
          "expression": "1",
          "result": {
           "data": {
            "text/plain": "1"
           },
           "metadata": {},
           "status": "ok"
          }
         }
        ]
       },
       "source": [
        "### test\n",
        "\n",
        "- `{python} 1`"
       ]
      },
      {
       "cell_type": "raw",
       "id": "9581579d",
       "metadata": {},
       "source": [
        "---\n",
        "\n",
        "\n",
        "### test\n",
        "\n",
        "- `{python} 2`\n",
        "\n",
        "---"
       ]
      },
      {
       "cell_type": "markdown",
       "id": "3c1e6667",
       "metadata": {
        "user_expressions": [
         {
          "expression": "3",
          "result": {
           "data": {
            "text/plain": "3"
           },
           "metadata": {},
           "status": "ok"
          }
         }
        ]
       },
       "source": [
        "### test\n",
        "\n",
        "- `{python} 3`"
       ]
      }
     ],
     "metadata": {
      "kernelspec": {
       "display_name": "Python 3 (ipykernel)",
       "language": "python",
       "name": "python3",
       "path": "C:\\Users\\chris\\PYENV~1\\PYENV-~2\\versions\\3.12.1\\share\\jupyter\\kernels\\python3"
      }
     },
     "nbformat": 4,
     "nbformat_minor": 5
    }

    especially the part with `{python} 2` is formatted this way

      {
       "cell_type": "raw",
       "id": "9581579d",
       "metadata": {},
       "source": [
        "---\n",
        "\n",
        "\n",
        "### test\n",
        "\n",
        "- `{python} 2`\n",
        "\n",
        "---"
       ]
      },

    So it is a raw cell and not a markdown cell. Usually --- are used to delimit YAML metadata block, who can be anywhere in the document. Like

    <!-- start of the doc -->
    ### test
    
    - `{python} 3`
    
    ---
    title: override
    ---

    would lead to raw cell too

        {
          "cell_type": "markdown",
          "metadata": {},
          "source": [
            "### test\n",
            "\n",
            "- `{python} 3`\n"
          ],
          "id": "85553944"
        },
        {
          "cell_type": "raw",
          "metadata": {},
          "source": [
            "---\n",
            "title: override\n",
            "---"
          ],
          "id": "d87135ea"
        }

    So I think we need to account for slide delimitation also 🤔

  3. added
    engines-jupyter
    on Mar 7, 2024
  4. mcanouil commented on Mar 7, 2024

    @mcanouil
    Collaborator

    Side note, what's the purpose of level three headings and the use of --- (compared to the below example)? (maybe it's for the sake of the reproducible example).

    ---
    title: Test
    subtitle: test
    format: revealjs
    engine: jupyter
    ---
    
    ## test
    
    - `{python} 1`
    
    ## test
    
    - `{python} 2`
    
    ## test
    
    - `{python} 3`
    
    ```
  5. cderv commented on Mar 7, 2024

    @cderv
    Member

    It does not matter really here. Yes you could not use --- but the example shows the issue which is with ---.

    here is another one adapted from our doc about using ---: https://quarto.org/docs/presentations/revealjs/#creating-slides that should make you happier 😉

    ---
    title: "Habits"
    author: "John Doe"
    format: revealjs
    engine: jupyter
    ---
    
    - Turn off alarm
    - Get out of bed
    - `{python} 1` 
    
    ---
    
    - Get in bed
    - Count sheep
    - `{python} 2`
    
    ---
    
    Last slide to recreate the issue
    

    what's the purpose of level three headings

    Also ### means <h3> in the HTML while ## will be <h2> so not the same styling by default.

  6. cderv commented on Mar 7, 2024

    @cderv
    Member

    Anyhow, the issue is with our Markdown to Jupyter conversion which use regex

    const yamlRegEx = /^---\s*$/;

    and then our line processing

    if (yamlRegEx.test(line) && !inCodeCell && !inCode) {
    if (inYaml) {
    lineBuffer.push(line);
    flushLineBuffer("raw", !parsedFrontMatter);
    parsedFrontMatter = true;
    inYaml = false;
    } else {
    flushLineBuffer("markdown");
    lineBuffer.push(line);
    inYaml = true;
    }
    } // begin code cell: ^```python

    I don't think we account correctly for manual slide delimiter --- which can be used for slide formats

  7. changed the title [-]Inline code only partially executed[/-] [+]`---` as slide separation markers confuses Jupyter's cell detection[/+] on Mar 12, 2024
  8. added this to the v1.5 milestone on Mar 12, 2024
  9. self-assigned this
    on Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugengines-jupyter

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions