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

Context aware indentation in VS Code #629

Open
daeh opened this issue Jan 4, 2025 · 3 comments
Open

Context aware indentation in VS Code #629

daeh opened this issue Jan 4, 2025 · 3 comments

Comments

@daeh
Copy link

daeh commented Jan 4, 2025

Is there a way for VS Code to apply context-aware indentations in qmd files? For instance, I need the python blocks to be indented with 4 spaces. But if 4-space indentation gets applied to everything, then <div class="author">In a Div</div> renders as a code block and the callout (which with 2 spaces correctly appears as a child of the first list item) is broken.

---
title: TEST
jupyter: python3
---

## Evaluated python cell

```{python}
def f():
    print("output")

f()
```

## Code block

```python
def f():
    print("output")
```

## HTML

<div class="container">
  <div class="author">In a Div</div>
</div>

## List

- unordered list

  ::: {.callout-note}
  A Callout
  :::

  - sub-item 1
  - sub-item 2
    - sub-sub-item 1

Thanks!!

quarto: 1.6.39
VSCode: 1.96.2
OS: Darwin arm64 23.6.0
quarto plugin: 1.118.0

@daeh
Copy link
Author

daeh commented Jan 4, 2025

Is the current best solution to set the document to 4-spaces and use raw for html

```{=html}
<div class="container">
    <div class="author">In a Div</div>
</div>
```

and extra space after bullet item?

-   unordered list

    ::: {.callout-note}
    A Callout
    :::

    -   sub-item 1
    -   sub-item 2
        -   sub-sub-item 1

?

@mcanouil
Copy link
Contributor

mcanouil commented Feb 3, 2025

Even if using raw code can work, the best practice is to use raw code blocks to ensure Quarto/Pandoc is using the content as is and do not try to process it as Markdown and hopefully guess right what the content is.

Regarding lists. It does not matter with or without spaces or the number of spaces used for the indendation. What matters is that sub elements are aligned first the parent item first character.

-     A parent item
      -  The dash is under "A"
         - The start is under "T".

Using spaces is a trick to use your document default indentation and/or for style reason with numbered list:

1.   An item
2.   An item
30.  An item
31.  An item
122. An item

@mcanouil
Copy link
Contributor

mcanouil commented Feb 3, 2025

Note a that I am not aware of any Markdown-based editor detecting code blocks/cells to apply various indentation.

In the case of code cell and in Quarto document / Jupyter Notebook, it could be possible to scope the indentation as it's the case with execution/formatting abilities delivered via third party extensions.

For code blocks on the other end, it's a bit trickier are those are text.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants