mdsh icon indicating copy to clipboard operation
mdsh copied to clipboard

`mdsh` clobbers code block immediately following command substitution

Open cole-h opened this issue 4 years ago • 4 comments

Take the following in.md file as an example:

`$ echo hi`

\```
bye
\```

After running mdsh --input in.md --output out.md, out.md looks like the following:

`$ echo hi`
\```
hi
\```

Notice how the "bye" code block is now missing.

This can be worked around by adding a dummy code block or HTML comment after command substitutions, e.g. <!-- --> or

\```
\```

cole-h avatar Jul 12 '21 16:07 cole-h

Initially, mdsh was only replacing the fenced block if it was right on the next line. But there is a markdown formatting tools called "prettier" that adds back an empty line in between both blocks. So I relaxed that rule for both tools to work together. But now we're hitting the issue you described.

This is all a bit hacky.

Maybe mdsh should always add comment sections, as it does for the HTML output. That would make it more verbose but less ambiguous.

zimbatm avatar Jul 12 '21 19:07 zimbatm

Do you remember where that next-line check was (or which commit removed it)? I could just patch that out until a reasonable solution is decided upon, seeing as I don't use prettier.

cole-h avatar Jul 13 '21 15:07 cole-h

This was introduced in the last release (v0.6.0). Reverting to 0.5.0 should be fine.

zimbatm avatar Jul 14 '21 13:07 zimbatm

One idea could be to add a option to require no newline: though I am fine with the current behavior.

juhp avatar Jun 18 '24 14:06 juhp