Skip to content

Indenting executable codeblocks makes them malfunction #9970

Open
@GuillaumeDehaene

Description

@GuillaumeDehaene

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjupyter

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions