executablebooks / mdformat

CommonMark compliant Markdown formatter
https://mdformat.rtfd.io
MIT License
439 stars 46 forks source link

Output formatted file to console #377

Closed csala closed 1 year ago

csala commented 1 year ago

Context

Sometimes it would be desirable to run mdformat to obtain the formatted markdown string without modifying the original source file.

For reference, other code formatting tools like black or isort offer this option in one way or another:

Proposal

Add a way to format a file and dump the formatted contents to stdout without touching the file.

I see several ways of achieving this:

  1. Add some cli option to dump to console, like the -d/--debug option from isort
  2. Add piping capabilities allowing - as input filename and then forcing output to stdout, like black does.
  3. Add a -o/--output <filename> option to write to a different output file, potentially allowing - to indicate that outputs need to go to stdout

My preferred option here would be number 3, or a combination of 2 and 3, since this is the one that provides more flexibility.

csala commented 1 year ago

Forget this. I did not realize that point 2. above is already supported