hougesen / mdsf

Format markdown code blocks using your favorite code formatters.
MIT License
10 stars 0 forks source link

issue shell block quote is not always directly about formatting shell scripts #161

Open ccoVeille opened 4 months ago

ccoVeille commented 4 months ago

shfmt is made for formatting script, definitely.

```shell
#!/bin/env bash

    date

But shell block quote in markdown is not ONLY about that

Yes, this would be valid

````markdown
```shell
  cp   foo    bar
  touch   foo

But the alternative syntax used in many markdown linters is this one

$ command result


So this

````markdown
```shell
$ date
Tue Apr  2 23:54:37 CEST 2024

Please note this one is sometimes refered as `console`

````markdown
```console
$ date
Tue Apr  2 23:54:37 CEST 2024

````markdown
```console
foo@bar:~$ whoami
foo


So your script will try to format things that are not always script.
ccoVeille commented 4 months ago

I'm not sure about the consequences of the things I'm raising, but at least now you know they exist

hougesen commented 4 months ago

Hmm, as far as I can tell shfmt doesn't have any issues formatting lines starting with $ (But it can't parse mdsf format <PATH_TO_FILE> which is rather ironic).

     $  cp   foo    bar
        $     touch    foo
$ date
Tue Apr  2 23:54:37 CEST 2024

Becomes

$ cp foo bar
$ touch foo
$ date
Tue Apr 2 23:54:37 CEST 2024

From a ux perspective I would personally expect any block tagged with shell / sh to be formatted using the shell formatter, whether it has a shebang or not. But I can definitely see your point.

I am honestly not sure what makes most sense 😅

ccoVeille commented 4 months ago

Yes, exactly. My idea was for your to have this in your mind. Maybe add a test or twos.

So you can see how things evolve.

Because developing is east, maintaining is hard. So having unit tests is always better.