zimbatm/mdsh

`mdsh` clobbers code block immediately following command substitution

cole-h opened this issue · 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

\```
\```

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.

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.

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

juhp commented

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