# Export jupyter to .jl does not preserve markdown cells

**URL:** <https://discourse.julialang.org/t/export-jupyter-to-jl-does-not-preserve-markdown-cells/57556>\
**Category:** General Usage\
**Tags:** markdown\
**Created:** [March 19, 2021, 4:32pm UTC](https://discourse.julialang.org/t/export-jupyter-to-jl-does-not-preserve-markdown-cells/57556 "2021-03-19T16:32:51Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 19, 2021, 5:02pm UTC](https://discourse.julialang.org/t/export-jupyter-to-jl-does-not-preserve-markdown-cells/57556/2 "2021-03-19T17:02:10Z")

</div>

> [@Ferran\_Mazzanti](#):
>
> Now the question is: is there a way to have this functionality? I mean, I want all my documentation to be included as commented lines in the exported .jl file, and I think this makes a lot of sense.

Yes. A `.ipynb` file is just JSON text, so you can easily write a script using the JSON.jl package to extract the code and markdown. Moreover, you can use the Markdown stdlib to parse and pretty-print the markdown content:

```julia
using JSON, Markdown

function ipynb2jl(ipynfile)
    jlfile = replace(ipynfile, r"(\.ipynb)?$" => ".jl")
    nb = open(JSON.parse, ipynfile, "r")
    open(jlfile, "w") do f
        for cell in nb["cells"]
            if cell["cell_type"] == "code"
                print(f, "\n\n")
                print.(Ref(f), cell["source"])
            elseif cell["cell_type"] == "markdown"
                md = Markdown.parse(join(cell["source"]))
                print(f, "\n\n# ", replace(repr("text/plain", md), '\n' => "\n# "))
            end
        end
    end
end

```

_Update_: this functionality is now available via the `nbexport` function of the [NBInclude.jl](https://github.com/stevengj/NBInclude.jl) package.

---

_[View the full topic](https://discourse.julialang.org/t/export-jupyter-to-jl-does-not-preserve-markdown-cells/57556)._
