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

Literal block content is re-formatted (wrongly) #36

Closed
pelson opened this issue Aug 9, 2024 · 2 comments · Fixed by #38
Closed

Literal block content is re-formatted (wrongly) #36

pelson opened this issue Aug 9, 2024 · 2 comments · Fixed by #38
Assignees

Comments

@pelson
Copy link

pelson commented Aug 9, 2024

With the following content:

# A B C

1. Create a `.pre-commit-config.yaml` file in your repository and add the desired
   hooks. For example:

    ```yaml
    repos:
      - repo: https://github.com/psf/black
        rev: v24.4

    ```

Test

```yaml
file: abc.txt
```

Run with mdformat --align-semantic-breaks-in-lists --number, the content is re-formatted to:

# A B C

1. Create a `.pre-commit-config.yaml` file in your repository and add the desired
   hooks. For example:

    ```yaml
    repos:
      - repo: https://github.com/psf/black
      rev: v24.4

    ```

Test

```yaml
file: abc.txt
```

Note that the yaml content has been re-formatted. The re-formatting of the content within code blocks is not desirable (risky).

Note that if you try to re-format the re-formatted code, you get an error:

Warning: Failed formatting content of a yaml code block (line 6 before formatting). 
@KyleKing
Copy link
Owner

KyleKing commented Aug 9, 2024

Yeah, that shouldn't be formatted and likely could be from an incomplete patch of #31. I'll add these as test cases and work on a fix when I next have time!

Also, this is possibly related to the error in #35

@KyleKing KyleKing self-assigned this Aug 20, 2024
KyleKing added a commit that referenced this issue Aug 20, 2024
KyleKing added a commit that referenced this issue Aug 20, 2024
@KyleKing
Copy link
Owner

KyleKing commented Aug 22, 2024

I can replicate the issue after first formatting with mdformat-config!

pipx install mdformat && pipx inject mdformat mdformat-config && mdformat tmp.md

Generates:

# A B C

1. Create a `.pre-commit-config.yaml` file in your repository and add the desired
   hooks. For example:

   \`\`\`yaml
   repos:
     - repo: https://github.com/psf/black
       rev: v24.4

   \`\`\`

The problem is that mdformat-mkdocs needs to correct the indentation to be a multiple of 4x instead of 3x, but doesn't properly indent rev: v24.4 for some reason, which also does seem to be a problem with ignoring code blocks:

1. List

   \`\`\`md
   # Title
   Content
   1. Numbered List
     * Unordered Sub-List
   \`\`\`

And the root cause is semantic_indents! Which wasn't respecting code blocks

Edited: code blocks within code blocks aren't handled by Github's renderer

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

Successfully merging a pull request may close this issue.

2 participants