rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
6.04k stars 889 forks source link

Support formatting Jupyter notebooks with Rust code #5699

Closed dclong closed 1 year ago

dclong commented 1 year ago

https://github.com/evcxr/evcxr/tree/main/evcxr_jupyter is a Jupyter notebook kernel which allows running Rust code in Jupyter notebooks. It's a great tool (in addition to Rust Playground) for exploring and learning Rust.

It would be very appealing if rustfmt support format Jupyter notebooks containing Rust code too.

ytmimi commented 1 year ago

Thanks for reaching out, but I'm going to close this as I don't anticipate that the team will add direct support for Jupyter notebooks to rustfmt. That being said, it probably wouldn't be too difficult to build a tool that extracted code blocks from a Jupyter notebook and then handed them off to rustfmt for formatting.

Jupyter notebooks are just JSON documents, and it should be fairly easy to iterate through all the "cell_type" : "code" cells and run rustfmt on their source.