Indenting executable codeblocks makes them malfunction

Open
#9,970 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
jupyter, markdown, python
Domain
cli

Research direction

Use the minimal Quarto example in the report as the reproducer; inspect the generated Markdown and resulting HTML for indented executable blocks outside and inside lists. Done means the list case is emitted as valid Markdown and the handling of top-level indentation is explicitly settled without breaking ordinary indented Markdown.

Written by the indexing model from the issue text.

Description

bug engines-jupyter
Bug description

Normal markdown code supports nesting environments into one-another using indentation. For example, lists can be nested. Paragraphs can be nested into a list bullet-point. Also, indentation can be used to mark a verbatim block.

However, indenting executable code blocks makes them malfunction (for jupyter).

Steps to reproduce

This minimal example compiles to very weird markdown. The resulting html is weird. As far as I can tell, this is due to correct parsing of the weird markdown.

NB: this is a minimal example with a stupid output. The issue persists if using a Markdown(tabulate(...)) example or a matplotlib figure.

---
execute:
    echo: false

format: markdown
---

# Minimal example

```{python}
print("- Foo")
```

    ```{python}
    print("- Foo")
    ```

- Nesting list

    - Foo

- Nesting list:

    ```{python}
    print("- Foo")
    ```

After compilation

# Minimal example

:::: {.cell execution_count="1"}
::: {.cell-output .cell-output-stdout}
    - Foo
:::
::::

    ::: {.cell execution_count=2}

    ::: {.cell-output .cell-output-stdout}
    ```
    - Foo
    ```
    :::
    :::

-   Nesting list

    -   Foo

-   Nesting list:

    ::: {.cell execution_count=3}

    ::: {.cell-output .cell-output-stdout} \`\`\`

    -   Foo \`\`\` ::: :::
Expected behavior

I'm not sure what the expected behavior should be, without breaking everything and making everything super complex.

  • For indentation outside of any context (first half of the example), I'm not sure if there is even any solution that makes sense:

    • maintaining indentation results in a verbatim code block, which is very weird
    • changing the markdown produced by execution sounds very complicated for very little benefit
    • can verbatim blocks from indentation be turned off in pandoc? I don't think so?
    • the simplest might be to write in the documentation that indenting produces this weird behavior?
  • For indentation inside of a list, like in the second half of the example, I would expect the behavior to be that indentation is preserved and produces correct markdown. I think the issue here is only that the markdown is mangled somehow.

Actual behavior
  • indentation outside of context: produces ugly verbatim code
  • indentation inside of context of list: mangled output, probably due to incorrect parsing of the div delimiters
Your environment
  • IDE: vscode
  • OS: windows 11
Quarto check output

Quarto 1.5.45
[>] Checking versions of quarto binary dependencies...
Pandoc version 3.2.0: OK
Dart Sass version 1.70.0: OK
Deno version 1.41.0: OK
Typst version 0.11.0: OK
[>] Checking versions of quarto dependencies......OK
[>] Checking Quarto installation......OK
Version: 1.5.45
Path: C:\Users\Guillaume\AppData\Local\Programs\Quarto\bin
CodePage: 1252

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

[>] Checking LaTeX....................OK
Tex: (not detected)

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

[>] Checking Python 3 installation....(None)

  Unable to locate an installed version of Python 3.
  Install Python 3 from https://www.python.org/downloads/

[>] Checking R installation...........(None)

  Unable to locate an installed version of R.
  Install R from https://cloud.r-project.org/

PS D:\Desktop\Dojo\quarto_bug_report_listings>

I'm not sure why python is not seen but everything compiles as it should:

Python 3.12.4 (tags/v3.12.4:8e8a4ba, Jun 6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)] on win32

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

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.

More from quarto-dev/quarto-cli

All issues in quarto-dev/quarto-cli

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.