Turn a snippet of Julia code into a shareable, self-contained Markdown block for pasting into a GitHub issue, Discourse post, or Slack message.
Inspired by the R package reprex.
MinimalWorkingExamples can be installed directly from the Julia package manager. In the Julia REPL, press ] to enter the Pkg mode, then run:
pkg> add MinimalWorkingExamplesThe quickest way: copy your code to the clipboard, then call mwe() with no arguments:
using MinimalWorkingExamples
mwe()Or write your code in a begin...end block and pass it to @mwe directly:
@mwe begin
using Statistics
x = [1, 2, 3, 4, 5]
mean(x)
endNote
mwe() is generally the better choice: it preserves your code's exact formatting and comments, and all you need to do is copy the code and call mwe(). @mwe strips comments and requires a begin...end block, but is more convenient for showcasing.
Either way, this runs the code as a script in a fresh Julia process with a clean temporary environment, copies the result to your clipboard, and shows a preview of the rendered Markdown:
```julia
using Statistics
x = [1, 2, 3, 4, 5]
mean(x)
#> 3.0
```The value of each statement is shown as #> (assignments and definitions like function/struct are skipped), as are any print calls and log messages (@warn, @info) in the code.
Contributions of all kinds are welcome!
The package is still evolving, so feedback on defaults and output format is especially valuable. If you have an idea for improving the generated output or the user experience, please open an issue.