hukkin / mdformat-gfm

Mdformat plugin for GitHub Flavored Markdown compatibility
MIT License
13 stars 2 forks source link

[Feature Request] Support git diff code blocks #36

Open elliotweiser opened 7 months ago

elliotweiser commented 7 months ago

Currently, git-diff style code blocks do not appear to be supported/respected by the formatter, particularly when describing a list of deletions. As a result, a GitHub workflow snippet appears to be treated as YAML rather than a git diff. As a result...

This content:

- build_args: |
-   "my_host=${{ vars.MY_HOST }}"
- secrets:
-   "my_token=${{ secrets.MY_TOKEN }}"
-   "my_user=${{ vars.MY_USER }}"
-   "my_host=${{ vars.MY_HOST }}"

Is formatted to this:

- build_args: |
- "my_host=${{ vars.MY_HOST }}"
- secrets:
- "my_token=${{ secrets.MY_TOKEN }}"
- "my_user=${{ vars.MY_USER }}"
- "my_host=${{ vars.MY_HOST }}"

At a glance, this is just whitespace, but important information gets lost about the structure of the described source file. It would be great to see this use-case supported.

It's certainly possible that I'm doing something wrong.

KyleKing commented 7 months ago

Hi, thanks for trying out mdformat-gfm!

Locally, I ran the latest version of mdformat with the below markdown file and the plugin didn't modify the formatting within the code block.

```diff
- build_args: |
-   "my_host=${{ vars.MY_HOST }}"
- secrets:
-   "my_token=${{ secrets.MY_TOKEN }}"
-   "my_user=${{ vars.MY_USER }}"
-   "my_host=${{ vars.MY_HOST }}"
```

Steps:

pipx install mdformat
pipx inject mdformat mdformat-gfm
mdformat ./tmp.md

Do you have another mdformat plugin installed? mdformat-gfm doesn't modify any text within backticks, but there are a number of other plugins which could be removing the whitespace

elliotweiser commented 7 months ago

Do you have another mdformat plugin installed? mdformat-gfm doesn't modify any text within backticks, but there are a number of other plugins which could be removing the whitespace

Very possible. I'll dig deeper and see what comes up. There's quite a bit going on in terms of formatting, and I believe we're have at least a few plugins to mdformat at play. Thanks for the sanity-check and repro steps-- I'll give this a shot just to be sure.

KyleKing commented 2 months ago

@elliotweiser, did you find out what plugin was the problem?