-
-
Notifications
You must be signed in to change notification settings - Fork 297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Converting .jl to Pluto notebook #132
Comments
I like your optimism in using the Open button and seeing what happens! I guess that this is easy to add in, but hard to do right. With that I mean that there is lots of new UI needed to explain to the user: what they are doing, what the result will be (no two-way conversion), what went wrong (if the import fails) and where they want to save the notebook after importing (overwrite?). Still, this might be worthwhile to add in, since it makes it easier to get started with Pluto. |
Ha. Yes it does seem like a good way to get started with Pluto, but I agree that it seems non-trivial to do correctly. You could add |
To anyone taking this on: see also #14, maybe this can be combined with Weave.jl and pandoc and Literate.jl and friends |
I think a possible way would be through Literate.jl, which has an option to output to Juypter, that means there is already a way to define markdown and Julia cells. By no means I think that a workflow .jl -> pluto should pass through .ipynb, though. But may be it is even simpler: IMHO it would be sufficient to have syntax to mark cell boundaries, e.g. by |
Support for writing notebook files by hand is not of this project, and making conversion part of Pluto is requires some carefully designed UI (#132 (comment)). But just like Jupyter conversion (https://observablehq.com/@olivier_plas/pluto-jl-jupyter-conversion and https://github.com/vdayanand/Jupyter2Pluto.jl), this can be an external tool, which is very simple to write! Maybe someone could try making it themselves? If you run julia> code="s = 1\nr=2"
"s = 1\nr=2"
julia> Meta.parse(code, 1)
(:(s = 1), 7) You can repeat this until you have found the start indices of every expression, and you then turn those into Pluto cells. |
Hi is there an API to turn something into a pluto cell (md or code) and to write a bunch of cells to a file? I think this is almost all I need... |
Yep: julia> import Pluto
julia> code = ["hello", "world()"];
julia> n = Pluto.Notebook(Pluto.Cell.(code));
julia> path = "hello.jl";
julia> Pluto.save_notebook(n, path); This gives: julia> read(path, String) |> Text
### A Pluto.jl notebook ###
# v0.11.4
using Markdown
using InteractiveUtils
# ╔═╡ 844da824-dcb6-11ea-1b3d-95c52106a0d2
hello
# ╔═╡ 844da856-dcb6-11ea-2061-a59a23dd029f
world()
# ╔═╡ Cell order:
# ╠═844da824-dcb6-11ea-1b3d-95c52106a0d2
# ╠═844da856-dcb6-11ea-2061-a59a23dd029f
|
Ok, this makes it easy to tweak Literate.script(), see my first attempt below.
|
Great! I will try it out soon! About the dependencies problem - I made |
Yeah I will do this within a day or two... |
It should be pretty trivilal to support something like
to Literate without having Pluto as a dependency. |
For writing a Pluto notebook to disk there is a Pluto API call |
We talked about it here: #311 - the file format will always be backwards compatible, or conversion code is included in Pluto |
WIP support for using Literate.jl to create Pluto notebooks from |
... so you have been faster than my PR to PlutoUtils using the Pluto.Notebook constructor... Have no time for testing this immediately. What I would like to see added are some options like |
Or perhaps just add a "begin" and "end", then run it on Pluto, and once it is opened in Pluto, delete begin and end and ask Pluto to divide the code into cells. |
This won't work, but you can paste the contents into a cell |
For the record, I wrote a simple utility for converting plain j.l file to notebook, available at |
I tried to open a standard .jl file in Pluto (from the Pluto startup page) and got
It would be great to be able to import a normal
.jl
and have it Plutified. This should e.g. take blocks of code and make them a single cell.The text was updated successfully, but these errors were encountered: